ianmcook commented on code in PR #33: URL: https://github.com/apache/arrow-experiments/pull/33#discussion_r1736518828
########## http/get_multipart/python/client/simple_client.py: ########## @@ -0,0 +1,143 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import email +import json +import pyarrow as pa +import sys +import time +import urllib.request + +JSON_FORMAT = "application/json" +TEXT_FORMAT = "text/plain" +ARROW_STREAM_FORMAT = "application/vnd.apache.arrow.stream" + +start_time = time.time() +response_parsing_time = 0 # time to parse the multipart message +arrow_stream_parsing_time = 0 # time to parse the Arrow stream + + +def parse_multipart_message(response, boundary, buffer_size=8192): + """ + Parse a multipart/mixed HTTP response into a list of Message objects. + + Returns + ------- + list of email.message.Message containing the parts of the multipart message. + """ + global response_parsing_time + buffer_size = max(buffer_size, 8192) + buffer = bytearray(buffer_size) + + header = f'MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary="{boundary}"\r\n\r\n' + feedparser = email.parser.BytesFeedParser() Review Comment: The docs for the FeedParser API say to always specify `policy`: https://docs.python.org/3/library/email.parser.html Can you please `from email import policy` at the top, and set `policy=policy.default` here? Thanks -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
