Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-109638: Fix for significant backtracking in csv.Sniffer#109639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sg3-141-592 wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
fromsg3-141-592:main
Open
Changes from3 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
3 changes: 2 additions & 1 deletionLib/csv.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -270,8 +270,9 @@ def _guess_quote_and_delimiter(self, data, delimiters):

# if we see an extra quote between delimiters, we've got a
# double quoted format
# in future Python versions this zero width look-ahead assert can be replaced with atomic groups
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please may you explain this comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sure, this zero-width lookahead assertion change in the Regex can be done with an atomic group which is cleaner and more concise.

# Current change(,|^)\W*"(?=(?P<zero>[^,|"\n]*))(?P=zero)"[^,|\n]*"\W*(,|$)# Atomic Group(,|^)\W*"(?>[^,|"\n]*)"[^,|\n]*"\W*(,|$)

But atomic groups are only supported in Python 3.11 onwards so I avoided using them here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks Sean. This PR (if merged) would be part of Python 3.13, so let's use the better atomic group method.

A

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sure, I've switched us to the simpler atomic group setup. Performance is identical to the previous fix.

dq_regexp = re.compile(
r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \
r"((%(delim)s)|^)\W*%(quote)s(?=(?P<zero>[^%(delim)s%(quote)s\n]*))(?P=zero)%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \
{'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE)


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp