|
4 | 4 | from xml.sax import handler, make_parser |
5 | 5 | import json |
6 | 6 | import re |
7 | | -import sys |
8 | 7 | import time |
9 | 8 |
|
10 | 9 | from overpy import exception |
|
13 | 12 | __uri__, __version__ |
14 | 13 | ) |
15 | 14 |
|
16 | | -PY2 = sys.version_info[0] == 2 |
17 | | -PY3 = sys.version_info[0] == 3 |
18 | | - |
19 | 15 | XML_PARSER_DOM = 1 |
20 | 16 | XML_PARSER_SAX = 2 |
21 | 17 |
|
|
29 | 25 | "visible": lambda v: v.lower() == "true" |
30 | 26 | } |
31 | 27 |
|
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 |
38 | 30 |
|
39 | 31 |
|
40 | 32 | def is_valid_type(element, cls): |
@@ -142,11 +134,7 @@ def query(self, query): |
142 | 134 | f.close() |
143 | 135 |
|
144 | 136 | 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") |
150 | 138 |
|
151 | 139 | if content_type == "application/json": |
152 | 140 | return self.parse_json(response) |
@@ -234,9 +222,6 @@ def parse_xml(self, data, encoding="utf-8", parser=None): |
234 | 222 |
|
235 | 223 | if isinstance(data, bytes): |
236 | 224 | data = data.decode(encoding) |
237 | | - if PY2 and not isinstance(data, str): |
238 | | - # Python 2.x: Convert unicode strings |
239 | | - data = data.encode(encoding) |
240 | 225 |
|
241 | 226 | m = re.compile("<remark>(?P<msg>[^<>]*)</remark>").search(data) |
242 | 227 | if m: |
@@ -399,10 +384,7 @@ def from_xml(cls, data, api=None, parser=None): |
399 | 384 | result.append(elem_cls.from_xml(child, result=result)) |
400 | 385 |
|
401 | 386 | 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 |
406 | 388 | source = StringIO(data) |
407 | 389 | sax_handler = OSMSAXHandler(result) |
408 | 390 | parser = make_parser() |
|
0 commit comments