Skip to content

Commit

Permalink
Make urllib/urlparse imports Py3 compatible
Browse files Browse the repository at this point in the history
The urlencode function moved in Python 3, as did the urlparse library.
This commit ensures that both are referenced through the `nsq._compat`
module.
  • Loading branch information
nickstenning committed May 13, 2016
1 parent a067546 commit aa1facb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions nsq/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def to_bytes(x, charset='utf-8', errors='strict'):
if isinstance(x, unicode):
return x.encode(charset, errors)
raise TypeError('expected bytes or a string, not %r' % type(x))

try:
from urllib import parse as urlparse
from urllib.parse import urlencode
except ImportError:
import urlparse
from urllib import urlencode
6 changes: 3 additions & 3 deletions nsq/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import logging
import time
import functools
import urllib
import random
import urlparse
import cgi
import warnings
import inspect
Expand All @@ -20,6 +18,8 @@

from ._compat import string_types
from ._compat import to_bytes
from ._compat import urlencode
from ._compat import urlparse
from .backoff_timer import BackoffTimer
from .client import Client
from . import protocol
Expand Down Expand Up @@ -573,7 +573,7 @@ def query_lookupd(self):

params = cgi.parse_qs(query)
params['topic'] = self.topic
query = urllib.urlencode(_utf8_params(params), doseq=1)
query = urlencode(_utf8_params(params), doseq=1)
lookupd_url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))

req = tornado.httpclient.HTTPRequest(
Expand Down

0 comments on commit aa1facb

Please sign in to comment.