summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2007-09-27 17:23:41 +0000
committerJason Kirtland <jek@discorporate.us>2007-09-27 17:23:41 +0000
commitc1221b7cd3392104a2ad0b183a4b44485d3166c4 (patch)
tree1eabd870ca4b6eee7448b210e11f7e2a550bc470 /lib/sqlalchemy/sql/compiler.py
parente3b06dc83e7990f07abb00287be7a4ab2d1e4494 (diff)
downloadsqlalchemy-c1221b7cd3392104a2ad0b183a4b44485d3166c4.tar.gz
- The IdentifierPreprarer's _requires_quotes test is now regex based.
Any out-of-tree dialects that provide custom sets of legal_characters or illegal_initial_characters will need to move to regexes or override _requires_quotes.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 4fca6b2ec..6d22da1de 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -36,10 +36,8 @@ RESERVED_WORDS = util.Set([
'then', 'to', 'trailing', 'true', 'union', 'unique', 'user',
'using', 'verbose', 'when', 'where'])
-LEGAL_CHARACTERS = util.Set(string.ascii_lowercase +
- string.ascii_uppercase +
- string.digits + '_$')
-ILLEGAL_INITIAL_CHARACTERS = util.Set(string.digits + '$')
+LEGAL_CHARACTERS = re.compile(r'^[A-Z0-9_$]+$', re.I)
+ILLEGAL_INITIAL_CHARACTERS = re.compile(r'[0-9$]')
BIND_PARAMS = re.compile(r'(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])', re.UNICODE)
BIND_PARAMS_ESC = re.compile(r'\x5c(:[\w\$]+)(?![:\w\$])', re.UNICODE)
@@ -979,11 +977,11 @@ class IdentifierPreparer(object):
def _requires_quotes(self, value):
"""Return True if the given identifier requires quoting."""
- return \
- value in self.reserved_words \
- or (value[0] in self.illegal_initial_characters) \
- or bool(len([x for x in unicode(value) if x not in self.legal_characters])) \
- or (value.lower() != value)
+ lc_value = value.lower()
+ return (lc_value in self.reserved_words
+ or self.illegal_initial_characters.match(value[0])
+ or not self.legal_characters.match(unicode(value))
+ or (lc_value != value))
def __generic_obj_format(self, obj, ident):
if getattr(obj, 'quote', False):