Example #1
0
def test_detect_encoding_cookie():
    lines = [
        '# coding=utf-8',
        'Test',
        'Проверка'
    ]
    encoding, _ = detect_encoding(lines)
    assert encoding == 'utf-8'
Example #2
0
def test_detect_encoding_cookie():
    lines = [
        u'# coding=utf-8',
        u'Test',
        u'Проверка'
    ]
    lines = [l.encode('utf-8') for l in lines]
    encoding, _ = detect_encoding(iter(lines))
    assert encoding == 'utf-8'
Example #3
0
    def set_current_file(self, fname):
        from pudb.source_view import SourceLine, format_source
        fname = self.debugger.canonic(fname)

        if self.shown_file != fname:
            if fname == "<string>":
                self.source[:] = [SourceLine(self, fname)]
            else:
                breakpoints = self.debugger.get_file_breaks(fname)
                try:
                    from linecache import getlines
                    lines = getlines(fname)

                    from pudb.lowlevel import detect_encoding
                    source_enc, _ = detect_encoding(iter(lines).next)

                    decoded_lines = []
                    for l in lines:
                        if hasattr(l, "decode"):
                            decoded_lines.append(l.decode(source_enc))
                        else:
                            decoded_lines.append(l)

                    self.source[:] = format_source(self,
                            decoded_lines, set(breakpoints))
                except:
                    from traceback import format_exception
                    import sys

                    self.message("Could not load source file '%s':\n\n%s" % (
                        fname, "".join(format_exception(*sys.exc_info()))),
                        title="Source Code Load Error")
                    self.source[:] = [SourceLine(self,
                        "Error while loading '%s'." % fname)]

            self.shown_file = fname
            self.current_line = None
Example #4
0
def test_detect_encoding_nocookie():
    lines = [u"Test Проверка"]
    lines = [line.encode("utf-8") for line in lines]
    encoding, _ = detect_encoding(iter(lines))
    assert encoding == "utf-8"
Example #5
0
def test_detect_encoding_nocookie():
    lines = ['Test Проверка']
    encoding, _ = detect_encoding(lines)
    assert encoding == 'utf-8'
Example #6
0
def test_detect_encoding_nocookie():
    lines = [u'Test Проверка']
    lines = [line.encode('utf-8') for line in lines]
    encoding, _ = detect_encoding(iter(lines))
    assert encoding == 'utf-8'
Example #7
0
def test_detect_encoding_nocookie():
    lines = ['Test Проверка']
    encoding, _ = detect_encoding(lines)
    assert encoding == 'utf-8'
Example #8
0
def test_detect_encoding_cookie():
    lines = ['# coding=utf-8', 'Test', 'Проверка']
    encoding, _ = detect_encoding(lines)
    assert encoding == 'utf-8'