Created
April 28, 2011 07:45
-
-
Save MattDietz/945979 to your computer and use it in GitHub Desktop.
pyhole
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pyhole/utils.py b/pyhole/utils.py | |
index 86a0180..5ff46e3 100644 | |
--- a/pyhole/utils.py | |
+++ b/pyhole/utils.py | |
@@ -71,18 +71,20 @@ def spawn(func): | |
def decode_entities(html): | |
"""Strip HTML entities from a string""" | |
- html = re.sub("<[^>]*?>", "", html) | |
- html = re.sub(" ", " ", html) | |
- html = re.sub("&", "&", html) | |
- html = re.sub(""", "\"", html) | |
- html = re.sub("—", "-", html) | |
- html = re.sub("’", "'", html) | |
- html = re.sub("“", "\"", html) | |
- html = re.sub("”", "\"", html) | |
- html = re.sub("…", "...", html) | |
- html = filter(lambda x: x in string.printable, html) | |
- | |
- return html.strip() | |
+ entities = [ | |
+ ("<[^>]*?>",""), | |
+ (" "," "), | |
+ ("&","&"), | |
+ (""","\""), | |
+ ("—","-"), | |
+ ("’","'"), | |
+ ("“","\""), | |
+ ("”","\""), | |
+ ("…","...")] | |
+ | |
+ #YARLY | |
+ html = reduce(lambda a,b: re.sub(b[0], b[1], a), entities, html) | |
+ return filter(lambda x: ord(x) > 9 and ord(x) < 127, html).strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment