class UnicodeChecker(checkers.BaseRawFileChecker): (source)
Check characters that could be used to hide bad code to humans. This includes: - Bidirectional Unicode (see https://trojansource.codes/) - Bad ASCII characters (see PEP672) If a programmer requires to use such a character they should use the escaped version, that is also much easier to read and does not depend on the editor used. The Checker also includes a check that UTF-16 and UTF-32 are not used to encode Python files. At the time of writing Python supported only UTF-8. See https://stackoverflow.com/questions/69897842/ and https://bugs.python.org/issue1503789 for background.
Method | process |
Perform the actual check by checking module stream. |
Class Variable | msgs |
Undocumented |
Class Variable | name |
Name of the provider. |
Class Method | _find |
Find all matches of BAD_CHARS within line. |
Static Method | _determine |
Determine the codec from the given stream. |
Static Method | _is |
Undocumented |
Static Method | _is |
Undocumented |
Method | _check |
Look for Bidirectional Unicode, if we use unicode. |
Method | _check |
Check validity of the codec. |
Method | _check |
Look for chars considered bad. |
Inherited from BaseChecker
(via BaseRawFileChecker
):
Method | __eq__ |
Permit to assert Checkers are equal. |
Method | __gt__ |
Sorting of checkers. |
Method | __hash__ |
Make Checker hashable. |
Method | __init__ |
Checker instances should have the linter as argument. |
Method | __repr__ |
Undocumented |
Method | __str__ |
This might be incomplete because multiple classes inheriting BaseChecker can have the same name. |
Method | add |
Undocumented |
Method | check |
Check the consistency of msgid. |
Method | close |
Called after visiting project (i.e set of modules). |
Method | create |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | open |
Called before visiting project (i.e. set of modules). |
Method | reduce |
Undocumented |
Class Variable | enabled |
Undocumented |
Class Variable | options |
Options provided by this provider. |
Class Variable | reports |
Undocumented |
Instance Variable | linter |
Undocumented |
Property | messages |
Undocumented |
Inherited from _ArgumentsProvider
(via BaseRawFileChecker
, BaseChecker
):
Method | get |
DEPRECATED: Return the dictionary defining an option given its name. |
Method | level |
Undocumented |
Method | load |
DEPRECATED: Initialize the provider using default values. |
Method | option |
DEPRECATED: Get the config attribute corresponding to opt. |
Method | option |
DEPRECATED: Get the current value for the given option. |
Method | options |
DEPRECATED. |
Method | options |
DEPRECATED: Return an iterator on options grouped by section. |
Method | set |
DEPRECATED: Method called to set an option (registered in the options list). |
Class Variable | option |
Option groups of this provider and their descriptions. |
Property | config |
Undocumented |
Property | level |
Undocumented |
Instance Variable | _arguments |
The manager that will parse and register any options provided. |
Instance Variable | _level |
Undocumented |
def _find_line_matches(cls, line:
bytes
, codec: str
) -> dict[ int, _BadChar]
:
(source)
¶
Find all matches of BAD_CHARS within line. Args: line: the input codec: that will be used to convert line/or search string into Return: A dictionary with the column offset and the BadASCIIChar
Determine the codec from the given stream. first tries https://www.python.org/dev/peps/pep-0263/ and if this fails also checks for BOMs of UTF-16 and UTF-32 to be future-proof. Args: stream: The byte stream to analyse Returns: A tuple consisting of: - normalized codec name - the line in which the codec was found Raises: SyntaxError: if failing to detect codec