当前位置: 首页>>代码示例>>Python>>正文


Python formatting.dedent函数代码示例

本文整理汇总了Python中rest_framework.utils.formatting.dedent函数的典型用法代码示例。如果您正苦于以下问题:Python dedent函数的具体用法?Python dedent怎么用?Python dedent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dedent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_docstring_is_not_stripped_by_get_description

def test_docstring_is_not_stripped_by_get_description():
    class ExampleDocstringAPIView(APIView):
        """
        === title

         * item a
           * item a-a
           * item a-b
         * item b

         - item 1
         - item 2

            code block begin
            code
            code
            code
            code block end

        the end
        """

        def get(self, *args, **kwargs):
            pass

        def post(self, request, *args, **kwargs):
            pass

    view = ExampleDocstringAPIView()
    schema = view.schema
    descr = schema.get_description('example', 'get')
    # the first and last character are '\n' correctly removed by get_description
    assert descr == formatting.dedent(ExampleDocstringAPIView.__doc__[1:][:-1])
开发者ID:kakulukia,项目名称:django-rest-framework,代码行数:33,代码来源:test_schemas.py

示例2: get_notes

    def get_notes(self):
        """
        Returns the body of the docstring trimmed before any parameters are
        listed. First, get the class docstring and then get the method's. The
        methods will always inherit the class comments.
        """
        docstring = ""

        class_docs = self.callback.__doc__ or ''
        class_docs = smart_text(class_docs)
        class_docs = IntrospectorHelper.strip_yaml_from_docstring(class_docs)
        class_docs = IntrospectorHelper.strip_params_from_docstring(class_docs)
        method_docs = self.get_docs()

        if class_docs is not None:
            docstring += class_docs + "  \n"
        if method_docs is not None:
            method_docs = formatting.dedent(smart_text(method_docs))
            method_docs = IntrospectorHelper.strip_yaml_from_docstring(
                method_docs
            )
            method_docs = IntrospectorHelper.strip_params_from_docstring(
                method_docs
            )
            docstring += '\n' + method_docs

        # Markdown is optional
        if apply_markdown:
            docstring = apply_markdown(docstring)
        else:
            docstring = docstring.replace("\n\n", "<br/>")

        return docstring
开发者ID:basicsbeauty,项目名称:django-rest-swagger,代码行数:33,代码来源:introspectors.py

示例3: get_description

    def get_description(self, path, method, view):
        """
        Determine a link description.

        This will be based on the method docstring if one exists,
        or else the class docstring.
        """
        method_name = getattr(view, 'action', method.lower())
        method_docstring = getattr(view, method_name, None).__doc__
        if method_docstring:
            # An explicit docstring on the method or action.
            return formatting.dedent(smart_text(method_docstring))

        description = view.get_view_description()
        lines = [line.strip() for line in description.splitlines()]
        current_section = ''
        sections = {'': ''}

        for line in lines:
            if header_regex.match(line):
                current_section, seperator, lead = line.partition(':')
                sections[current_section] = lead.strip()
            else:
                sections[current_section] += line + '\n'

        header = getattr(view, 'action', method.lower())
        if header in sections:
            return sections[header].strip()
        if header in self.coerce_method_names:
            if self.coerce_method_names[header] in sections:
                return sections[self.coerce_method_names[header]].strip()
        return sections[''].strip()
开发者ID:theromis,项目名称:django-rest-framework,代码行数:32,代码来源:schemas.py

示例4: get_view_description

def get_view_description(view_cls, html=False):
    """
    Given a view class, return a textual description to represent the view.
    This name is used in the browsable API, and in OPTIONS responses.

    This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
    """
    description = view_cls.__doc__ or ''
    description = formatting.dedent(smart_text(description))

    if hasattr(getattr(view_cls, 'serializer_class', 'None'), 'Meta'):
        doc_url = get_doc_url(
            'api',
            '{0}s'.format(
                view_cls.serializer_class.Meta.model.__name__.lower()
            )
        )
    else:
        doc_url = get_doc_url('api')

    if html:
        return (
            formatting.markup_description(description) +
            mark_safe(DOC_TEXT.format(doc_url))
        )
    return description
