mirror of
https://github.com/wassname/FanFicFare.git
synced 2026-09-10 11:40:24 +08:00
Another work around for SGMLParser's entity handling. —again v —a;gain
This commit is contained in:
@@ -27,7 +27,7 @@ class FanFictionDownLoaderBase(InterfaceActionBase):
|
||||
description = 'UI plugin to download FanFiction stories from various sites.'
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
author = 'Jim Miller'
|
||||
version = (1, 5, 10)
|
||||
version = (1, 5, 11)
|
||||
minimum_calibre_version = (0, 8, 30)
|
||||
|
||||
#: This field defines the GUI plugin class that contains all the code
|
||||
|
||||
@@ -331,10 +331,6 @@ class BaseSiteAdapter(Configurable):
|
||||
# This is primarily for epub updates.
|
||||
return re.sub(r"</?body>\r?\n?","",retval)
|
||||
|
||||
fullmon = {"January":"01", "February":"02", "March":"03", "April":"04", "May":"05",
|
||||
"June":"06","July":"07", "August":"08", "September":"09", "October":"10",
|
||||
"November":"11", "December":"12" }
|
||||
|
||||
def cachedfetch(realfetch,cache,url):
|
||||
if url in cache:
|
||||
print("cache hit")
|
||||
@@ -342,6 +338,9 @@ def cachedfetch(realfetch,cache,url):
|
||||
else:
|
||||
return realfetch(url)
|
||||
|
||||
fullmon = {"January":"01", "February":"02", "March":"03", "April":"04", "May":"05",
|
||||
"June":"06","July":"07", "August":"08", "September":"09", "October":"10",
|
||||
"November":"11", "December":"12" }
|
||||
|
||||
def makeDate(string,format):
|
||||
# Surprise! Abstracting this turned out to be more useful than
|
||||
|
||||
@@ -23,11 +23,16 @@ def _unirepl(match):
|
||||
radix=16
|
||||
else:
|
||||
radix=10
|
||||
value = int(match.group(2), radix )
|
||||
return unichr(value)
|
||||
value = int(match.group(2), radix)
|
||||
return "%s%s"%(unichr(value),match.group(3))
|
||||
|
||||
def _replaceNumberEntities(data):
|
||||
p = re.compile(r'&#(x?)([0-9a-fA-F]+);')
|
||||
# The same brokenish entity parsing in SGMLParser that inserts ';'
|
||||
# after non-entities will also insert ';' incorrectly after number
|
||||
# entities, including part of the next word if it's a-z.
|
||||
# "Don't—ever—do—that—again," becomes
|
||||
# "Don't—e;ver—d;o—that—a;gain,"
|
||||
p = re.compile(r'&#(x?)([0-9a-fA-F]{,4})([0-9a-fA-F]*);')
|
||||
return p.sub(_unirepl, data)
|
||||
|
||||
def _replaceNotEntities(data):
|
||||
@@ -50,9 +55,6 @@ def removeAllEntities(text):
|
||||
return removeEntities(text).replace('<', '<').replace('>', '>').replace('&', '&')
|
||||
|
||||
def removeEntities(text):
|
||||
|
||||
# replace numeric versions of [&<>] with named versions,
|
||||
# then replace named versions with actual characters,
|
||||
|
||||
if text is None:
|
||||
return ""
|
||||
@@ -67,6 +69,8 @@ def removeEntities(text):
|
||||
except UnicodeEncodeError, e:
|
||||
t = text
|
||||
text = t
|
||||
# replace numeric versions of [&<>] with named versions,
|
||||
# then replace named versions with actual characters,
|
||||
text = re.sub(r'�*38;','&',text)
|
||||
text = re.sub(r'�*60;','<',text)
|
||||
text = re.sub(r'�*62;','>',text)
|
||||
|
||||
@@ -216,7 +216,7 @@ class Story:
|
||||
for (p,v) in self.replacements:
|
||||
if (isinstance(value,str) or isinstance(value,unicode)) and re.match(p,value):
|
||||
value = re.sub(p,v,value)
|
||||
return value;
|
||||
return value
|
||||
|
||||
def getMetadata(self, key, removeallentities=False):
|
||||
value = None
|
||||
|
||||
Reference in New Issue
Block a user