[MRG] scrapely.tool: add support for non-ascii <text> and <data> arguments#46
Merged
pablohoffman merged 2 commits intoscrapy:masterfrom Oct 10, 2013
Merged
[MRG] scrapely.tool: add support for non-ascii <text> and <data> arguments#46pablohoffman merged 2 commits intoscrapy:masterfrom
pablohoffman merged 2 commits intoscrapy:masterfrom
Conversation
<text> and <data> arguments are parsed by parse_criteria function (it uses shlex and optparse for parsing). Data that is passed to parse_criteria function is extracted from "line" argument of do_<…> methods. This "line" argument is read from self.stdin by cmd.Cmd and passed to do_ methods. In Python 2.x sys.stdin (which is default for cmd.Cmd.stdin) is binary, so "line" is a bytestring; its encoding is self.stdin.encoding. That's why <text> and <data> argument values was previously bytestrings; when passed to other scrapely functions they eventually got implicitly decoded using sys.getdefaultencoding() - this usually leads to UnicodeDecodeError if input text is non-ascii. The fix is to decode these arguments using self.stdin.encoding before passing them to scrapely. This is done after shlex call because shlex doesn't support unicode. Non-ascii "field" arguments are still unsupported.
pablohoffman
added a commit
that referenced
this pull request
Oct 10, 2013
[MRG] scrapely.tool: add support for non-ascii <text> and <data> arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I think that there are two separate issues in #45:
This PR addresses (1).