Python docutils.statemachine 模块,StringList() 实例源码

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

项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols
项目:RST-vscode    作者:tht13    | 项目源码 | 文件源码
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols
项目:tf_aws_ecs_instance_draining_on_scale_in    作者:terraform-community-modules    | 项目源码 | 文件源码
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols
项目:sphinx-js    作者:erikrose    | 项目源码 | 文件源码
def __init__(self, directive, app, arguments=None, content=None, options=None):
        self._directive = directive

        # content, arguments, options, app: all need to be accessible to
        # template_vars, so we bring them in on construction and stow them away
        # on the instance so calls to template_vars don't need to concern
        # themselves with what it needs.
        self._app = app
        self._partial_path, self._explicit_formal_params = PathVisitor().parse(arguments[0])
        self._content = content or StringList()
        self._options = options or {}
项目:borg-import    作者:borgbackup    | 项目源码 | 文件源码
def run(self):
        command = self.arguments[0]
        parser = self._get_command_parser(build_parser(), command)

        full_command = 'borg-import ' + command
        headline = '::\n\n    ' + full_command

        if any(len(o.option_strings) for o in parser._actions):
            headline += ' <options>'

        # Add the metavars of the parameters to the synopsis line
        for option in parser._actions:
            if not option.option_strings:
                headline += ' ' + option.metavar

        headline += '\n\n'

        # Final result will look like:
        # borg-import something <options> FOO_BAR REPOSITORY
        contents = headline.splitlines()

        for group in parser._action_groups:
            self.write_options_group(group, contents)

        if parser.epilog:
            contents.append('Description')
            contents.append('~~~~~~~~~~~')
            contents.append('')

        node = nodes.paragraph()
        nested_parse_with_titles(self.state, StringList(contents), node)
        gen_nodes = [node]

        if parser.epilog:
            paragraphs = parser.epilog.split('\n\n')
            for paragraph in paragraphs:
                node = nodes.paragraph()
                nested_parse_with_titles(self.state, StringList(paragraph.split('\n')), node)
                gen_nodes.append(node)

        return gen_nodes
项目:mlens    作者:flennerhag    | 项目源码 | 文件源码
def run(self):
        try:
            if 'tooltip' in self.options:
                tooltip = self.options['tooltip'][:195] + '...'
            else:
                raise ValueError('tooltip not found')

            if 'figure' in self.options:
                env = self.state.document.settings.env
                rel_figname, figname = env.relfn2path(self.options['figure'])
                thumbnail = os.path.join('_static/thumbs/', os.path.basename(figname))

                try:
                    os.makedirs('_static/thumbs')
                except FileExistsError:
                    pass

                sphinx_gallery.gen_rst.scale_image(figname, thumbnail, 400, 280)
            else:
                thumbnail = '_static/img/thumbnails/default.png'

            if 'description' in self.options:
                description = self.options['description']
            else:
                raise ValueError('description not doc found')

        except FileNotFoundError as e:
            print(e)
            return []
        except ValueError as e:
            print(e)
            raise
            return []

        thumbnail_rst = GALLERY_TEMPLATE.format(tooltip=tooltip,
                                                thumbnail=thumbnail,
                                                description=description)
        thumbnail = StringList(thumbnail_rst.split('\n'))
        thumb = nodes.paragraph()
        self.state.nested_parse(thumbnail, self.content_offset, thumb)
        return [thumb]
项目:package-manager    作者:bro    | 项目源码 | 文件源码
def _nested_parse_paragraph(self, text):
        content = nodes.paragraph()
        self.state.nested_parse(StringList(text.split("\n")), 0, content)
        return content
项目:tutorials    作者:pytorch    | 项目源码 | 文件源码
def run(self):
        try:
            if 'tooltip' in self.options:
                tooltip = self.options['tooltip'][:195] + '...'
            else:
                raise ValueError('tooltip not found')

            if 'figure' in self.options:
                env = self.state.document.settings.env
                rel_figname, figname = env.relfn2path(self.options['figure'])
                thumbnail = os.path.join('_static/thumbs/', os.path.basename(figname))

                try:
                    os.makedirs('_static/thumbs')
                except FileExistsError:
                    pass

                sphinx_gallery.gen_rst.scale_image(figname, thumbnail, 400, 280)
            else:
                thumbnail = '_static/img/thumbnails/default.png'

            if 'description' in self.options:
                description = self.options['description']
            else:
                raise ValueError('description not doc found')

        except FileNotFoundError as e:
            print(e)
            return []
        except ValueError as e:
            print(e)
            raise
            return []

        thumbnail_rst = GALLERY_TEMPLATE.format(tooltip=tooltip,
                                                thumbnail=thumbnail,
                                                description=description)
        thumbnail = StringList(thumbnail_rst.split('\n'))
        thumb = nodes.paragraph()
        self.state.nested_parse(thumbnail, self.content_offset, thumb)
        return [thumb]
