コード例 #1
0
def test_source_to_unicode():
    with io.open(nonascii_path, 'rb') as f:
        source_bytes = f.read()
    nt.assert_equal(openpy.source_to_unicode(source_bytes, skip_encoding_cookie=False),
                    source_bytes.decode('iso-8859-5'))

    source_no_cookie = openpy.source_to_unicode(source_bytes, skip_encoding_cookie=True)
    nt.assert_not_in(u'coding: iso-8859-5', source_no_cookie)
コード例 #2
0
def test_source_to_unicode():
    with io.open(nonascii_path, "rb") as f:
        source_bytes = f.read()
    assert (openpy.source_to_unicode(source_bytes,
                                     skip_encoding_cookie=False).splitlines()
            == source_bytes.decode("iso-8859-5").splitlines())

    source_no_cookie = openpy.source_to_unicode(source_bytes,
                                                skip_encoding_cookie=True)
    assert "coding: iso-8859-5" not in source_no_cookie
コード例 #3
0
def test_source_to_unicode():
    with io.open(nonascii_path, "rb") as f:
        source_bytes = f.read()
    nt.assert_equal(
        openpy.source_to_unicode(source_bytes,
                                 skip_encoding_cookie=False).splitlines(),
        source_bytes.decode("iso-8859-5").splitlines(),
    )

    source_no_cookie = openpy.source_to_unicode(source_bytes,
                                                skip_encoding_cookie=True)
    nt.assert_not_in("coding: iso-8859-5", source_no_cookie)
コード例 #4
0
ファイル: osm.py プロジェクト: pyarnold/ipython
    def pycat(self, parameter_s=''):
        """Show a syntax-highlighted file through a pager.

        This magic is similar to the cat utility, but it will assume the file
        to be Python source and will show it with syntax highlighting.

        This magic command can either take a local filename, an url,
        an history range (see %history) or a macro as argument ::

        %pycat myscript.py
        %pycat 7-27
        %pycat myMacro
        %pycat http://www.example.com/myscript.py
        """
        if not parameter_s:
            raise UsageError('Missing filename, URL, input history range, '
                             'or macro.')

        try:
            cont = self.shell.find_user_code(
                parameter_s, skip_encoding_cookie=False)
        except (ValueError, IOError):
            print("Error: no such file, variable, URL, history range or macro")
            return

        page.page(self.shell.pycolorize(source_to_unicode(cont)))
コード例 #5
0
ファイル: osm.py プロジェクト: LonelySamurai/SDP-Math
    def pycat(self, parameter_s=''):
        """Show a syntax-highlighted file through a pager.

        This magic is similar to the cat utility, but it will assume the file
        to be Python source and will show it with syntax highlighting.

        This magic command can either take a local filename, an url,
        an history range (see %history) or a macro as argument ::

        %pycat myscript.py
        %pycat 7-27
        %pycat myMacro
        %pycat http://www.example.com/myscript.py
        """
        if not parameter_s:
            raise UsageError('Missing filename, URL, input history range, '
                             'or macro.')

        try:
            cont = self.shell.find_user_code(parameter_s,
                                             skip_encoding_cookie=False)
        except (ValueError, IOError):
            print("Error: no such file, variable, URL, history range or macro")
            return

        page.page(self.shell.pycolorize(source_to_unicode(cont)))