durusmail: quixote-users: Re: import and export - help!
import and export - help!
2004-04-18
Re: import and export - help!
2004-04-19
2004-04-20
2004-04-20
2004-04-20
2004-04-20
2004-04-21
2004-04-21
Jason E. Sibre (2 parts)
2004-04-21
Re: import and export - help! (resolved)
2004-04-21
2004-04-20
2004-04-20
Re: import and export - help!
jsibre@sibre.org
2004-04-20
Quoting John Miller :

> Actually, I have:
> '''
> _q_exports = ['links', 'book', 'keywords']
> from qxdemo.ui import links
> from qxdemo.ui.links import book, keywords
> '''
> because 'book' and 'keywords' are inside the links.ptl file. I also
> have a _q_index method in here as a springboard for the various demo
> features. One issue I had was the trailing slash in the URLs:
> href="links/" *required* the trailing slash to work (until I set
> FIX_TRAILING_SLASH = 1 in the .conf file). The other two URLs,
> href="book" and href="keywords" would *only* work *without* the
> trailing slash. Anyway, I prefer no trailing slash, so setting
> FIX_TRAILING_SLASH = 1 makes all the URLs consistent.
>

Ouch...  Now I wish I'd paid more attention at the beginning of your dialog...
What you're doing with the import statments (and _q_exports) really has me
scratching my head.  I'm not in a position at the moment to look at the code of
qxdemo, and I'm not too familiar with it, having only looked briefly at it a
few months ago, but, based on what you're doing, I think either it's really
broken, or you're trying to make it work in a rather odd (for quixote) way.

Your comments about the FIX_TRAILING_SLASH stuff seems to indicate that also.

The Quixotic idiom is that namespaces become the 'directories' of your URLs, and
methods/functions become the 'files' of your URLs.  Hence, namespaces (of an
instance of a class, module, package, etc) should have trailing slashes,
because they don't really do anything 'webbish' on their own.  Given the url
"/ui/" (for example), quixote will implicitly serve it as if you'd requested
"/ui/_q_index".  That's why it wants to convert "/ui" (again, for example) to
"/ui/", and breaks if you don't allow it to do so (i.e., you set
FIX_TRAILING_SLASHES to 0).  A notable exception to this is when a namespace is
callable (i.e., have a __call__() defined).  In those cases, quixote won't look
for the _q_index.  Going back to the example, "/ui" would work, and it would be
as if you'd requested "/ui/__call__"...
[You'll actually see similar options / behavior apache, if you ever look for
them.  Of course, the names are different.]

> [...]
>
> However, I'm still baffled by the mechanics of importing and exporting
> files and methods *across directories*. Say, for example, I had a
> subdirectory inside the /qxdemo/ui directory - let's call it 'foo' and
> it has a 'bar.ptl' page with a method called 'run()'. How and where do
> I expose the 'run()' method? From /qxdemo/ui/__init__.py? From
> /qxdemo/ui/foo/__init__.py? From both? All the failed experiments I
> tried with qxdemo have left me wondering how to think 'quixotically'
> with respect to exposing methods and pages to the web across
> directories.

Again with the head scratching.  I hope I'm not just misunderstanding you here,
and causing more confusion rather than reducing it, but I think this question
stems from not yet 'getting' the quixote publishing method.

Assume we have this structure:
.../qxdemo/ui/__init__.py
.../qxdemo/ui/foo/__init__.py
.../qxdemo/ui/foo/bar.ptl

as long as:
the _q_exports of ui/__init__.py contains 'foo' in it,
and
the _q_exports of ui/foo/__init__.py contains 'bar' in it,
and
the _q_exports of ui/foo/bar.ptl contains 'run' in it,
you're done!

A request to /foo/bar/run (assuming 'ui' is the app's root) will call the run()
method.  (I think... I've been doing my publishing with live classes rather
than modules and packages lately, so I'm not positive about the details on the
package importing the module... Someone wanna sanity-check me?)

Of course, you COULD import the run() method up to a higher level with something
like:
[in ui/__init__.py]
from foo.bar import run
_q_exports = ['run']

and then request "/run".

And there's nothing wrong with that.  In fact, sometimes doing this is helpful.
Just so long as you're aware of the alternatives, and not just pulling
everything up into your root namespace because you didn't know that you didn't
have to.

Hope this helps some.

Jason





----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


reply