[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/apidoc/utilitymodule/ Fixed utility module to work well with any type of utility name.

Tarek Ziadé tziade at nuxeo.com
Sat Oct 29 09:14:42 EDT 2005


Bjorn Tillenius wrote:

>On Fri, Oct 28, 2005 at 02:33:13PM -0400, Stephan Richter wrote:
>  
>
>>+Bu what are those strange names? Since utility names can be any string, it is
>>+hard to deal with them in a URL. Thus the system will advertise and use the
>>+names in their `BASE64` encoded form. However, because it is easier in the
>>+Python API to use the real utility names, utilities can be looked up in their
>>+original form as well.
>>    
>>
>
>Maybe I've missed some aspect of the problem, but it seems strange that
>you chose to use BASE64, thus producing very cryptic URLs, which aren't
>readable at all. If the problem is that you want to use the names in
>URLs, why not use urllib.quote() whenever you construct a URL?
>
>Since ILocation.__name__ is a TextLine, thus allow the names to contain
>almost any characters, I can name my utility:
>
>    "Is this name url safe??? Let's see."
>
>Now, let's encode it with BASE64:
>
>    >>> "Is this name url safe??? Let's see.".encode('base64')
>    'SXMgdGhpcyBuYW1lIHVybCBzYWZlPz8/IExldCdzIHNlZS4=\n'
>  
>


>As you can see, there's a '/' character in there, thus the traverser
>will think that the utility name is 'SXMgdGhpcyBuYW1lIHVybCBzYWZlPz8'.
>So it seems like you have to use urllib.quote() anyway.
>  
>
Otherwise we can use it like this, wich is much safer for the use case 
you have shown:

 >>> import base64
 >>> base64.urlsafe_b64encode("Is this name url safe??? Let's see.")
'SXMgdGhpcyBuYW1lIHVybCBzYWZlPz8_IExldCdzIHNlZS4='
 >>> 
base64.urlsafe_b64decode('SXMgdGhpcyBuYW1lIHVybCBzYWZlPz8_IExldCdzIHNlZS4=')
"Is this name url safe??? Let's see."

Tarek

-- 
Tarek Ziadé | Nuxeo R&D (Paris, France)
CPS Plateform : http://www.cps-project.org
mail: tziade at nuxeo.com | tel: +33 (0) 6 30 37 02 63
You need Zope 3 - http://www.z3lab.org/



More information about the Zope3-Checkins mailing list