예제 #1
0
    def __init__(self, docstring, config=None, app=None, what='', name='',
                 obj=None, options=None):
        # type: (Union[unicode, List[unicode]], SphinxConfig, Sphinx, unicode, unicode, Any, Any) -> None  # NOQA
        self._config = config
        self._app = app

        if not self._config:
            from sphinx.ext.napoleon import Config
            self._config = self._app and self._app.config or Config()  # type: ignore

        if not what:
            if inspect.isclass(obj):
                what = 'class'
            elif inspect.ismodule(obj):
                what = 'module'
            elif isinstance(obj, collections.Callable):  # type: ignore
                what = 'function'
            else:
                what = 'object'

        self._what = what
        self._name = name
        self._obj = obj
        self._opt = options
        if isinstance(docstring, string_types):
            docstring = docstring.splitlines()
        self._lines = docstring
        self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
        self._parsed_lines = []  # type: List[unicode]
        self._is_in_section = False
        self._section_indent = 0
        if not hasattr(self, '_directive_sections'):
            self._directive_sections = []  # type: List[unicode]
        if not hasattr(self, '_sections'):
            self._sections = {
                'args': self._parse_parameters_section,
                'arguments': self._parse_parameters_section,
                'attributes': self._parse_attributes_section,
                'example': self._parse_examples_section,
                'examples': self._parse_examples_section,
                'keyword args': self._parse_keyword_arguments_section,
                'keyword arguments': self._parse_keyword_arguments_section,
                'methods': self._parse_methods_section,
                'note': self._parse_note_section,
                'notes': self._parse_notes_section,
                'other parameters': self._parse_other_parameters_section,
                'parameters': self._parse_parameters_section,
                'return': self._parse_returns_section,
                'returns': self._parse_returns_section,
                'raises': self._parse_raises_section,
                'references': self._parse_references_section,
                'see also': self._parse_see_also_section,
                'todo': self._parse_todo_section,
                'warning': self._parse_warning_section,
                'warnings': self._parse_warning_section,
                'warns': self._parse_warns_section,
                'yield': self._parse_yields_section,
                'yields': self._parse_yields_section,
            }  # type: Dict[unicode, Callable]
        self._parse()
예제 #2
0
    def __init__(self, docstring, config=None, app=None, what="", name="", obj=None, options=None):
        self._config = config
        self._app = app

        if not self._config:
            from sphinx.ext.napoleon import Config

            self._config = self._app and self._app.config or Config()

        if not what:
            if inspect.isclass(obj):
                what = "class"
            elif inspect.ismodule(obj):
                what = "module"
            elif isinstance(obj, collections.Callable):
                what = "function"
            else:
                what = "object"

        self._what = what
        self._name = name
        self._obj = obj
        self._opt = options
        if isinstance(docstring, string_types):
            docstring = docstring.splitlines()
        self._lines = docstring
        self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
        self._parsed_lines = []
        self._is_in_section = False
        self._section_indent = 0
        if not hasattr(self, "_directive_sections"):
            self._directive_sections = []
        if not hasattr(self, "_sections"):
            self._sections = {
                "args": self._parse_parameters_section,
                "arguments": self._parse_parameters_section,
                "attributes": self._parse_attributes_section,
                "example": self._parse_examples_section,
                "examples": self._parse_examples_section,
                "keyword args": self._parse_keyword_arguments_section,
                "keyword arguments": self._parse_keyword_arguments_section,
                "methods": self._parse_methods_section,
                "note": self._parse_note_section,
                "notes": self._parse_notes_section,
                "other parameters": self._parse_other_parameters_section,
                "parameters": self._parse_parameters_section,
                "return": self._parse_returns_section,
                "returns": self._parse_returns_section,
                "raises": self._parse_raises_section,
                "references": self._parse_references_section,
                "see also": self._parse_see_also_section,
                "todo": self._parse_todo_section,
                "warning": self._parse_warning_section,
                "warnings": self._parse_warning_section,
                "warns": self._parse_warns_section,
                "yield": self._parse_yields_section,
                "yields": self._parse_yields_section,
            }
        self._parse()
