From 7173d11ba2ad2275951c973a784b9f28396dea90 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 21 Jun 2011 18:34:14 -0400 Subject: [PATCH] - Use urllib.parse_qsl() in Python 2.6 and above, no deprecation warning about cgi.parse_qsl() [ticket:1682] --- CHANGES | 5 +++++ lib/sqlalchemy/engine/url.py | 8 ++++---- lib/sqlalchemy/util/__init__.py | 3 ++- lib/sqlalchemy/util/compat.py | 8 ++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 09f45d58bc..49fa1e576f 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,11 @@ CHANGES after from_statement() were called. [ticket:2199]. Also in 0.6.9. +- engine + - Use urllib.parse_qsl() in Python 2.6 and above, + no deprecation warning about cgi.parse_qsl() + [ticket:1682] + - mssql - Adjusted the pyodbc dialect such that bound values are passed as bytes and not unicode diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 7d5e0692f7..0734f6035f 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -12,8 +12,8 @@ with a string argument; alternatively, the URL is a public-facing construct whic be used directly and is also accepted directly by ``create_engine()``. """ -import re, cgi, sys, urllib -from sqlalchemy import exc +import re, urllib +from sqlalchemy import exc, util class URL(object): @@ -193,7 +193,7 @@ def _parse_rfc1738_args(name): if components['database'] is not None: tokens = components['database'].split('?', 2) components['database'] = tokens[0] - query = (len(tokens) > 1 and dict(cgi.parse_qsl(tokens[1]))) or None + query = (len(tokens) > 1 and dict(util.parse_qsl(tokens[1]))) or None # Py2K if query is not None: query = dict((k.encode('ascii'), query[k]) for k in query) @@ -215,7 +215,7 @@ def _parse_keyvalue_args(name): m = re.match( r'(\w+)://(.*)', name) if m is not None: (name, args) = m.group(1, 2) - opts = dict( cgi.parse_qsl( args ) ) + opts = dict( util.parse_qsl( args ) ) return URL(name, *opts) else: return None diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 93c418edae..827fce088d 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -6,7 +6,8 @@ from compat import callable, cmp, reduce, defaultdict, py25_dict, \ threading, py3k, jython, pypy, win32, set_types, buffer, pickle, \ - update_wrapper, partial, md5_hex, decode_slice, dottedgetter + update_wrapper, partial, md5_hex, decode_slice, dottedgetter,\ + parse_qsl from _collections import NamedTuple, ImmutableContainer, immutabledict, \ Properties, OrderedProperties, ImmutableProperties, OrderedDict, \ diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 69d648498a..866c0c2167 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -81,6 +81,14 @@ except ImportError: return func(*(args + fargs), **newkeywords) return newfunc + +if sys.version_info < (2, 6): + # emits a nasty deprecation warning + # in newer pythons + from cgi import parse_qsl +else: + from urlparse import parse_qsl + if py3k: # they're bringing it back in 3.2. brilliant ! def callable(fn): -- 2.39.5