python3: add reprlib wrapper to polyglot

This commit is contained in:
Eli Schwartz 2019-03-26 03:15:21 -04:00
parent 696afe85bd
commit 564f053c02
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
7 changed files with 19 additions and 9 deletions

View File

@ -240,7 +240,7 @@ def prints(*args, **kwargs):
file.write(arg) file.write(arg)
count += len(arg) count += len(arg)
except: except:
import repr as reprlib from polyglot import reprlib
arg = reprlib.repr(arg) arg = reprlib.repr(arg)
file.write(arg) file.write(arg)
count += len(arg) count += len(arg)

View File

@ -8,13 +8,13 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import inspect, time, numbers import inspect, time, numbers
from io import BytesIO from io import BytesIO
from repr import repr
from functools import partial from functools import partial
from operator import itemgetter from operator import itemgetter
from calibre.library.field_metadata import fm_as_dict from calibre.library.field_metadata import fm_as_dict
from calibre.db.tests.base import BaseTest from calibre.db.tests.base import BaseTest
from polyglot.builtins import iteritems, range from polyglot.builtins import iteritems, range
from polyglot import reprlib
# Utils {{{ # Utils {{{
@ -32,7 +32,7 @@ class ET(object):
oldres = getattr(old, self.func_name)(*self.args, **self.kwargs) oldres = getattr(old, self.func_name)(*self.args, **self.kwargs)
newres = getattr(legacy, self.func_name)(*self.args, **self.kwargs) newres = getattr(legacy, self.func_name)(*self.args, **self.kwargs)
test.assertEqual(oldres, newres, 'Equivalence test for %s with args: %s and kwargs: %s failed' % ( test.assertEqual(oldres, newres, 'Equivalence test for %s with args: %s and kwargs: %s failed' % (
self.func_name, repr(self.args), repr(self.kwargs))) self.func_name, reprlib.repr(self.args), reprlib.repr(self.kwargs)))
self.retval = newres self.retval = newres
return newres return newres

View File

@ -8,7 +8,6 @@ Wrapper for multi-threaded access to a single sqlite database connection. Serial
all calls. all calls.
''' '''
import sqlite3 as sqlite, traceback, time, uuid, sys, os import sqlite3 as sqlite, traceback, time, uuid, sys, os
import repr as reprlib
from sqlite3 import IntegrityError, OperationalError from sqlite3 import IntegrityError, OperationalError
from threading import Thread from threading import Thread
from threading import RLock from threading import RLock
@ -22,6 +21,7 @@ from calibre.constants import iswindows, DEBUG, plugins
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
from calibre import prints from calibre import prints
from polyglot.builtins import unicode_type from polyglot.builtins import unicode_type
from polyglot import reprlib
from polyglot.queue import Queue from polyglot.queue import Queue
from dateutil.tz import tzoffset from dateutil.tz import tzoffset

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import re, repr as reprlib import re
from io import BytesIO, DEFAULT_BUFFER_SIZE from io import BytesIO, DEFAULT_BUFFER_SIZE
from calibre import as_unicode, force_unicode from calibre import as_unicode, force_unicode
@ -14,7 +14,7 @@ from calibre.ptempfile import SpooledTemporaryFile
from calibre.srv.errors import HTTPSimpleResponse from calibre.srv.errors import HTTPSimpleResponse
from calibre.srv.loop import Connection, READ, WRITE from calibre.srv.loop import Connection, READ, WRITE
from calibre.srv.utils import MultiDict, HTTP1, HTTP11, Accumulator from calibre.srv.utils import MultiDict, HTTP1, HTTP11, Accumulator
from polyglot import http_client from polyglot import http_client, reprlib
from polyglot.urllib import unquote from polyglot.urllib import unquote
protocol_map = {(1, 0):HTTP1, (1, 1):HTTP11} protocol_map = {(1, 0):HTTP1, (1, 1):HTTP11}

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import os, hashlib, uuid, struct, repr as reprlib import os, hashlib, uuid, struct
from collections import namedtuple from collections import namedtuple
from io import BytesIO, DEFAULT_BUFFER_SIZE from io import BytesIO, DEFAULT_BUFFER_SIZE
from itertools import chain, repeat from itertools import chain, repeat
@ -26,7 +26,7 @@ from calibre.srv.utils import (
sort_q_values, get_translator_for_lang, Cookie, fast_now_strftime) sort_q_values, get_translator_for_lang, Cookie, fast_now_strftime)
from calibre.utils.speedups import ReadOnlyFileBuffer from calibre.utils.speedups import ReadOnlyFileBuffer
from calibre.utils.monotonic import monotonic from calibre.utils.monotonic import monotonic
from polyglot import http_client from polyglot import http_client, reprlib
Range = namedtuple('Range', 'start stop size') Range = namedtuple('Range', 'start stop size')
MULTIPART_SEPARATOR = uuid.uuid4().hex.decode('ascii') MULTIPART_SEPARATOR = uuid.uuid4().hex.decode('ascii')

View File

@ -9,7 +9,6 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import errno, socket, select, os, time import errno, socket, select, os, time
from Cookie import SimpleCookie from Cookie import SimpleCookie
from contextlib import closing from contextlib import closing
import repr as reprlib
from email.utils import formatdate from email.utils import formatdate
from operator import itemgetter from operator import itemgetter
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
@ -23,6 +22,7 @@ from calibre.utils.socket_inheritance import set_socket_inherit
from calibre.utils.logging import ThreadSafeLog from calibre.utils.logging import ThreadSafeLog
from calibre.utils.shared_file import share_open, raise_winerror from calibre.utils.shared_file import share_open, raise_winerror
from polyglot.builtins import iteritems, map, unicode_type, range from polyglot.builtins import iteritems, map, unicode_type, range
from polyglot import reprlib
from polyglot.urllib import parse_qs, quote as urlquote from polyglot.urllib import parse_qs, quote as urlquote
HTTP1 = 'HTTP/1.0' HTTP1 = 'HTTP/1.0'

10
src/polyglot/reprlib.py Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
from polyglot.builtins import is_py3
if is_py3:
from reprlib import repr
else:
from repr import repr