예제 #3
0
파일: tlisp.py 프로젝트: gcabbage/TransDoc
    def __init__(self, docstring, config=None, sig=None, what='', name='',
               arglist='', retann='', allfuncs=[]):
        self._config = config

        if not what:
            what = 'function'

        if sig:
            name, arglist, retann = tlisp_sig_re.match(sig).groups()
            self.tlisp_signature = sig.strip()

        self._what = what
        self.name = name
        self.args = [arg.strip('[]') for arg in arglist.split()]
        self.retann = retann

        if isinstance(docstring, string_types):
            def lnkrepl(match):
                if match.group(1).lower() in allfuncs:
                    return ':tl:function:`'+match.group()+'`'
                else:
                    return match.group()
            docstring = _literal_regex.sub(r'``\1``', docstring)
            docstring = _fnclink_regex.sub(lnkrepl, docstring)
            docstring = docstring.splitlines()
        self._lines = docstring
        self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
        self._parsed_lines = []  # type: List[unicode]
        self._is_in_section = False
        self._is_in_params = False
        self._param_fields = []
        self._section_indent = 0
        self._directive_sections = []
        self._sections = {
                'parameter': self._parse_parameter_section,
                'attributes': self._parse_attributes_section,
                'example': self._parse_examples_section,
                'examples': self._parse_examples_section,
                'keyword args': self._parse_keyword_arguments_section,
                'keyword arguments': self._parse_keyword_arguments_section,
                'methods': self._parse_methods_section,
                'note': self._parse_note_section,
                'notes': self._parse_notes_section,
                'other parameters': self._parse_other_parameters_section,
                'return': self._parse_returns_section,
                'returns': self._parse_returns_section,
                'raises': self._parse_raises_section,
                'references': self._parse_references_section,
                'see also': self._parse_see_also_section,
                'todo': self._parse_todo_section,
                'warning': self._parse_warning_section,
                'warnings': self._parse_warning_section,
                'warns': self._parse_warns_section,
                'yield': self._parse_yields_section,
                'yields': self._parse_yields_section,
                } # type: Dict[unicode, Callable]
        self._parse()
        self.__doc__ = str(self)
    def test_init_with_sentinel_args(self):
        a = iter(['1', '2', '3', 'DONE'])
        sentinel = 'DONE'

        def get_next():
            return next(a)
        it = modify_iter(get_next, sentinel, int)
        expected = [1, 2, 3]
        self.assertEqual(expected, [i for i in it])
    def test_init_with_sentinel_kwargs(self):
        a = iter([1, 2, 3, 4])
        sentinel = 4

        def get_next():
            return next(a)
        it = modify_iter(get_next, sentinel, modifier=str)
        expected = ['1', '2', '3']
        self.assertEqual(expected, [i for i in it])
예제 #6
0
    def test_init_with_sentinel_kwargs(self):
        a = iter([1, 2, 3, 4])
        sentinel = 4

        def get_next():
            return next(a)
        it = modify_iter(get_next, sentinel, modifier=str)
        expected = ['1', '2', '3']
        self.assertEqual(expected, [i for i in it])
예제 #7
0
    def test_init_with_sentinel_args(self):
        a = iter(['1', '2', '3', 'DONE'])
        sentinel = 'DONE'

        def get_next():
            return next(a)
        it = modify_iter(get_next, sentinel, int)
        expected = [1, 2, 3]
        self.assertEqual(expected, [i for i in it])
예제 #8
0
파일: docstring.py 프로젝트: ck1981/sphinx
 def __init__(self,
              docstring,
              config=None,
              app=None,
              what='',
              name='',
              obj=None,
              options=None):
     self._config = config
     self._app = app
     if not self._config:
         from sphinx.ext.napoleon import Config
         self._config = self._app and self._app.config or Config()
     self._what = what
     self._name = name
     self._obj = obj
     self._opt = options
     if isinstance(docstring, basestring):
         docstring = docstring.splitlines()
     self._lines = docstring
     self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
     self._parsed_lines = []
     self._is_in_section = False
     self._section_indent = 0
     if not hasattr(self, '_directive_sections'):
         self._directive_sections = []
     if not hasattr(self, '_sections'):
         self._sections = {
             'args': self._parse_parameters_section,
             'arguments': self._parse_parameters_section,
             'attributes': self._parse_attributes_section,
             'example': self._parse_examples_section,
             'examples': self._parse_examples_section,
             'keyword args': self._parse_keyword_arguments_section,
             'keyword arguments': self._parse_keyword_arguments_section,
             'methods': self._parse_methods_section,
             'note': self._parse_note_section,
             'notes': self._parse_notes_section,
             'other parameters': self._parse_other_parameters_section,
             'parameters': self._parse_parameters_section,
             'return': self._parse_returns_section,
             'returns': self._parse_returns_section,
             'raises': self._parse_raises_section,
             'references': self._parse_references_section,
             'see also': self._parse_see_also_section,
             'warning': self._parse_warning_section,
             'warnings': self._parse_warning_section,
             'warns': self._parse_warns_section,
             'yields': self._parse_yields_section,
         }
     self._parse()
    def __init__(self, docstring: str) -> None:
        lines = docstring.splitlines()
        self._line_iter = modify_iter(lines, modifier=lambda s: s.rstrip())
        self._parsed_sections: List[SectionBrick] = []
        self._is_in_section = False
        self._section_indent = 0
        if not hasattr(self, "_sections"):
            self._sections: Dict[str, Callable] = {
                "args": self._parse_parameters_section,
                "arguments": self._parse_parameters_section,
                "parameters": self._parse_parameters_section,
                "return": self._parse_returns_section,
                "returns": self._parse_returns_section,
            }

        self._parse()
