コード例 #1
0
    def append_stream(self,
                      streamid: str,
                      stream: STREAM_TYPES,
                      encoding: str | None = None) -> None:
        """Append a file to search for similarities."""
        if isinstance(stream, BufferedIOBase):
            if encoding is None:
                raise ValueError
            readlines = decoding_stream(stream, encoding).readlines
        else:
            readlines = stream.readlines  # type: ignore[assignment] # hint parameter is incorrectly typed as non-optional

        try:
            lines = readlines()
        except UnicodeDecodeError:
            lines = []

        self.linesets.append(
            LineSet(
                streamid,
                lines,
                self.namespace.ignore_comments,
                self.namespace.ignore_docstrings,
                self.namespace.ignore_imports,
                self.namespace.ignore_signatures,
                line_enabled_callback=self.linter.
                _is_one_message_enabled  # type: ignore[attr-defined]
                if hasattr(self, "linter") else None,
            ))
コード例 #2
0
ファイル: similar.py プロジェクト: AWhetter/pylint
    def append_stream(self,
                      streamid: str,
                      stream: STREAM_TYPES,
                      encoding: Optional[str] = None) -> None:
        """Append a file to search for similarities."""
        if isinstance(stream, BufferedIOBase):
            if encoding is None:
                raise ValueError
            readlines = decoding_stream(stream, encoding).readlines
        else:
            readlines = stream.readlines  # type: ignore[assignment] # hint parameter is incorrectly typed as non-optional
        try:
            active_lines: List[str] = []
            if hasattr(self, "linter"):
                # Remove those lines that should be ignored because of disables
                for index, line in enumerate(readlines()):
                    if self.linter._is_one_message_enabled(
                            "R0801", index + 1):  # type: ignore[attr-defined]
                        active_lines.append(line)
            else:
                active_lines = readlines()

            self.linesets.append(
                LineSet(
                    streamid,
                    active_lines,
                    self.ignore_comments,
                    self.ignore_docstrings,
                    self.ignore_imports,
                    self.ignore_signatures,
                ))
        except UnicodeDecodeError:
            pass
コード例 #3
0
def test_decoding_stream_unknown_encoding():
    """decoding_stream should fall back to *some* decoding when given an
    unknown encoding.
    """
    binary_io = io.BytesIO(b"foo\nbar")
    stream = utils.decoding_stream(binary_io, "garbage-encoding")
    # should still act like a StreamReader
    ret = stream.readlines()
    assert ret == ["foo\n", "bar"]
コード例 #4
0
ファイル: unittest_utils.py プロジェクト: KabageMark/newsapp
def test_decoding_stream_unknown_encoding():
    """decoding_stream should fall back to *some* decoding when given an
    unknown encoding.
    """
    binary_io = io.BytesIO(b'foo\nbar')
    stream = utils.decoding_stream(binary_io, 'garbage-encoding')
    # should still act like a StreamReader
    ret = stream.readlines()
    assert ret == ['foo\n', 'bar']
コード例 #5
0
 def append_stream(self, streamid, stream, encoding=None):
     """append a file to search for similarities"""
     if encoding is None:
         readlines = stream.readlines
     else:
         readlines = decoding_stream(stream, encoding).readlines
     try:
         self.linesets.append(
             LineSet(streamid, readlines(), self.ignore_comments,
                     self.ignore_docstrings, self.ignore_imports))
     except UnicodeDecodeError:
         pass
コード例 #6
0
ファイル: similar.py プロジェクト: Marslo/VimConfig
 def append_stream(self, streamid, stream, encoding=None):
     """append a file to search for similarities"""
     if encoding is None:
         readlines = stream.readlines
     else:
         readlines = decoding_stream(stream, encoding).readlines
     try:
         self.linesets.append(LineSet(streamid,
                                      readlines(),
                                      self.ignore_comments,
                                      self.ignore_docstrings,
                                      self.ignore_imports))
     except UnicodeDecodeError:
         pass
コード例 #7
0
ファイル: similar.py プロジェクト: craig-sh/pylint
 def append_stream(self,
                   streamid: str,
                   stream: STREAM_TYPES,
                   encoding: Optional[str] = None) -> None:
     """append a file to search for similarities"""
     if isinstance(stream, BufferedIOBase):
         if encoding is None:
             raise ValueError
         readlines = decoding_stream(stream, encoding).readlines
     else:
         readlines = stream.readlines  # type: ignore # hint parameter is incorrectly typed as non-optional
     try:
         self.linesets.append(
             LineSet(
                 streamid,
                 readlines(),
                 self.ignore_comments,
                 self.ignore_docstrings,
                 self.ignore_imports,
                 self.ignore_signatures,
             ))
     except UnicodeDecodeError:
         pass
コード例 #8
0
def test_decoding_stream_known_encoding():
    binary_io = io.BytesIO("€".encode("cp1252"))
    stream = utils.decoding_stream(binary_io, "cp1252")
    assert stream.read() == "€"
コード例 #9
0
def test_decoding_stream_known_encoding():
    binary_io = io.BytesIO('€'.encode('cp1252'))
    stream = utils.decoding_stream(binary_io, 'cp1252')
    assert stream.read() == '€'
コード例 #10
0
ファイル: unittest_utils.py プロジェクト: KabageMark/newsapp
def test_decoding_stream_known_encoding():
    binary_io = io.BytesIO(u'€'.encode('cp1252'))
    stream = utils.decoding_stream(binary_io, 'cp1252')
    assert stream.read() == u'€'