开发者ID:nijel,项目名称:weblate,代码行数:26,代码来源:views.py

示例5: get_view_doc

def get_view_doc(view, html=True):
    """
    Build view documentation. Return in html format.
    If you want in markdown format, use html=False
    """
    try:
        description = view.__doc__ or ''
        description = formatting.dedent(smart_text(description))

        # include filters in description
        filter_fields = get_filter_fields(view)
        if filter_fields:
            filter_doc = ['\n\n\n## Filters', '']
            for f in filter_fields:
                filter_doc.append('- `%s`' % f)
            description += '\n'.join(filter_doc)

        # replace {api_url} by current base url
        api_url = "/api"
        description = description.replace('{api_url}', api_url)
        if html:
            description = formatting.markup_description(description)
        return description
    except:
        import traceback
        traceback.print_exc()
        raise
开发者ID:gustavosoares,项目名称:django_services,代码行数:27,代码来源:utils.py

示例6: get_notes

    def get_notes(self):
        """
        Returns the body of the docstring trimmed before any parameters are
        listed. First, get the class docstring and then get the method's. The
        methods will always inherit the class comments.
        """
        docstring = ""

        class_docs = get_view_description(self.callback)
        class_docs = IntrospectorHelper.strip_yaml_from_docstring(class_docs)
        class_docs = IntrospectorHelper.strip_params_from_docstring(class_docs)
        method_docs = self.get_docs()

        if class_docs is not None:
            docstring += class_docs + "  \n"
        if method_docs is not None:
            method_docs = formatting.dedent(smart_text(method_docs))
            method_docs = IntrospectorHelper.strip_yaml_from_docstring(
                method_docs
            )
            method_docs = IntrospectorHelper.strip_params_from_docstring(
                method_docs
            )
            docstring += '\n' + method_docs
        docstring = docstring.strip()

        return do_markdown(docstring)
开发者ID:Nnonexistent,项目名称:django-rest-swagger,代码行数:27,代码来源:introspectors.py

示例7: get_restructuredtext

def get_restructuredtext(view_cls, html=False):
    from docutils import core
    description = view_cls.__doc__ or ''
    description = formatting.dedent(smart_text(description))
    if html:
        parts = core.publish_parts(source=description, writer_name='html')
        html = parts['body_pre_docinfo'] + parts['fragment']
        return mark_safe(html)
    return description
开发者ID:TeamLovely,项目名称:django-rest-swagger,代码行数:9,代码来源:views.py

示例8: get_view_description

 def get_view_description(self, html=False):
     description = self.__doc__ or """
     Returns a nested list of objects that would be also be deleted when
     this object is deleted.
     """
     description = formatting.dedent(description)
     if html:
         return formatting.markup_description(description)
     return description
开发者ID:Darriall,项目名称:editorsnotes,代码行数:9,代码来源:base.py

示例9: get_view_description

def get_view_description(view_cls, html=False):
    """
    Given a view class, return a textual description to represent the view.
    This name is used in the browsable API, and in OPTIONS responses.

    This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
    """
    description = view_cls.__doc__ or ''
    description = formatting.dedent(smart_text(description))
    if html:
        return formatting.markup_description(description)
    return description
开发者ID:fengsi,项目名称:django-rest-framework,代码行数:12,代码来源:views.py

示例10: format_docstring

 def format_docstring(self, view, method, docstring):
     macros = settings.BROWSABLE_DOCUMENT_MACROS
     if view:
         macros['FILTERS'] = get_filters(view)
         if '%(SERIALIZER)s' in docstring:
             macros['SERIALIZER'] = get_serializer(view, include_read_only=True)
         if '%(WRITABLE_SERIALIZER)s' in docstring:
             macros['WRITABLE_SERIALIZER'] = get_serializer(view, include_read_only=False)
     string = formatting.dedent(docstring)
     formatted = string % macros
     formatted = self.substitute_urls(view, method, formatted)
     string = smart_text(formatted)
     return formatting.markup_description(string)
开发者ID:ycheng-aa,项目名称:product-definition-center,代码行数:13,代码来源:renderers.py

示例11: get_view_description

