summaryrefslogtreecommitdiff
path: root/lib/extras.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extras.py')
-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