Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
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'
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()))),