def get_view_description(view_cls, html=False):
    from django_markwhat.templatetags.markup import restructuredtext
    description = view_cls.__doc__ or ''
    description = formatting.dedent(smart_text(description))
    if html:
        rst_doc = getattr(view_cls, 'rst_doc', None)
        if rst_doc:
            if isinstance(rst_doc, str):
                path = os.path.dirname(sys.modules[view_cls.__module__].__file__)
                path = os.path.join(path, rst_doc)
                with open(path) as rst:
                    return restructuredtext(rst.read())
            return restructuredtext(description)
        return formatting.markup_description(description)
    return description
开发者ID:miphreal,项目名称:drf-tweaks,代码行数:15,代码来源:renderers.py

示例12: get_view_description

def get_view_description(cls, html=False):
    description = ''
    if getattr(cls, 'get_description', None):
        cache_key = cls.__name__
        cached_description = cache.get(cache_key)
        if not cached_description:
            description = cls.get_description()
            description = formatting.dedent(smart_text(description))
            # Cache for 1 hour (if we update description, it will take 1 hour to show)
            cache.set(cache_key, description, 60*60)
        else:
            description = cached_description
    if html:
        return formatting.markup_description(description)
    return description
开发者ID:MTG,项目名称:freesound,代码行数:15,代码来源:apiv2_utils.py

示例13: get_view_description

def get_view_description(view, html=False):
    """
    Given a view class, return a textual description to represent the view.
    This name is used in the browsable API, and in OPTIONS responses.

    This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
    """
    # Description may be set by some Views, such as a ViewSet.
    description = getattr(view, 'description', None)
    if description is None:
        description = view.__class__.__doc__ or ''

    description = formatting.dedent(smart_text(description))
    if html:
        return formatting.markup_description(description)
    return description
开发者ID:jplaut,项目名称:django-rest-framework,代码行数:16,代码来源:views.py

示例14: get_description

    def get_description(self, path, method):
        """
        Determine a link description.

        This will be based on the method docstring if one exists,
        or else the class docstring.
        """
        view = self.view

        method_name = getattr(view, 'action', method.lower())
        method_docstring = getattr(view, method_name, None).__doc__
        if method_docstring:
            # An explicit docstring on the method or action.
            return self._get_description_section(view, method.lower(), formatting.dedent(smart_text(method_docstring)))
        else:
            return self._get_description_section(view, getattr(view, 'action', method.lower()), view.get_view_description())
开发者ID:jaidharosenblatt,项目名称:TutorEDU,代码行数:16,代码来源:inspectors.py

示例15: load_obj_from_docstring

    def load_obj_from_docstring(self, docstring):
        """Loads YAML from docstring"""

        # update one dict by other recursively
        def recursive_update(obj, other):
            for key, value in other.iteritems():
                if key in obj and key != 'overwrite':
                    # if value is dictionary we need to update it
                    if isinstance(value, dict) and not value.get('overwrite', False):
                        recursive_update(obj[key], other[key])
                    # if value is a list we need to extend it
                    elif isinstance(value, list):
                        obj[key].extend(value)
                    else:
                        obj[key] = value
                else:
                    obj[key] = value

        if not docstring:
            return {}

        split_lines = trim_docstring(docstring).split('\n')

        # Cut YAML from rest of docstring
        for index, line in enumerate(split_lines):
            line = line.strip()
            if line.startswith('---'):
                cut_from = index
                break
        else:
            return {}
        yaml_string = formatting.dedent("\n".join(split_lines[cut_from:]))

        try:
            yaml_obj = yaml.load(yaml_string)
            # if is parent view specified, we need to get docs from parent view
            if 'inherit_docs_from' in yaml_obj:
                parent_class = self._load_class(yaml_obj['inherit_docs_from'], self.method_introspector.callback)
                parent_docs = self.method_introspector.get_inherited_docs(parent_class)
                parent_obj = self.load_obj_from_docstring(docstring=parent_docs)
                recursive_update(parent_obj, yaml_obj)
                yaml_obj = parent_obj
        except yaml.YAMLError as e:
            self.yaml_error = e
            return {}
        return yaml_obj
开发者ID:Gipzo,项目名称:django-rest-swagger,代码行数:46,代码来源:introspectors.py


注:本文中的rest_framework.utils.formatting.dedent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。