summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-05-20 17:57:34 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-05-20 17:57:34 +0100
commit0161d54dbb54ae363089c5ab82f2101cb9df6466 (patch)
tree45fc087acc4bd7b10eee12ee99399031004b141c /lib
parent36f0db81d228b612a66abf6c880d1d6629da77fc (diff)
parenta8d4f37b191399639ce80df0b5316702ca9f7e5f (diff)
downloadpsycopg2-0161d54dbb54ae363089c5ab82f2101cb9df6466.tar.gz
Merge branch 'master' into encrypt-pass
Diffstat (limited to 'lib')
-rw-r--r--lib/extras.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/extras.py b/lib/extras.py
index 1f85d53..9c26ccb 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -363,12 +363,15 @@ class NamedTupleCursor(_cursor):
return
def _make_nt(self):
+ # ascii except alnum and underscore
+ nochars = ' !"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~'
+ re_clean = _re.compile('[' + _re.escape(nochars) + ']')
+
def f(s):
- # NOTE: Python 3 actually allows unicode chars in fields
- s = _re.sub('[^a-zA-Z0-9_]', '_', s)
+ s = re_clean.sub('_', s)
# Python identifier cannot start with numbers, namedtuple fields
# cannot start with underscore. So...
- if _re.match('^[0-9_]', s):
+ if s[0] == '_' or '0' <= s[0] <= '9':
s = 'f' + s
return s