mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3 porting
This commit is contained in:
parent
eb37632940
commit
2b8ac505e2
@ -1,16 +1,15 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
# License: GPLv3 Copyright: 2010, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import copy, ssl
|
||||
import copy
|
||||
import ssl
|
||||
|
||||
from mechanize import Browser as B, HTTPSHandler
|
||||
|
||||
from polyglot import http_client
|
||||
from polyglot.http_cookie import CookieJar, Cookie
|
||||
from polyglot.http_cookie import Cookie, CookieJar
|
||||
|
||||
|
||||
class ModernHTTPSHandler(HTTPSHandler):
|
||||
|
@ -1,6 +1,7 @@
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2010, sengian <sengian1@gmail.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2010, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import re
|
||||
from polyglot.builtins import codepoint_to_chr, map, range, filter
|
||||
@ -24,7 +25,7 @@ def ascii_pat(for_binary=False):
|
||||
if ans is None:
|
||||
chars = set(range(32)) - {9, 10, 13}
|
||||
chars.add(127)
|
||||
pat = u'|'.join(map(codepoint_to_chr, chars))
|
||||
pat = '|'.join(map(codepoint_to_chr, chars))
|
||||
if for_binary:
|
||||
pat = pat.encode('ascii')
|
||||
ans = re.compile(pat)
|
||||
@ -38,14 +39,14 @@ def clean_ascii_chars(txt, charlist=None):
|
||||
This is all control chars except \t, \n and \r
|
||||
'''
|
||||
is_binary = isinstance(txt, bytes)
|
||||
empty = b'' if is_binary else u''
|
||||
empty = b'' if is_binary else ''
|
||||
if not txt:
|
||||
return empty
|
||||
|
||||
if charlist is None:
|
||||
pat = ascii_pat(is_binary)
|
||||
else:
|
||||
pat = u'|'.join(map(codepoint_to_chr, charlist))
|
||||
pat = '|'.join(map(codepoint_to_chr, charlist))
|
||||
if is_binary:
|
||||
pat = pat.encode('utf-8')
|
||||
return pat.sub(empty, txt)
|
||||
@ -57,15 +58,15 @@ def allowed(x):
|
||||
|
||||
|
||||
def py_clean_xml_chars(unicode_string):
|
||||
return u''.join(filter(allowed, unicode_string))
|
||||
return ''.join(filter(allowed, unicode_string))
|
||||
|
||||
|
||||
clean_xml_chars = native_clean_xml_chars or py_clean_xml_chars
|
||||
|
||||
|
||||
def test_clean_xml_chars():
|
||||
raw = u'asd\x02a\U00010437x\ud801b\udffe\ud802'
|
||||
if native_clean_xml_chars(raw) != u'asda\U00010437xb':
|
||||
raw = 'asd\x02a\U00010437x\ud801b\udffe\ud802'
|
||||
if native_clean_xml_chars(raw) != 'asda\U00010437xb':
|
||||
raise ValueError('Failed to XML clean: %r' % raw)
|
||||
|
||||
|
||||
@ -75,7 +76,7 @@ def test_clean_xml_chars():
|
||||
# @param text The HTML (or XML) source text.
|
||||
# @return The plain text, as a Unicode string, if necessary.
|
||||
|
||||
def unescape(text, rm=False, rchar=u''):
|
||||
def unescape(text, rm=False, rchar=''):
|
||||
def fixup(m, rm=rm, rchar=rchar):
|
||||
text = m.group(0)
|
||||
if text[:2] == "&#":
|
||||
|
@ -6,7 +6,7 @@ Created on 13 Jan 2011
|
||||
|
||||
@author: charles
|
||||
'''
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
@ -838,7 +838,7 @@ class BuiltinFormatsSizes(BuiltinFormatterFunction):
|
||||
def evaluate(self, formatter, kwargs, mi, locals):
|
||||
fmt_data = mi.get('format_metadata', {})
|
||||
try:
|
||||
return ','.join(k.upper()+':'+str(v['size']) for k,v in iteritems(fmt_data))
|
||||
return ','.join(k.upper()+':'+unicode_type(v['size']) for k,v in iteritems(fmt_data))
|
||||
except:
|
||||
return ''
|
||||
|
||||
@ -857,7 +857,7 @@ class BuiltinFormatsPaths(BuiltinFormatterFunction):
|
||||
def evaluate(self, formatter, kwargs, mi, locals):
|
||||
fmt_data = mi.get('format_metadata', {})
|
||||
try:
|
||||
return ','.join(k.upper()+':'+str(v['path']) for k,v in iteritems(fmt_data))
|
||||
return ','.join(k.upper()+':'+unicode_type(v['path']) for k,v in iteritems(fmt_data))
|
||||
except:
|
||||
return ''
|
||||
|
||||
@ -1088,7 +1088,7 @@ class BuiltinBooksize(BuiltinFormatterFunction):
|
||||
try:
|
||||
v = mi._proxy_metadata.book_size
|
||||
if v is not None:
|
||||
return str(mi._proxy_metadata.book_size)
|
||||
return unicode_type(mi._proxy_metadata.book_size)
|
||||
return ''
|
||||
except:
|
||||
pass
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import with_statement
|
||||
# License: GPLv3 Copyright: 2010, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from calibre.constants import iswindows, islinux, isbsd
|
||||
from calibre.utils.config_base import tweaks
|
||||
|
Loading…
x
Reference in New Issue
Block a user