Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect target file encoding in autodetect.py #71

Merged
merged 1 commit into from
Dec 5, 2014
Merged

Detect target file encoding in autodetect.py #71

merged 1 commit into from
Dec 5, 2014

Conversation

jquast
Copy link
Contributor

@jquast jquast commented Nov 20, 2014

Closes issue #65. Infer the target python source file encoding before attempting to parse it for imports of interest (such as django).

  • First, using byte order markers (BOM). An example of
    this was found in setuptools/tests/script-with-bom.py.
  • Secondly, using PEP263 regular expression over the first
    two lines -- only if they begin with a comment (#), decoded
    as utf8, to determine if it has a source file encoding,
    by seeking statements such as # coding: latin1.
  • Finally, default to utf8. If the target file fails to decode,
    or the given codec is not found -- issue a warning and move
    on to the next file.

Closes issue #65.  Infer the target python source
file encoding before attempting to parse it for
imports of interest.

- First, using byte order markers (BOM).  An example of
  this was found in ``setuptools/tests/script-with-bom.py``.
- Secondly, using PEP263 regular expression over the first
  two lines -- only if they begin with a comment (#), decoded
  as utf8, to determine if it has a source file encoding,
  by seeking statements such as ``# coding: latin1``.
- Finally, default to utf8.  If the target file fails to decode,
  or the given codec is not found -- issue a warning and move
  on to the next file.
carlio added a commit that referenced this pull request Dec 5, 2014
Detect target file encoding in autodetect.py
@carlio carlio merged commit f7012a9 into prospector-dev:develop Dec 5, 2014
@landscape-bot
Copy link

Code Health
Repository health increased by 1% when comparing resolve-unicodedecodeerror-issue-65 81d4624 on jquast/prospector to develop 8acda72 on landscapeio/prospector

9 new problems were found (including 2 errors and 0 code smells)
21 problems were fixed (including 0 errors and 3 code smells)

View the changes on Landscape.io

@jquast jquast deleted the resolve-unicodedecodeerror-issue-65 branch December 12, 2014 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants