Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions python_multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,14 +1157,6 @@ def advance_header_size(amount: int = 1) -> None:
if current_header_size > self.max_header_size:
raise MultipartParseError("Maximum header size exceeded", offset=i)

# Set a mark.
def set_mark(name: str) -> None:
self.marks[name] = i

# Remove a mark.
def delete_mark(name: str, reset: bool = False) -> None:
self.marks.pop(name, None)

# Helper function that makes calling a callback with data easier. The
# 'remaining' parameter will callback from the marked value until the
# end of the buffer, and reset the mark, instead of deleting it. This
Expand Down Expand Up @@ -1290,7 +1282,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No
current_header_size = 0

# Set a mark of our header field.
set_mark("header_field")
self.marks["header_field"] = i

# Notify that we're starting a header if the next character is
# not a CR; a CR at the beginning of the header will cause us
Expand All @@ -1308,7 +1300,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No
# that we've reached the second of 2 newlines, and so there are
# no more headers to parse.
if c == CR and index == 0:
delete_mark("header_field")
self.marks.pop("header_field", None)
state = HEADERS_ALMOST_DONE
i += 1
continue
Expand Down Expand Up @@ -1356,7 +1348,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No
continue

# Mark the start of the header value.
set_mark("header_value")
self.marks["header_value"] = i

# Move to the header-value state, reprocessing this character.
state = HEADER_VALUE
Expand Down Expand Up @@ -1403,7 +1395,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No

elif state == PART_DATA_START:
# Mark the start of our part data.
set_mark("part_data")
self.marks["part_data"] = i

# Start processing part data, including this character.
state = PART_DATA
Expand Down Expand Up @@ -1471,7 +1463,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No
# RFC 2046 forbids lines starting with the boundary in a part, so this can't be data.
elif c in b" \t":
data_callback("part_data", i - boundary_length)
delete_mark("part_data")
self.marks.pop("part_data", None)
index = 0
state = BOUNDARY_PADDING

Expand Down
Loading