Ejemplo n.º 1
0
 def load_source(self):
     """Load the source for the specified file."""
     if self.filename in self.STDIN_NAMES:
         self.filename = 'stdin'
         self.source = pycodestyle.stdin_get_value()
     else:
         with tokenize_open(self.filename) as fd:
             self.source = fd.read()
Ejemplo n.º 2
0
    def test_open(self):
        filename = support.TESTFN + '.py'
        self.addCleanup(support.unlink, filename)

        # test coding cookie
        for encoding in ('iso-8859-15', 'utf-8'):
            with open(filename, 'w', encoding=encoding) as fp:
                print("# coding: %s" % encoding, file=fp)
                print("print('euro:\u20ac')", file=fp)
            with tokenize_open(filename) as fp:
                self.assertEqual(fp.encoding, encoding)
                self.assertEqual(fp.mode, 'r')

        # test BOM (no coding cookie)
        with open(filename, 'w', encoding='utf-8-sig') as fp:
            print("print('euro:\u20ac')", file=fp)
        with tokenize_open(filename) as fp:
            self.assertEqual(fp.encoding, 'utf-8-sig')
            self.assertEqual(fp.mode, 'r')
Ejemplo n.º 3
0
    def test_open(self):
        filename = support.TESTFN + '.py'
        self.addCleanup(support.unlink, filename)

        # test coding cookie
        for encoding in ('iso-8859-15', 'utf-8'):
            with open(filename, 'w', encoding=encoding) as fp:
                print("# coding: %s" % encoding, file=fp)
                print("print('euro:\u20ac')", file=fp)
            with tokenize_open(filename) as fp:
                self.assertEqual(fp.encoding, encoding)
                self.assertEqual(fp.mode, 'r')

        # test BOM (no coding cookie)
        with open(filename, 'w', encoding='utf-8-sig') as fp:
            print("print('euro:\u20ac')", file=fp)
        with tokenize_open(filename) as fp:
            self.assertEqual(fp.encoding, 'utf-8-sig')
            self.assertEqual(fp.mode, 'r')
Ejemplo n.º 4
0
    def test_open(self):
        filename = support.TESTFN + ".py"
        self.addCleanup(support.unlink, filename)

        # test coding cookie
        for encoding in ("iso-8859-15", "utf-8"):
            with open(filename, "w", encoding=encoding) as fp:
                print("# coding: %s" % encoding, file=fp)
                print("print('euro:\u20ac')", file=fp)
            with tokenize_open(filename) as fp:
                self.assertEqual(fp.encoding, encoding)
                self.assertEqual(fp.mode, "r")

        # test BOM (no coding cookie)
        with open(filename, "w", encoding="utf-8-sig") as fp:
            print("print('euro:\u20ac')", file=fp)
        with tokenize_open(filename) as fp:
            self.assertEqual(fp.encoding, "utf-8-sig")
            self.assertEqual(fp.mode, "r")
 def load_source(self):
     """Load the source for the specified file."""
     if self.filename in self.STDIN_NAMES:
         self.filename = "stdin"
         if sys.version_info[0] < 3:
             self.source = sys.stdin.read()
         else:
             self.source = TextIOWrapper(sys.stdin.buffer,
                                         errors="ignore").read()
     else:
         with tokenize_open(self.filename) as fd:
             self.source = fd.read()