Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > html codes

Reply
Thread Tools

html codes

 
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-09-2008
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
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      12-09-2008
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
 
Reply With Quote
 
 
 
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-09-2008
>> 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("Lblich hnlich blich")

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

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

> Lblich hnlich blich
>
> If you care about the encoding you have to encode/decode explicitly:
>
>>>> urllib.quote(u"Lblich 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write codes to connect access database using html codes hiralcp Software 0 12-18-2007 08:49 PM
How to use file I/o codes with form and controls codes Allen ASP .Net 1 12-03-2007 12:04 AM
Virtual Key Codes, Scan Codes and ASCII Codes in C gj_williams2000@yahoo.co.uk C Programming 2 08-20-2005 11:04 AM
RegEx replace of html codes to ascii codes Greg -- ASP .Net 4 08-09-2005 07:27 PM
Converting accent characters to html codes Alexandre Soares ASP .Net 1 09-01-2004 04:55 PM



Advertisments