[Twisted-web] loaders.xmlstr versus loader.xmlfile

Michael Wilson michael.wilson at gmail.com
Mon Dec 20 17:00:51 MST 2004


I spent some time tracing through this, and here is some more data:

1. In the origional customform.py, which uses xmlstr, I see the getDoc
and precompile methods being invokes (as expected). I verified this by
putting breakpoints at these methods.

2. In the example below, these methods are NEVER called. __init__ is
called when twisted loads the app, but that's it. We never actually
call getDoc or precompile.

I can't figure out why, but there's some more data. 


On Mon, 20 Dec 2004 08:43:34 -0800, Michael Wilson
<michael.wilson at gmail.com> wrote:
> Sure, below you will find the version of customform.py I used, and the
> .xml file follows. Now that I know it should be the same I'll dig
> around some more.
> 
> #################################################################################
> # This is a version of examples/customform.py, except I've moved the template
> # off to disk.
> 
> from twisted.application import internet, service
> from twisted.web import static
> from nevow import inevow, rend, loaders, tags, appserver
> 
> from nevow import rend
> from nevow import url
> from nevow import loaders
> from nevow import tags as T
> 
> from formless import annotate
> from formless import iformless
> from formless import webform
> 
> FORM_LAYOUT = loaders.xmlfile( 'customform.xml' )
> 
> #################################################################################
> # ISomething and Page are just something to test the form rendering on.
> 
> class ISomething(annotate.TypedInterface):
> 
>     def doSomething(
>         self,
>         ctx = annotate.Context(),
>         fee = annotate.String(required=True, description="Wee!"),
>         fi = annotate.Integer(description="Tra-la-la"),
>         fo = annotate.Text(),
>         fum = annotate.String(),
>         ):
>         """Do Something Really Exciting
> 
>         Normally you would put a useful description of the interface here but,
>         since the inteface is useless anyway, I cannot think of anything
>         useful to say about it. Although ... did I mention it is useless?"""
>     doSomething = annotate.autocallable(doSomething)
> 
> class Root(rend.Page):
>     """Render a custom and normal form for an ISomething.
>     """
>     __implements__ = ISomething, rend.Page.__implements__
>     addSlash = True
> 
>     child_webform_css = webform.defaultCSS
> 
>     def render_normalForm(self, ctx, data):
>         return webform.renderForms()
> 
>     def render_customForm(self, ctx, data):
>         return webform.renderForms()[FORM_LAYOUT]
> 
>     def doSomething(self, ctx, **kwargs):
>         print '***** doSomething called with:', kwargs
> 
>     docFactory = loaders.stan(
>         T.html[
>             T.head[
>                 T.title['Example :: Custom Form Layout'],
>                 T.link(rel='stylesheet', type='text/css',
> href=url.here.child("webform_css")),
>                 ],
>             T.body[
>                 T.h1['Custom'],
>                 render_customForm,
>                 T.h1['Default'],
>                 render_normalForm,
>                 ]
>             ]
>         )
> 
> application = service.Application('hellostan')
> webServer = internet.TCPServer(8080, appserver.NevowSite(Root()))
> webServer.setServiceParent(application)
> 
> --------------- customform.xml follows --------------------
> 
> <?xml version="1.0"?>
>     <form xmlns:n="http://nevow.com/ns/nevow/0.1" n:pattern="freeform-form">
> 
>       <!-- Replace/fill the form attributes -->
>       <n:attr name="action"><n:slot name="form-action"/></n:attr>
>       <n:attr name="id"><n:slot name="form-id"/></n:attr>
>       <n:attr name="name"><n:slot name="form-name"/></n:attr>
> 
>       <!-- General form information -->
>       <p><strong><n:slot name="form-label"/></strong></p>
>       <p><em><n:slot name="form-description"/></em></p>
>       <p><strong><em><n:slot name="form-error"/></em></strong></p>
> 
>       <!-- Start of the form layout table -->
>       <table style="background: #eee; border: 1px solid #bbb; padding: 1em;" >
>         <!-- Mark location arguments will be added -->
>         <n:slot name="form-arguments"/>
>         <!-- General argument layout pattern -->
>         <n:invisible n:pattern="argument" n:render="remove">
>           <tr>
>             <th><n:slot name="label"/>:</th>
>             <td><n:slot name="input"/><span
> class="freeform-error"><n:slot name="error"/></span></td>
>           </tr>
>           <tr>
>             <th></th>
>             <td><n:slot name="description"/></td>
>           </tr>
>         </n:invisible>
>         <!-- Argument layout, just for fum -->
>         <n:invisible n:pattern="argument!!fo" n:render="remove">
>           <tr>
>             <th><n:slot name="label"/>:</th>
>             <td>
>               <textarea cols="40" rows="5"><n:attr name="id"><n:slot
> name="id"/></n:attr><n:attr name="name"><n:slot
> name="name"/></n:attr><n:slot name="value"/></textarea>
>               <span class="freeform-error"><n:slot name="error"/></span></td>
>           </tr>
>           <tr>
>             <th></th>
>             <td><n:slot name="description"/></td>
>           </tr>
>         </n:invisible>
>         <!-- Button row -->
>         <tr>
>           <td colspan="2">
>             <n:slot name="form-button"/>
>           </td>
>         </tr>
>       </table>
>     </form>
> 
> 
> On Mon, 20 Dec 2004 11:40:49 +0200, Tommi Virtanen <tv at twistedmatrix.com> wrote:
> > Michael Wilson wrote:
> >
> > >Shouldn't I be able to put it into a file and replace
> > >"loaders.xmlstr(...)' with "loaders.xmlfile(...)" and have it act
> > >exactly the same?
> > >
> > >
> > Yes. You need to provide more information for anyone to help you;
> > preferably a minimal runnable program that demonstrates the issue.
> >
> >
>



More information about the Twisted-web mailing list