Python docutils.nodes 模块,reprunicode() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用docutils.nodes.reprunicode()

项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, unicode):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, unicode):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, unicode):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, str):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
项目:RST-vscode    作者:tht13    | 项目源码 | 文件源码
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, unicode):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
项目:tf_aws_ecs_instance_draining_on_scale_in    作者:terraform-community-modules    | 项目源码 | 文件源码
def decode_path(path):
    """
    Ensure `path` is Unicode. Return `nodes.reprunicode` object.

    Decode file/path string in a failsave manner if not already done.
    """
    # see also http://article.gmane.org/gmane.text.docutils.user/2905
    if isinstance(path, unicode):
        return path
    try:
        path = path.decode(sys.getfilesystemencoding(), 'strict')
    except AttributeError: # default value None has no decode method
        return nodes.reprunicode(path)
    except UnicodeDecodeError:
        try:
            path = path.decode('utf-8', 'strict')
        except UnicodeDecodeError:
            path = path.decode('ascii', 'replace')
    return nodes.reprunicode(path)
项目:docs    作者:hasura    | 项目源码 | 文件源码
def open_file(self, path):
        """Open a file and register it as a dependency."""
        path = os.path.normpath(path)
        path = utils.relative_path(None, path)
        path = nodes.reprunicode(path)
        self.state.document.settings.record_dependencies.add(path)
        return open(path, 'r')
项目:m2r    作者:miyakogi    | 项目源码 | 文件源码
def run(self):
        """Most of this method is from ``docutils.parser.rst.Directive``.

        docutils version: 0.12
        """
        if not self.state.document.settings.file_insertion_enabled:
            raise self.warning('"%s" directive disabled.' % self.name)
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)
        source_dir = os.path.dirname(os.path.abspath(source))
        path = rst.directives.path(self.arguments[0])
        path = os.path.normpath(os.path.join(source_dir, path))
        path = utils.relative_path(None, path)
        path = nodes.reprunicode(path)

        # get options (currently not use directive-specific options)
        encoding = self.options.get(
            'encoding', self.state.document.settings.input_encoding)
        e_handler = self.state.document.settings.input_encoding_error_handler
        tab_width = self.options.get(
            'tab-width', self.state.document.settings.tab_width)

        # open the inclding file
        try:
            self.state.document.settings.record_dependencies.add(path)
            include_file = io.FileInput(source_path=path,
                                        encoding=encoding,
                                        error_handler=e_handler)
        except UnicodeEncodeError as error:
            raise self.severe('Problems with "%s" directive path:\n'
                              'Cannot encode input file path "%s" '
                              '(wrong locale?).' %
                              (self.name, SafeString(path)))
        except IOError as error:
            raise self.severe('Problems with "%s" directive path:\n%s.' %
                              (self.name, ErrorString(error)))

        # read from the file
        try:
            rawtext = include_file.read()
        except UnicodeError as error:
            raise self.severe('Problem with "%s" directive:\n%s' %
                              (self.name, ErrorString(error)))

        config = self.state.document.settings.env.config
        converter = M2R(no_underscore_emphasis=config.no_underscore_emphasis)
        include_lines = statemachine.string2lines(converter(rawtext),
                                                  tab_width,
                                                  convert_whitespace=True)
        self.state_machine.insert_input(include_lines, path)
        return []
项目:tensorforce    作者:reinforceio    | 项目源码 | 文件源码
def run(self):
        """Most of this method is from ``docutils.parser.rst.Directive``.

        docutils version: 0.12
        """
        if not self.state.document.settings.file_insertion_enabled:
            raise self.warning('"%s" directive disabled.' % self.name)
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)
        source_dir = os.path.dirname(os.path.abspath(source))
        path = rst.directives.path(self.arguments[0])
        path = os.path.normpath(os.path.join(source_dir, path))
        path = utils.relative_path(None, path)
        path = nodes.reprunicode(path)

        # get options (currently not use directive-specific options)
        encoding = self.options.get(
            'encoding', self.state.document.settings.input_encoding)
        e_handler = self.state.document.settings.input_encoding_error_handler
        tab_width = self.options.get(
            'tab-width', self.state.document.settings.tab_width)

        # open the inclding file
        try:
            self.state.document.settings.record_dependencies.add(path)
            include_file = io.FileInput(source_path=path,
                                        encoding=encoding,
                                        error_handler=e_handler)
        except UnicodeEncodeError as error:
            raise self.severe('Problems with "%s" directive path:\n'
                              'Cannot encode input file path "%s" '
                              '(wrong locale?).' %
                              (self.name, SafeString(path)))
        except IOError as error:
            raise self.severe('Problems with "%s" directive path:\n%s.' %
                              (self.name, ErrorString(error)))

        # read from the file
        try:
            rawtext = include_file.read()
        except UnicodeError as error:
            raise self.severe('Problem with "%s" directive:\n%s' %
                              (self.name, ErrorString(error)))

        config = self.state.document.settings.env.config
        converter = M2R(no_underscore_emphasis=config.no_underscore_emphasis)
        include_lines = statemachine.string2lines(converter(rawtext),
                                                  tab_width,
                                                  convert_whitespace=True)
        self.state_machine.insert_input(include_lines, path)
        return []