summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-02-12 17:29:44 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-02-24 10:39:04 +0100
commit58c30ce0ff09d89b240248fb8efc58372f6cf26d (patch)
tree1e71000b4b270c87cc14aa8990cd0970a9a4657a
parentaf741607ead03c6616f93a21eeebcdd66ea4cd7a (diff)
downloadurlgrabber-58c30ce0ff09d89b240248fb8efc58372f6cf26d.tar.gz
Simplify quoter function declaration
There isn't much point in defining a nested function which doesn't use its closure for anything. Also doing it just once is generally quicker.
-rw-r--r--urlgrabber/grabber.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 5d337e5..c0a0572 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -2030,10 +2030,10 @@ def retrygrab(url, filename=None, copy_local=0, close_connection=0,
#
#####################################################################
-_quoter_map = {}
-for c in '%[(,)] \n':
- _quoter_map[c] = '%%%02x' % ord(c)
-del c
+def _quoter(c):
+ if c in '%[(,)] \n':
+ return '%%%02x' % ord(c)
+ return c
def _dumps(v):
if v is None: return 'None'
@@ -2044,13 +2044,12 @@ def _dumps(v):
if isinstance(v, text_type):
v = v.encode('UTF8')
if isinstance(v, str):
- def quoter(c): return _quoter_map.get(c, c)
- return "'%s'" % ''.join(map(quoter, v))
+ return "'%s'" % ''.join(map(_quoter, v))
if isinstance(v, tuple):
return "(%s)" % ','.join(map(_dumps, v))
if isinstance(v, list):
return "[%s]" % ','.join(map(_dumps, v))
- raise TypeError('Can\'t serialize %s' % v)
+ raise TypeError("Can't serialize %s" % v)
def _loads(s):
def decode(v):