Open the context
Choose the project folder and name the files or behavior involved.
Resolve one to 16 Content-Length field strings of at most 128 characters into a single agreed value from zero to 2147483647. Test comma lists, leading zeros and spaces or tabs, rejecting empty tokens, signs, line breaks and disagreements without claiming complete HTTP framing validation.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import re
def agreed_content_length(fields):
if type(fields) is not list or not 1 <= len(fields) <= 16:
raise ValueError("length.fields")
result = None
for field in fields:
if type(field) is not str or len(field) > 128:
raise ValueError("length.field")
for item in field.split(","):
token = item.strip(" \t")
if re.fullmatch(r"[0-9]+", token) is None:
raise ValueError("length.digits")
value = int(token)
if value > 2147483647 or (result is not None and value != result):
raise ValueError("length.agreement")
result = value
return result
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.