예제 #10
0
파일: docstring.py 프로젝트: Scalr/sphinx
 def __init__(self, docstring, config=None, app=None, what='', name='',
              obj=None, options=None):
     self._config = config
     self._app = app
     if not self._config:
         from sphinx.ext.napoleon import Config
         self._config = self._app and self._app.config or Config()
     self._what = what
     self._name = name
     self._obj = obj
     self._opt = options
     if isinstance(docstring, basestring):
         docstring = docstring.splitlines()
     self._lines = docstring
     self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
     self._parsed_lines = []
     self._is_in_section = False
     self._section_indent = 0
     if not hasattr(self, '_directive_sections'):
         self._directive_sections = []
     if not hasattr(self, '_sections'):
         self._sections = {
             'args': self._parse_parameters_section,
             'arguments': self._parse_parameters_section,
             'attributes': self._parse_attributes_section,
             'example': self._parse_examples_section,
             'examples': self._parse_examples_section,
             'keyword args': self._parse_keyword_arguments_section,
             'keyword arguments': self._parse_keyword_arguments_section,
             'methods': self._parse_methods_section,
             'note': self._parse_note_section,
             'notes': self._parse_notes_section,
             'other parameters': self._parse_other_parameters_section,
             'parameters': self._parse_parameters_section,
             'return': self._parse_returns_section,
             'returns': self._parse_returns_section,
             'raises': self._parse_raises_section,
             'references': self._parse_references_section,
             'see also': self._parse_see_also_section,
             'warning': self._parse_warning_section,
             'warnings': self._parse_warning_section,
             'warns': self._parse_warns_section,
             'yields': self._parse_yields_section,
         }
     self._parse()
예제 #11
0
 def test_modifier_rstrip_unicode(self):
     a = [u'', u'  ', u'  a  ', u'b  ', u'  c', u'  ', u'']
     it = modify_iter(a, modifier=lambda s: s.rstrip())
     expected = [u'', u'', u'  a', u'b', u'  c', u'', u'']
     self.assertEqual(expected, [i for i in it])
예제 #12
0
    def __init__(self, docstring: Union[str, List[str]], config: SphinxConfig = None,
                 app: Sphinx = None, what: str = '', name: str = '',
                 obj: Any = None, options: Any = None) -> None:
        self._config = config
        self._app = app

        if not self._config:
            from sphinx.ext.napoleon import Config
            self._config = self._app.config if self._app else Config()  # type: ignore

        if not what:
            if inspect.isclass(obj):
                what = 'class'
            elif inspect.ismodule(obj):
                what = 'module'
            elif callable(obj):
                what = 'function'
            else:
                what = 'object'

        self._what = what
        self._name = name
        self._obj = obj
        self._opt = options
        if isinstance(docstring, str):
            lines = docstring.splitlines()
        else:
            lines = docstring
        self._line_iter = modify_iter(lines, modifier=lambda s: s.rstrip())
        self._parsed_lines = []  # type: List[str]
        self._is_in_section = False
        self._section_indent = 0
        if not hasattr(self, '_directive_sections'):
            self._directive_sections = []  # type: List[str]
        if not hasattr(self, '_sections'):
            self._sections = {
                'args': self._parse_parameters_section,
                'arguments': self._parse_parameters_section,
                'attention': partial(self._parse_admonition, 'attention'),
                'attributes': self._parse_attributes_section,
                'caution': partial(self._parse_admonition, 'caution'),
                'danger': partial(self._parse_admonition, 'danger'),
                'error': partial(self._parse_admonition, 'error'),
                'example': self._parse_examples_section,
                'examples': self._parse_examples_section,
                'hint': partial(self._parse_admonition, 'hint'),
                'important': partial(self._parse_admonition, 'important'),
                'keyword args': self._parse_keyword_arguments_section,
                'keyword arguments': self._parse_keyword_arguments_section,
                'methods': self._parse_methods_section,
                'note': partial(self._parse_admonition, 'note'),
                'notes': self._parse_notes_section,
                'other parameters': self._parse_other_parameters_section,
                'parameters': self._parse_parameters_section,
                'return': self._parse_returns_section,
                'returns': self._parse_returns_section,
                'raise': self._parse_raises_section,
                'raises': self._parse_raises_section,
                'references': self._parse_references_section,
                'see also': self._parse_see_also_section,
                'tip': partial(self._parse_admonition, 'tip'),
                'todo': partial(self._parse_admonition, 'todo'),
                'warning': partial(self._parse_admonition, 'warning'),
                'warnings': partial(self._parse_admonition, 'warning'),
                'warn': self._parse_warns_section,
                'warns': self._parse_warns_section,
                'yield': self._parse_yields_section,
                'yields': self._parse_yields_section,
            }  # type: Dict[str, Callable]

        self._load_custom_sections()

        self._parse()
 def test_modifier_rstrip_unicode(self):
     a = ['', '  ', '  a  ', 'b  ', '  c', '  ', '']
     it = modify_iter(a, modifier=lambda s: s.rstrip())
     expected = ['', '', '  a', 'b', '  c', '', '']
     self.assertEqual(expected, [i for i in it])
 def test_modifier_default(self):
     a = ['', '  ', '  a  ', 'b  ', '  c', '  ', '']
     it = modify_iter(a)
     expected = ['', '  ', '  a  ', 'b  ', '  c', '  ', '']
     self.assertEqual(expected, [i for i in it])
