{"id":"postal-merge-text","publisher":"WESWOO","engine":"Python 3","title":{"zh":"下载可复算输入与代码","en":"Download runnable inputs and code"},"routine":"postal_merge","python_source":"def postal_merge(data):\n    import csv,io,re\n    raw=next(csv.DictReader(io.StringIO(data['csv'])))\n    code=raw['Shipping Zip']\n    if data['known_text_prefix'] and code.startswith(\"'\"):\n        code=code[1:]\n    if raw['Shipping Country']=='US' and not re.fullmatch(r'[0-9]{5}(-[0-9]{4})?',code):\n        return ['check original order',None]\n    if not code.strip():\n        return ['check original order',None]\n    dest=io.StringIO()\n    writer=csv.writer(dest)\n    writer.writerow(['Shipping Zip'])\n    writer.writerow([code])\n    return ['text',next(csv.DictReader(io.StringIO(dest.getvalue())))['Shipping Zip']]\n","checks":[{"condition":"US label with source text prefix","input":{"csv":"Shipping Country,Shipping Zip\nUS,'02108","known_text_prefix":true},"expected":["text","02108"],"observed":["text","02108"]},{"condition":"Already truncated","input":{"csv":"Shipping Country,Shipping Zip\nUS,2108","known_text_prefix":true},"expected":["check original order",null],"observed":["check original order",null]},{"condition":"ZIP plus four","input":{"csv":"Shipping Country,Shipping Zip\nUS,'02108-1234","known_text_prefix":true},"expected":["text","02108-1234"],"observed":["text","02108-1234"]},{"condition":"Canadian address","input":{"csv":"Shipping Country,Shipping Zip\nCA,'K1A 0B1","known_text_prefix":true},"expected":["text","K1A 0B1"],"observed":["text","K1A 0B1"]}],"instructions":"Save python_source in a Python 3 module. Call the named routine with each check.input and compare with check.expected. Calendar case needs an IANA time-zone database."}