durusmail: qp: Re: qpy development ideas
qpy development ideas
2007-10-08
2007-10-09
Re: qpy development ideas
2007-10-10
2007-10-10
2007-10-14
2007-10-15
David K. Hess (2 parts)
2007-10-09
2007-10-09
2007-10-10
2007-10-10
2007-10-10
2007-10-10
2007-10-10
Re: qpy development ideas
Michael Watkins
2007-10-17
* David Binger wrote on [2007-10-17 13:26:37 -0400]:
> I don't really see the need for decorators at all for this.

While I was thinking as I type, I mentioned that I didn't have a
sense where this might fall on the "qp" continuum. As I've thought
about this more, for my own personal use, decorators for xhtml (if
not xml) validation are somewhat less useful as I use a mix of
publisher.header/footer/page methods throughout code.

I've since seen David Hess's follow-on message about using
decorators to encapsulate [html] with ensure_signed_in / header /
footer - I can see some merit in that - one line of code instead of
three. Mind you, the slightly briefer:

@page
def some_page [html] ():
    o = get_some_obj()
    ' stuff '
    # ... code ...
    ' yet more stuff '

Doesn't deal with a common usage:

def some_page [html] ():
    o = get_some_obj()
    header(title='%s : %s' % (
        o.get_name(),
        get_publisher().format_date(o.get_stamp())))
    ' stuff '
    # ... code ...
    ' yet more stuff '
    footer()

> It seems like all of this would be clearer if your SitePublisher
> simply overrides fill_response() call the inherited method, and
> then validate and/or revise the response body as desired.

That's basically the default answer for so many QP customizations -
a good thing, and easy to accomplish.

Here's an example using the tidy executable which I've wrapped up in
"call_tidy":

    def fill_response_using_root_directory(self):
        path = get_request().get_path_info()
        components = path[1:].split('/')
        body = self.get_root_directory()._q_traverse(components)
        if (self.configuration.get('tidy', False) and
            'html' in get_response().content_type[0]):
            num_errors, num_warnings, body, errors = call_tidy(body)
            if (num_errors or num_warnings):
                print '[Tidy Errors: %d, Warnings: %s] %s' % (
                    num_errors, num_warnings, '; '.join(errors))
        get_response().set_body(body)

Hmnn, that bit of code just located for me a forgotten call to
footer() in one of my methods. It was pure chance that it was caught
- I should crawl through an entire site more often.

> I assume different QP site authors might want different forms
> of validation, and different forms of output formatting.

Yes, and it seems in XML land there are so many options and
variations. Validating? Well-formedness alone? Which parser?

Options available today:

- server-side per-request output examination such as the example
  above,

- the PageLoader class / crawler as pointed out in Dulcinea;

- client side validation using tidy with "your editor here".  I have
  keys mapped in vim to push an in-buffer chunk of (x)html / xml through
  tidy (or through xmllint). It can be handy to run unfiltered xhtml
  locally so that I can use the facilities of vim to step through
  errors presented in the vim quickfix list.

- roll your own
reply