diff --git a/BeautifulSoup.py b/BeautifulSoup.py index 748e6fe..31ff0e5 100644 --- a/BeautifulSoup.py +++ b/BeautifulSoup.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + """Beautiful Soup Elixir and Tonic "The Screen-Scraper's Friend" diff --git a/__init__.py b/__init__.py index e69de29..40a96af 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/adapter.py b/adapter.py index b7708f4..03c3b59 100644 --- a/adapter.py +++ b/adapter.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + class LoginRequiredException(Exception): def __init__(self, url): self.url = url diff --git a/constants.py b/constants.py index 294ae4b..dc185eb 100644 --- a/constants.py +++ b/constants.py @@ -27,7 +27,7 @@ h7 { text-align: left; font-size: large; font-weight: bold; } MIMETYPE = '''application/epub+zip''' -TITLE_HEADER = ''' +TITLE_HEADER = ''' %s - %s

%s by %s

@@ -41,7 +41,7 @@ TITLE_FOOTER = '''
''' -CONTAINER = ''' +CONTAINER = ''' diff --git a/downloader.py b/downloader.py index f8ca80c..bee778c 100644 --- a/downloader.py +++ b/downloader.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os import re import sys diff --git a/fictionalley.py b/fictionalley.py index 56d14f0..da81a4c 100644 --- a/fictionalley.py +++ b/fictionalley.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os import re import sys diff --git a/html2text.py b/html2text.py index 5d61b9a..ce6e1d3 100644 --- a/html2text.py +++ b/html2text.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- + """html2text: Turn HTML into equivalent Markdown-structured text.""" __version__ = "2.37" __author__ = "Aaron Swartz (me@aaronsw.com)" diff --git a/html_constants.py b/html_constants.py index c698e8f..f160a8a 100644 --- a/html_constants.py +++ b/html_constants.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + XHTML_START = ''' diff --git a/output.py b/output.py index c2f87c2..e028237 100644 --- a/output.py +++ b/output.py @@ -5,6 +5,7 @@ import re import sys import cgi import uuid +import unicodedata import codecs import shutil import string @@ -123,7 +124,7 @@ class EPubFanficWriter(FanficWriter): if self.inmemory: self.files[fileName] = StringIO.StringIO() else: - self.files[fileName] = open(self.directory + '/' + fileName, 'w') + self.files[fileName] = open(self.directory + '/' + fileName, encoding='utf-8', mode='w') self._writeFile(fileName, data) @@ -182,7 +183,7 @@ class EPubFanficWriter(FanficWriter): # BeautifulStoneSoup doesn't have any selfClosingTags by default. # hr & br needs to be if they're going to work. # Some stories do use multiple br tags as their section breaks... - self.soup = bs.BeautifulStoneSoup(text.decode('utf-8'), selfClosingTags=('br','hr')) + self.soup = bs.BeautifulStoneSoup(text, selfClosingTags=('br','hr')) allTags = self.soup.findAll(recursive=True) for t in allTags: @@ -349,6 +350,15 @@ def replaceNumberEntities(data): def removeEntities(text): # replace numeric versions of [&<>] with named versions. + + try: + t = text.decode('utf-8') + except UnicodeEncodeError, e: + try: + t = text.encode ('ascii', 'xmlcharrefreplace') + except UnicodeEncodeError, e: + t = text + text = t text = re.sub(r'�*38;','&',text) text = re.sub(r'�*60;','<',text) text = re.sub(r'�*62;','>',text) diff --git a/twilighted.py b/twilighted.py index 5551f0e..764502e 100644 --- a/twilighted.py +++ b/twilighted.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os import re import sys diff --git a/twipassword.py b/twipassword.py index 466686f..105c09c 100644 --- a/twipassword.py +++ b/twipassword.py @@ -1,2 +1,4 @@ +# -*- coding: utf-8 -*- + # This is really for the web version. downalod.py will ask. password='somepass' diff --git a/zipdir.py b/zipdir.py index f9a79ac..597b4f8 100644 --- a/zipdir.py +++ b/zipdir.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os import zipfile import logging