[Python 3 compability] decode function used in 'needsQuoting' function

is not available on Python 3.
This commit is contained in:
Murtuza Zabuawala 2016-01-04 17:08:48 +05:30 committed by Ashesh Vashi
parent eed1590a51
commit b309b1ffb8

View File

@ -797,52 +797,56 @@ class Driver(BaseDriver):
@staticmethod @staticmethod
def needsQuoting(key, forTypes): def needsQuoting(key, forTypes):
# Python 3 does not require the decoding of value
if hasattr(str, 'decode'):
value = key.decode() value = key.decode()
valNoArray = value.decode() else:
value = key
valNoArray = value
# check if the string is number or not # check if the string is number or not
if (isinstance(value, int)): if (isinstance(value, int)):
return True; return True;
# certain types should not be quoted even though it contains a space. Evilness. # certain types should not be quoted even though it contains a space. Evilness.
elif forTypes and value[-2:] == u"[]": elif forTypes and value[-2:] == u"[]":
valNoArray = value[:-2] valNoArray = value[:-2]
if forTypes and valNoArray.lower() in [ if forTypes and valNoArray.lower() in [
u"bit varying" u"bit varying"
u"\"char\"", u"\"char\"",
u"character varying", u"character varying",
u"double precision" u"double precision"
u"timestamp without time zone" u"timestamp without time zone"
u"timestamp with time zone" u"timestamp with time zone"
u"time without time zone" u"time without time zone"
u"time with time zone" u"time with time zone"
u"\"trigger\"" u"\"trigger\""
u"\"unknown\"" u"\"unknown\""
]: ]:
return False return False
if u'0' <= valNoArray[0] <= u'9': if u'0' <= valNoArray[0] <= u'9':
return True
for c in valNoArray:
if not (u'a' <= c <= u'z') and c != u'_':
return True return True
for c in valNoArray: # check string is keywaord or not
if not (u'a' <= c <= u'z') and c != u'_': category = Driver.ScanKeywordExtraLookup(value)
return True
# check string is keywaord or not if category is None:
category = Driver.ScanKeywordExtraLookup(value) return False
if category is None: # UNRESERVED_KEYWORD
return False if category == 0:
return False
# UNRESERVED_KEYWORD # COL_NAME_KEYWORD
if category == 0: if forTypes and category == 3:
return False return False
# COL_NAME_KEYWORD return True
if forTypes and category == 3:
return False
return True
@staticmethod @staticmethod
def qtTypeIdent(conn, *args): def qtTypeIdent(conn, *args):