예제 #15
0
 def test_modifier_rstrip(self):
     a = ['', '  ', '  a  ', 'b  ', '  c', '  ', '']
     it = modify_iter(a, modifier=lambda s: s.rstrip())
     expected = ['', '', '  a', 'b', '  c', '', '']
     self.assertEqual(expected, list(it))
예제 #16
0
    def __init__(self, docstring, config=None, app=None, what='', name='',
                 obj=None, options=None):
        # type: (Union[str, List[str]], SphinxConfig, Sphinx, str, str, Any, Any) -> None
        self._config = config
        self._app = app

        if not self._config:
            from sphinx.ext.napoleon import Config
            self._config = self._app and self._app.config or Config()  # type: ignore

        if not what:
            if inspect.isclass(obj):
                what = 'class'
            elif inspect.ismodule(obj):
                what = 'module'
            elif callable(obj):
                what = 'function'
            else:
                what = 'object'

        self._what = what
        self._name = name
        self._obj = obj
        self._opt = options
        if isinstance(docstring, str):
            lines = docstring.splitlines()
        else:
            lines = docstring
        self._line_iter = modify_iter(lines, modifier=lambda s: s.rstrip())
        self._parsed_lines = []  # type: List[str]
        self._is_in_section = False
        self._section_indent = 0
        if not hasattr(self, '_directive_sections'):
            self._directive_sections = []  # type: List[str]
        if not hasattr(self, '_sections'):
            self._sections = {
                'args': self._parse_parameters_section,
                'arguments': self._parse_parameters_section,
                'attention': partial(self._parse_admonition, 'attention'),
                'attributes': self._parse_attributes_section,
                'caution': partial(self._parse_admonition, 'caution'),
                'danger': partial(self._parse_admonition, 'danger'),
                'error': partial(self._parse_admonition, 'error'),
                'example': self._parse_examples_section,
                'examples': self._parse_examples_section,
                'hint': partial(self._parse_admonition, 'hint'),
                'important': partial(self._parse_admonition, 'important'),
                'keyword args': self._parse_keyword_arguments_section,
                'keyword arguments': self._parse_keyword_arguments_section,
                'methods': self._parse_methods_section,
                'note': partial(self._parse_admonition, 'note'),
                'notes': self._parse_notes_section,
                'other parameters': self._parse_other_parameters_section,
                'parameters': self._parse_parameters_section,
                'return': self._parse_returns_section,
                'returns': self._parse_returns_section,
                'raises': self._parse_raises_section,
                'references': self._parse_references_section,
                'see also': self._parse_see_also_section,
                'tip': partial(self._parse_admonition, 'tip'),
                'todo': partial(self._parse_admonition, 'todo'),
                'warning': partial(self._parse_admonition, 'warning'),
                'warnings': partial(self._parse_admonition, 'warning'),
                'warns': self._parse_warns_section,
                'yield': self._parse_yields_section,
                'yields': self._parse_yields_section,
            }  # type: Dict[str, Callable]

        self._load_custom_sections()

        self._parse()
예제 #17
0
 def test_modifier_default(self):
     a = ['', '  ', '  a  ', 'b  ', '  c', '  ', '']
     it = modify_iter(a)
     expected = ['', '  ', '  a  ', 'b  ', '  c', '  ', '']
     self.assertEqual(expected, [i for i in it])