Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion How do you htmlentities in Python
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Thomas Jollans  
View profile  
 More options Jun 5 2007, 2:14 am
Newsgroups: comp.lang.python
From: "Thomas Jollans" <tho...@jollans.NOSPAM.com>
Date: Mon, 4 Jun 2007 17:14:56 +0100
Local: Tues, Jun 5 2007 2:14 am
Subject: Re: How do you htmlentities in Python
"Adam Atlas" <a...@atlas.st> wrote in message

news:1180965792.757685.132580@q75g2000hsh.googlegroups.com...

> As far as I know, there isn't a standard idiom to do this, but it's
> still a one-liner. Untested, but I think this should work:

> import re
> from htmlentitydefs import name2codepoint
> def htmlentitydecode(s):
>    return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
>         name2codepoint[m.group(1)], s)

'&(%s);' won't quite work: HTML (and, I assume, SGML, but not XHTML being
XML) allows you to skip the semicolon after the entity if it's followed by a
white space (IIRC). Should this be respected, it looks more like this:
r'&(%s)([;\s]|$)'

Also, this completely ignores non-name entities as also found in XML. (eg
%x20; for ' ' or so) Maybe some part of the HTMLParser module is useful, I
wouldn't know. IMHO, these particular batteries aren't too commonly needed.

Regards,
Thomas Jollans


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google