Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   html codes (http://www.velocityreviews.com/forums/t647876-html-codes.html)

Daniel Fetchinson 12-09-2008 07:51 AM

html codes
 
Hi folks,

I came across a javascript library that returns all sorts of html
codes in the cookies it sets and I need my web framework (written in
python :)) to decode them. I'm aware of htmlentitydefs but
htmlentitydefs.entitydefs.keys( ) are of the form '&#xxx' but this
javascript library uses stuff like '%3A' for the ':' for example. The
conversion is here:

http://www.ascii.cl/htmlcodes.htm

Is there a python package/module/whatever that does the conversion for
me or do I have to write a little wrapper myself (and introduce bugs
while doing so :))?

Cheers,
Daniel

--
Psss, psss, put it down! - http://www.cafepress.com/putitdown

Peter Otten 12-09-2008 08:19 AM

Re: html codes
 
Daniel Fetchinson wrote:

> I came across a javascript library that returns all sorts of html
> codes in the cookies it sets and I need my web framework (written in
> python :)) to decode them. I'm aware of htmlentitydefs but
> htmlentitydefs.entitydefs.keys( ) are of the form '&#xxx' but this
> javascript library uses stuff like '%3A' for the ':' for example. The
> conversion is here:
>
> http://www.ascii.cl/htmlcodes.htm
>
> Is there a python package/module/whatever that does the conversion for
> me or do I have to write a little wrapper myself (and introduce bugs
> while doing so :))?


>>> import urllib
>>> urllib.quote("Löblich ähnlich üblich")

'L%C3%B6blich%20%C3%A4hnlich%20%C3%BCblich'
>>> urllib.unquote(_)

'L\xc3\xb6blich \xc3\xa4hnlich \xc3\xbcblich'
>>> print _

Löblich ähnlich üblich

If you care about the encoding you have to encode/decode explicitly:

>>> urllib.quote(u"Löblich ähnlich üblich".encode("latin1"))

'L%F6blich%20%E4hnlich%20%FCblich'
>>> urllib.unquote(_).decode("latin1")

u'L\xf6blich \xe4hnlich \xfcblich'

Peter

Daniel Fetchinson 12-09-2008 04:14 PM

Re: html codes
 
>> I came across a javascript library that returns all sorts of html
>> codes in the cookies it sets and I need my web framework (written in
>> python :)) to decode them. I'm aware of htmlentitydefs but
>> htmlentitydefs.entitydefs.keys( ) are of the form '&#xxx' but this
>> javascript library uses stuff like '%3A' for the ':' for example. The
>> conversion is here:
>>
>> http://www.ascii.cl/htmlcodes.htm
>>
>> Is there a python package/module/whatever that does the conversion for
>> me or do I have to write a little wrapper myself (and introduce bugs
>> while doing so :))?

>
>>>> import urllib
>>>> urllib.quote("Löblich ähnlich üblich")

> 'L%C3%B6blich%20%C3%A4hnlich%20%C3%BCblich'
>>>> urllib.unquote(_)

> 'L\xc3\xb6blich \xc3\xa4hnlich \xc3\xbcblich'
>>>> print _

> Löblich ähnlich üblich
>
> If you care about the encoding you have to encode/decode explicitly:
>
>>>> urllib.quote(u"Löblich ähnlich üblich".encode("latin1"))

> 'L%F6blich%20%E4hnlich%20%FCblich'
>>>> urllib.unquote(_).decode("latin1")

> u'L\xf6blich \xe4hnlich \xfcblich'


Thanks a lot guys!

Cheers,
Daniel


--
Psss, psss, put it down! - http://www.cafepress.com/putitdown


All times are GMT. The time now is 10:44 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57