项目:sunvox-guide    作者:metrasynth    | 项目源码 | 文件源码
def run(self):
        env = self.state.document.settings.env
        style = self.options.get('style', 'detailed')
        depth = self.options.get('depth')
        src_path = self.state.document['source']
        varname, = self.arguments
        if '.' in varname:
            projname, modname = varname.split('.')
        else:
            projname, modname = varname, None
        p = env.file_projects[src_path]
        project = p[projname]
        pm = env.file_projects_modules[src_path]
        mod = pm[projname][modname] if modname else None
        if depth is None:
            modules = project.modules
            connections = project.module_connections
        elif int(depth) == 0:
            modules = [mod]
            connections = defaultdict(list)
        else:
            modules = []
            connections = []
        uml_src = [UML_FORMATTING]
        if style == 'basic':
            uml_src += ['hide attributes']
        for module in modules:
            if module is None:
                continue
            modname = 'mod{:02X}'.format(module.index)
            modtitle = '[{:02X}] {}'.format(module.index, module.name)
            modtype = module.mtype
            modgroup = module.mgroup
            uml_src += [
                '{}({}, "{}", "{}") {{'.format(modgroup, modname,
                                               modtype, modtitle),
                '\n'.join('{} : {}'.format(cname, cval(getattr(module, cname)))
                          for cname in module.controllers),
                '}',
            ]
        for dest, sources in connections.items():
            for src in sources:
                if src == -1:
                    continue
                uml_src.append('mod{:02X} --> mod{:02X}'.format(src, dest))
        uml_src = '\n'.join(uml_src)
        uml_src = '..  uml::\n\n' + indent(uml_src, '    ')
        uml = StringList(
            initlist=uml_src.split('\n'),
            parent=self,
            parent_offset=self.content_offset,
        )
        node = nodes.Element()
        node.document = self.state.document
        self.state.nested_parse(uml, 0, node)
        return list(node)
项目:mlens    作者:flennerhag    | 项目源码 | 文件源码
def run(self):
        args = self.arguments
        fname = args[-1]

        env = self.state.document.settings.env
        fname, abs_fname = env.relfn2path(fname)
        basename = os.path.basename(fname)
        dirname = os.path.dirname(fname)

        try:
            if 'intro' in self.options:
                intro = self.options['intro'][:195] + '...'
            else:
                intro = sphinx_gallery.gen_rst.extract_intro(abs_fname)

            thumbnail_rst = sphinx_gallery.backreferences._thumbnail_div(
                dirname, basename, intro)

            if 'figure' in self.options:
                rel_figname, figname = env.relfn2path(self.options['figure'])
                save_figname = os.path.join('_static/thumbs/',
                                            os.path.basename(figname))

                try:
                    os.makedirs('_static/thumbs')
                except OSError:
                    pass

                sphinx_gallery.gen_rst.scale_image(figname, save_figname,
                                                   400, 280)
                # replace figure in rst with simple regex
                thumbnail_rst = re.sub(r'..\sfigure::\s.*\.png',
                                       '.. figure:: /{}'.format(save_figname),
                                       thumbnail_rst)

            thumbnail = StringList(thumbnail_rst.split('\n'))
            thumb = nodes.paragraph()
            self.state.nested_parse(thumbnail, self.content_offset, thumb)

            return [thumb]
        except FileNotFoundError as e:
            print(e)
            return []
项目:tutorials    作者:pytorch    | 项目源码 | 文件源码
def run(self):
        args = self.arguments
        fname = args[-1]

        env = self.state.document.settings.env
        fname, abs_fname = env.relfn2path(fname)
        basename = os.path.basename(fname)
        dirname = os.path.dirname(fname)

        try:
            if 'intro' in self.options:
                intro = self.options['intro'][:195] + '...'
            else:
                _, blocks = sphinx_gallery.gen_rst.split_code_and_text_blocks(abs_fname)
                intro, _ = sphinx_gallery.gen_rst.extract_intro_and_title(abs_fname, blocks[0][1])

            thumbnail_rst = sphinx_gallery.backreferences._thumbnail_div(
                dirname, basename, intro)

            if 'figure' in self.options:
                rel_figname, figname = env.relfn2path(self.options['figure'])
                save_figname = os.path.join('_static/thumbs/',
                                            os.path.basename(figname))

                try:
                    os.makedirs('_static/thumbs')
                except OSError:
                    pass

                sphinx_gallery.gen_rst.scale_image(figname, save_figname,
                                                   400, 280)
                # replace figure in rst with simple regex
                thumbnail_rst = re.sub(r'..\sfigure::\s.*\.png',
                                       '.. figure:: /{}'.format(save_figname),
                                       thumbnail_rst)

            thumbnail = StringList(thumbnail_rst.split('\n'))
            thumb = nodes.paragraph()
            self.state.nested_parse(thumbnail, self.content_offset, thumb)

            return [thumb]
        except FileNotFoundError as e:
            print(e)
            return []