Skip to content

Commit 29ddf0c

Browse files
committed
http: remove chunk capability
There is no need to support chunks in python3 as the `read()` interface does that for us. Furthermore, this improves fetch performance in large queries (c.f. #111). Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
1 parent 5ab8845 commit 29ddf0c

File tree

2 files changed

+1
-22
lines changed

2 files changed

+1
-22
lines changed

overpy/__init__.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Overpass:
6060
"""
6161
Class to access the Overpass API
6262
63-
:param read_chunk_size: Max size of each chunk read from the server response
6463
:param url: Optional URL of the Overpass server. Defaults to http://overpass-api.de/api/interpreter
6564
:param xml_parser: The xml parser to use
6665
:param max_retry_count: Max number of retries (Default: default_max_retry_count)
@@ -70,9 +69,6 @@ class Overpass:
7069
#: Global max number of retries (Default: 0)
7170
default_max_retry_count: ClassVar[int] = 0
7271

73-
#: Max size of each chunk read from the server response
74-
default_read_chunk_size: ClassVar[int] = 4096
75-
7672
#: Global time to wait between tries (Default: 1.0s)
7773
default_retry_timeout: ClassVar[float] = 1.0
7874

@@ -81,7 +77,6 @@ class Overpass:
8177

8278
def __init__(
8379
self,
84-
read_chunk_size: Optional[int] = None,
8580
url: Optional[str] = None,
8681
xml_parser: int = XML_PARSER_SAX,
8782
max_retry_count: int = None,
@@ -94,11 +89,6 @@ def __init__(
9489

9590
self._regex_extract_error_msg = re.compile(br"\<p\>(?P<msg>\<strong\s.*?)\</p\>")
9691
self._regex_remove_tag = re.compile(b"<[^>]*?>")
97-
if read_chunk_size is None:
98-
read_chunk_size = self.default_read_chunk_size
99-
100-
#: The chunk size for this instance
101-
self.read_chunk_size = read_chunk_size
10292

10393
if max_retry_count is None:
10494
max_retry_count = self.default_max_retry_count
@@ -151,9 +141,7 @@ def query(self, query: Union[bytes, str]) -> "Result":
151141
response = b""
152142
try:
153143
with urlopen(self.url, query) as f:
154-
f_read = partial(f.read, self.read_chunk_size)
155-
for data in iter(f_read, b""):
156-
response += data
144+
response = f.read()
157145
except HTTPError as exc:
158146
f = exc
159147

tests/test_request.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,6 @@ def do_POST(self):
128128

129129

130130
class TestQuery:
131-
def test_chunk_size(self):
132-
url, server = new_server_thread(HandleResponseJSON)
133-
134-
api = overpy.Overpass(read_chunk_size=128)
135-
api.url = url
136-
result = api.query("[out:json];node(50.745,7.17,50.75,7.18);out;")
137-
stop_server_thread(server)
138-
assert len(result.nodes) > 0
139-
140131
def test_overpass_syntax_error(self):
141132
url, server = new_server_thread(HandleOverpassBadRequest)
142133

0 commit comments

Comments
 (0)