Hi Jose,
I've tried your suggestion of using:
self.directory = os.path.normpath(directory)
and that works fine too so I'll check that in instead if you'd prefer?
James Gardner wrote:
>> At the moment if I put in a URL which resolves to a directory this
>> code kicks in (line 460 of paste.urlparser):
>>
>> if os.path.isdir(full):
>> # @@: Cache?
>> child_root = self.root_directory is not None and \
>> self.root_directory or self.directory
>> return self.__class__(full, root_directory=child_root,
>> cache_max_age=self.cache_max_age)(environ,
>> start_response)
Ian Bicking wrote:
> Huh... it's supposed to do the recursive traversal of directories. So
> it just creates another instance of StaticURLParser that points to the
> subdirectory, and then passes the request off to that.
I don't understand why you'd ever want to do this? It only ever gets
called if the URL maps to a directory and if that is the case it should
return a 403. I'll change it.
> It doesn't seem to have reasonable behavior when a StaticURLParser
> instance is asked to serve itself, not a subfile. Probably it should
> return 403 Forbidden in that case
Should it do this rather than 404? I only ask because it is used in the
config/middleware.py Cascade and if a 403 is returned, other parts of
the app won't get called but if this is the correct behavior that's fine.
Cheers,
James
Dear James,
I was wondering if you'd had time to investigate the strange redirects?
Are you happy with your checked in code? I was going to upgrade to the
svn version of paste to get the updates but wanted to check to see what
the status was
Jose
On Dec 18, 10:20 am, James Gardner <[EMAIL PROTECTED]> wrote:
Hi all,
I've checked in some changes to paste.urlparser to work with Windows but
I've noticed a problem with certain URLs now redirecting to themselves
which I'm investigating.
Cheers,
James
programmer.py wrote:
> Oh, I think this is what you really wanted to know about normpath...
> os.path.normpath(r'c:/tmp/pylons-sandbox/helloworld')
> 'c:\\tmp\\pylons-sandbox\\helloworld'
> It does seem to fix the path separator on windows.
> jw
> On Dec 18, 11:51 am, "programmer.py" <[EMAIL PROTECTED]> wrote:
>> fwiw, im on windows ->
>>>>> import os.path
>>>>>
os.path.normpath(r'c:\tmp\pylons-sandbox\helloworld')'c:\\tmp\\pylons-sandbox\\helloworld'
>> Also, Ian is right, the problem is in urlparser.py ... I printed out
>> the `full' and self.root_directory before the check @457 and got ->
>> c:\tmp\pylons-sandbox\helloworld\helloworld\public\index.html
>> c:/tmp/pylons-sandbox/helloworld/helloworld/public
>> ouch.
>> Thanks all!
>> jw
>> On Dec 18, 10:47 am, Ian Bicking <[EMAIL PROTECTED]> wrote:
>>> James Gardner wrote:
>>>> Hi Jose,
>>>> The problem is that StaticURLParser keeps some variables with / path
>>>> separators and \ characters with others if you don't specify the
>>>> root_directory on Windows.
>>>> The solution on Windows is to specify both the directory and the
>>>> root_directory when setting up the static file parser and ensure
they
>>>> use Windows \ separators.
>>>> In your Pylons project config/middleware.py change this line:
>>>> static_app = StaticURLParser(..)
>>>> to this:
>>>> static_app = StaticURLParser(
>>>> directory=config.paths['static_files'].replace('/','\\'),
>>>>
root_directory=config.paths['static_files'].replace('/','\\')
>>>> )I suppose in StaticURLParser we could do:
>>> if os.path.sep != '/':
>>> directory = directory.replace('/', os.path.sep)
>>> and ditto root_directory. Would that resolve the problem? Does
>>> os.path.normpath do this replacement on Windows? That seems like
a more
>>> ideal solution. I'm guessing the reason it isn't working is when it
>>> tests on urlparser.py:450 "full.startswith(self.root_directory)" that
>>> the backslash/slash confusion causes the problem. That should
probably
>>> be updated to at least give a slightly more useful not found message
>>> (via the optional debug_message argument to not_found).
>>> Since you are on Windows, can you try these things out?
>>> --
>>> Ian Bicking | [EMAIL PROTECTED] |http://blog.ianbicking.org
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---