fix: 兼容GBK不间断空格
This commit is contained in:
@@ -1064,6 +1064,10 @@ def normalize_cell(value: object) -> str:
|
||||
return str(value).strip()
|
||||
|
||||
|
||||
def normalize_csv_cell(value: object) -> str:
|
||||
return normalize_cell(value).replace("\u00a0", " ")
|
||||
|
||||
|
||||
def sql_text_literal(value: str) -> str:
|
||||
encoded = value.encode("utf-8").hex()
|
||||
return "''" if not encoded else f"CONVERT(0x{encoded} USING utf8mb4)"
|
||||
@@ -1087,7 +1091,7 @@ def write_csv(path: Path, header: tuple[str, ...], rows: list[tuple[object, ...]
|
||||
writer = csv.writer(file)
|
||||
writer.writerow(header)
|
||||
for row in rows:
|
||||
writer.writerow(normalize_cell(value) for value in row)
|
||||
writer.writerow(normalize_csv_cell(value) for value in row)
|
||||
|
||||
|
||||
def write_dict_csv(path: Path, header: tuple[str, ...], rows: list[dict[str, str]]) -> None:
|
||||
@@ -1098,7 +1102,8 @@ def dict_csv_bytes(header: tuple[str, ...], rows: list[dict[str, str]]) -> bytes
|
||||
output = io.StringIO(newline="")
|
||||
writer = csv.DictWriter(output, fieldnames=header, extrasaction="raise")
|
||||
writer.writeheader()
|
||||
writer.writerows(rows)
|
||||
for row in rows:
|
||||
writer.writerow({column: normalize_csv_cell(row[column]) for column in header})
|
||||
return output.getvalue().encode(CSV_ENCODING)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user