Skip to content

Commit dc30736

Browse files
eumirophibos
authored andcommitted
Remove Python2/Python3 switches
1 parent f3af2d8 commit dc30736

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

overpy/__init__.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from xml.sax import handler, make_parser
55
import json
66
import re
7-
import sys
87
import time
98

109
from overpy import exception
@@ -13,9 +12,6 @@
1312
__uri__, __version__
1413
)
1514

16-
PY2 = sys.version_info[0] == 2
17-
PY3 = sys.version_info[0] == 3
18-
1915
XML_PARSER_DOM = 1
2016
XML_PARSER_SAX = 2
2117

@@ -29,12 +25,8 @@
2925
"visible": lambda v: v.lower() == "true"
3026
}
3127

32-
if PY2:
33-
from urllib2 import urlopen
34-
from urllib2 import HTTPError
35-
elif PY3:
36-
from urllib.request import urlopen
37-
from urllib.error import HTTPError
28+
from urllib.request import urlopen
29+
from urllib.error import HTTPError
3830

3931

4032
def is_valid_type(element, cls):
@@ -142,11 +134,7 @@ def query(self, query):
142134
f.close()
143135

144136
if f.code == 200:
145-
if PY2:
146-
http_info = f.info()
147-
content_type = http_info.getheader("content-type")
148-
else:
149-
content_type = f.getheader("Content-Type")
137+
content_type = f.getheader("Content-Type")
150138

151139
if content_type == "application/json":
152140
return self.parse_json(response)
@@ -234,9 +222,6 @@ def parse_xml(self, data, encoding="utf-8", parser=None):
234222

235223
if isinstance(data, bytes):
236224
data = data.decode(encoding)
237-
if PY2 and not isinstance(data, str):
238-
# Python 2.x: Convert unicode strings
239-
data = data.encode(encoding)
240225

241226
m = re.compile("<remark>(?P<msg>[^<>]*)</remark>").search(data)
242227
if m:
@@ -399,10 +384,7 @@ def from_xml(cls, data, api=None, parser=None):
399384
result.append(elem_cls.from_xml(child, result=result))
400385

401386
elif parser == XML_PARSER_SAX:
402-
if PY2:
403-
from StringIO import StringIO
404-
else:
405-
from io import StringIO
387+
from io import StringIO
406388
source = StringIO(data)
407389
sax_handler = OSMSAXHandler(result)
408390
parser = make_parser()

tests/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
import threading
44
from threading import Lock
55

6-
PY2 = sys.version_info[0] == 2
7-
if PY2:
8-
from SocketServer import BaseRequestHandler, TCPServer, ThreadingMixIn
9-
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
10-
else:
11-
from socketserver import BaseRequestHandler, TCPServer, ThreadingMixIn
12-
from http.server import BaseHTTPRequestHandler, HTTPServer
6+
from socketserver import BaseRequestHandler, TCPServer, ThreadingMixIn
7+
from http.server import BaseHTTPRequestHandler, HTTPServer
138

149
TCPServer.allow_reuse_address = True
1510

0 commit comments

Comments
 (0)