mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
fix sqlite3 string escaping
This commit is contained in:
parent
b927789c4b
commit
6d6f2c9aa0
2
setup.py
2
setup.py
@ -40,7 +40,7 @@ except:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='warcprox',
|
name='warcprox',
|
||||||
version='2.4b2.dev148',
|
version='2.4b2.dev149',
|
||||||
description='WARC writing MITM HTTP/S proxy',
|
description='WARC writing MITM HTTP/S proxy',
|
||||||
url='https://github.com/internetarchive/warcprox',
|
url='https://github.com/internetarchive/warcprox',
|
||||||
author='Noah Levitt',
|
author='Noah Levitt',
|
||||||
|
@ -103,17 +103,13 @@ class TroughClient(object):
|
|||||||
elif isinstance(x, bool):
|
elif isinstance(x, bool):
|
||||||
return int(x)
|
return int(x)
|
||||||
elif isinstance(x, str) or isinstance(x, bytes):
|
elif isinstance(x, str) or isinstance(x, bytes):
|
||||||
# py3: repr(u'abc') => 'abc'
|
# the only character that needs escaped in sqlite string literals
|
||||||
# repr(b'abc') => b'abc'
|
# is single-quote, which is escaped as two single-quotes
|
||||||
# py2: repr(u'abc') => u'abc'
|
if isinstance(x, bytes):
|
||||||
# repr(b'abc') => 'abc'
|
s = x.decode('utf-8')
|
||||||
# Repr gives us a prefix we don't want in different situations
|
|
||||||
# depending on whether this is py2 or py3. Chop it off either way.
|
|
||||||
r = repr(x)
|
|
||||||
if r[:1] == "'":
|
|
||||||
return r
|
|
||||||
else:
|
else:
|
||||||
return r[1:]
|
s = x
|
||||||
|
return "'" + s.replace("'", "''") + "'"
|
||||||
elif isinstance(x, (int, float)):
|
elif isinstance(x, (int, float)):
|
||||||
return x
|
return x
|
||||||
else:
|
else:
|
||||||
@ -196,7 +192,7 @@ class TroughClient(object):
|
|||||||
response.status_code, response.reason, response.text,
|
response.status_code, response.reason, response.text,
|
||||||
write_url, sql)
|
write_url, sql)
|
||||||
return
|
return
|
||||||
self.logger.debug('posted %r to %s', sql, write_url)
|
self.logger.debug('posted to %s: %r', write_url, sql)
|
||||||
|
|
||||||
def read(self, segment_id, sql_tmpl, values=()):
|
def read(self, segment_id, sql_tmpl, values=()):
|
||||||
read_url = self.read_url(segment_id)
|
read_url = self.read_url(segment_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user