From 84d405894c4236c1d2bb54c673a71e4a8e78a2ec Mon Sep 17 00:00:00 2001 From: Ashesh Vashi Date: Thu, 14 Sep 2017 23:42:37 +0530 Subject: Moving the encrypt_password method from the connection class to the psycopgmodule, and exported it from psycopg2.extensions as per review comments. --- lib/extensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/extensions.py b/lib/extensions.py index 91b8133..47155bb 100644 --- a/lib/extensions.py +++ b/lib/extensions.py @@ -63,7 +63,7 @@ from psycopg2._psycopg import ( # noqa string_types, binary_types, new_type, new_array_type, register_type, ISQLQuote, Notify, Diagnostics, Column, QueryCanceledError, TransactionRollbackError, - set_wait_callback, get_wait_callback, ) + set_wait_callback, get_wait_callback, encrypt_password, ) """Isolation level values.""" -- cgit v1.2.1 From ddb87b7727793ef1d49f3915ad4b2399aeb6ef78 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 29 Jan 2018 02:41:44 +0000 Subject: Convert fields names into valid Python identifiers in NamedTupleCursor Close #211. --- lib/extras.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/extras.py b/lib/extras.py index 68df344..1f85d53 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -363,7 +363,17 @@ class NamedTupleCursor(_cursor): return def _make_nt(self): - return namedtuple("Record", [d[0] for d in self.description or ()]) + def f(s): + # NOTE: Python 3 actually allows unicode chars in fields + s = _re.sub('[^a-zA-Z0-9_]', '_', s) + # Python identifier cannot start with numbers, namedtuple fields + # cannot start with underscore. So... + if _re.match('^[0-9_]', s): + s = 'f' + s + + return s + + return namedtuple("Record", [f(d[0]) for d in self.description or ()]) class LoggingConnection(_connection): -- cgit v1.2.1 From bc84b6233eaa1e7a6302b51f8ab8950534ff1813 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 13 May 2018 23:51:21 +0100 Subject: Allow non-ascii chars in namedtuple fields They can be valid chars in Python 3. Or maybe not? In which case Python will throw an exception, but that's fine. Fix regression introduced fixing #211 --- lib/extras.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1