How to use the pudb.lowlevel.detect_encoding function in pudb

To help you get started, we’ve selected a few pudb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inducer / pudb / test / test_lowlevel.py View on Github external
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'
github inducer / pudb / test / test_lowlevel.py View on Github external
def test_detect_encoding_nocookie():
    lines = [u'Test Проверка']
    lines = [l.encode('utf-8') for l in lines]
    encoding, _ = detect_encoding(iter(lines))
    assert encoding == 'utf-8'
github inducer / pudb / pudb / debugger.py View on Github external
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 == "":
                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()))),