Skip to content

Commit edb064d

Browse files
committed
Attempt to import using Python 3 stdlib names first.
1 parent 307d736 commit edb064d

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

github2/issues.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import urllib
1+
try:
2+
from urllib.parse import quote_plus # For Python 3
3+
except ImportError:
4+
from urllib import quote_plus
25

36
from github2.core import (GithubCommand, BaseData, Attribute, DateAttribute,
47
repr_string, requires_auth)
@@ -47,9 +50,8 @@ def search(self, project, term, state="open"):
4750
:param str term: term to search issues for
4851
:param str state: can be either ``open`` or ``closed``.
4952
"""
50-
return self.get_values("search", project, state,
51-
urllib.quote_plus(term), filter="issues",
52-
datatype=Issue)
53+
return self.get_values("search", project, state, quote_plus(term),
54+
filter="issues", datatype=Issue)
5355

5456
def list(self, project, state="open"):
5557
"""Get all issues for project with given state.

github2/request.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33
import re
44
import time
55
import httplib2
6-
from httplib import responses
6+
try:
7+
from http.client import responses # For Python 3
8+
except ImportError:
9+
from httplib import responses
710
try:
811
import json as simplejson # For Python 2.6
912
except ImportError:
1013
import simplejson
1114
from os import path
12-
from urlparse import (urlsplit, urlunsplit)
1315
try:
14-
from urlparse import parse_qs
16+
# For Python 3
17+
from urllib.parse import (parse_qs, quote, urlencode, urlsplit, urlunsplit)
1518
except ImportError:
16-
from cgi import parse_qs
17-
from urllib import urlencode, quote
19+
from urlparse import (urlsplit, urlunsplit)
20+
try:
21+
from urlparse import parse_qs
22+
except ImportError:
23+
from cgi import parse_qs
24+
from urllib import urlencode, quote
1825

1926

2027
#: Hostname for API access

github2/users.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
try:
2+
from urllib.parse import quote_plus # For Python 3
3+
except ImportError:
4+
from urllib import quote_plus
5+
16
from github2.core import (BaseData, GithubCommand, DateAttribute, Attribute,
27
enhanced_by_auth, requires_auth)
3-
import urllib
48

59

610
class User(BaseData):
@@ -48,8 +52,8 @@ def search(self, query):
4852
4953
:param str query: term to search for
5054
"""
51-
return self.get_values("search", urllib.quote_plus(query),
52-
filter="users", datatype=User)
55+
return self.get_values("search", quote_plus(query), filter="users",
56+
datatype=User)
5357

5458
def search_by_email(self, query):
5559
"""Search for users by email address

0 commit comments

Comments
 (0)