From 454cfe38028263d68058f694ca7bf1b2cffbc290 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 31 Jul 2020 20:43:58 +0530 Subject: wallet api --- _exts/typescriptdomain.py | 342 +++++++++++++++++++++++++--------------------- 1 file changed, 184 insertions(+), 158 deletions(-) (limited to '_exts') diff --git a/_exts/typescriptdomain.py b/_exts/typescriptdomain.py index ce21b3b0..68777645 100644 --- a/_exts/typescriptdomain.py +++ b/_exts/typescriptdomain.py @@ -17,7 +17,7 @@ from pygments.filter import Filter from pygments.token import Literal, Text, Operator, Keyword, Name, Number from pygments.token import Comment, Token, _TokenType from pygments.token import * -from pygments.lexer import RegexLexer, bygroups, include +from pygments.lexer import RegexLexer, bygroups, include from pygments.formatters import HtmlFormatter from docutils import nodes @@ -47,30 +47,30 @@ class TypeScriptDefinition(SphinxDirective): optional_arguments = 0 final_argument_whitespace = False option_spec = { - 'force': directives.flag, - 'linenos': directives.flag, - 'dedent': int, - 'lineno-start': int, - 'emphasize-lines': directives.unchanged_required, - 'caption': directives.unchanged_required, - 'class': directives.class_option, + "force": directives.flag, + "linenos": directives.flag, + "dedent": int, + "lineno-start": int, + "emphasize-lines": directives.unchanged_required, + "caption": directives.unchanged_required, + "class": directives.class_option, } def run(self) -> List[Node]: document = self.state.document - code = '\n'.join(self.content) + code = "\n".join(self.content) location = self.state_machine.get_source_and_line(self.lineno) - linespec = self.options.get('emphasize-lines') + linespec = self.options.get("emphasize-lines") if linespec: try: nlines = len(self.content) hl_lines = parselinenos(linespec, nlines) if any(i >= nlines for i in hl_lines): logger.warning( - __('line number spec is out of range(1-%d): %r') % - (nlines, self.options['emphasize-lines']), - location=location + __("line number spec is out of range(1-%d): %r") + % (nlines, self.options["emphasize-lines"]), + location=location, ) hl_lines = [x + 1 for x in hl_lines if x < nlines] @@ -79,28 +79,26 @@ class TypeScriptDefinition(SphinxDirective): else: hl_lines = None - if 'dedent' in self.options: + if "dedent" in self.options: location = self.state_machine.get_source_and_line(self.lineno) - lines = code.split('\n') - lines = dedent_lines( - lines, self.options['dedent'], location=location - ) - code = '\n'.join(lines) + lines = code.split("\n") + lines = dedent_lines(lines, self.options["dedent"], location=location) + code = "\n".join(lines) literal = nodes.literal_block(code, code) # type: Element - if 'linenos' in self.options or 'lineno-start' in self.options: - literal['linenos'] = True - literal['classes'] += self.options.get('class', []) - literal['force'] = 'force' in self.options - literal['language'] = "tsref" - extra_args = literal['highlight_args'] = {} + if "linenos" in self.options or "lineno-start" in self.options: + literal["linenos"] = True + literal["classes"] += self.options.get("class", []) + literal["force"] = "force" in self.options + literal["language"] = "tsref" + extra_args = literal["highlight_args"] = {} if hl_lines is not None: - extra_args['hl_lines'] = hl_lines - if 'lineno-start' in self.options: - extra_args['linenostart'] = self.options['lineno-start'] + extra_args["hl_lines"] = hl_lines + if "lineno-start" in self.options: + extra_args["linenostart"] = self.options["lineno-start"] self.set_source_info(literal) - caption = self.options.get('caption') + caption = self.options.get("caption") if caption: try: literal = container_wrapper(self, literal, caption) @@ -108,11 +106,11 @@ class TypeScriptDefinition(SphinxDirective): return [document.reporter.warning(exc, line=self.lineno)] tsid = "tsref-type-" + self.arguments[0] - literal['ids'].append(tsid) + literal["ids"].append(tsid) tsname = self.arguments[0] - ts = self.env.get_domain('ts') - ts.add_object('type', tsname, self.env.docname, tsid) + ts = self.env.get_domain("ts") + ts.add_object("type", tsname, self.env.docname, tsid) return [literal] @@ -120,27 +118,24 @@ class TypeScriptDefinition(SphinxDirective): class TypeScriptDomain(Domain): """TypeScript domain.""" - name = 'ts' - label = 'TypeScript' + name = "ts" + label = "TypeScript" directives = { - 'def': TypeScriptDefinition, + "def": TypeScriptDefinition, } roles = { - 'type': - XRefRole( + "type": XRefRole( lowercase=False, warn_dangling=True, innernodeclass=nodes.inline ), } dangling_warnings = { - 'type': 'undefined TypeScript type: %(target)s', + "type": "undefined TypeScript type: %(target)s", } - def resolve_xref( - self, env, fromdocname, builder, typ, target, node, contnode - ): + def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): try: info = self.objects[(str(typ), str(target))] except KeyError: @@ -148,14 +143,10 @@ class TypeScriptDomain(Domain): return None else: anchor = "tsref-type-{}".format(str(target)) - title = typ.upper() + ' ' + target - return make_refnode( - builder, fromdocname, info[0], anchor, contnode, title - ) + title = typ.upper() + " " + target + return make_refnode(builder, fromdocname, info[0], anchor, contnode, title) - def resolve_any_xref( - self, env, fromdocname, builder, target, node, contnode - ): + def resolve_any_xref(self, env, fromdocname, builder, target, node, contnode): """Resolve the pending_xref *node* with the given *target*. The reference comes from an "any" or similar role, which means that Sphinx @@ -174,22 +165,18 @@ class TypeScriptDomain(Domain): pass else: anchor = "tsref-type-{}".format(str(target)) - title = "TYPE" + ' ' + target - node = make_refnode( - builder, fromdocname, info[0], anchor, contnode, title - ) + title = "TYPE" + " " + target + node = make_refnode(builder, fromdocname, info[0], anchor, contnode, title) ret.append(("ts:type", node)) return ret @property def objects(self) -> Dict[Tuple[str, str], Tuple[str, str]]: return self.data.setdefault( - 'objects', {} + "objects", {} ) # (objtype, name) -> docname, labelid - def add_object( - self, objtype: str, name: str, docname: str, labelid: str - ) -> None: + def add_object(self, objtype: str, name: str, docname: str, labelid: str) -> None: self.objects[objtype, name] = (docname, labelid) @@ -198,101 +185,114 @@ class BetterTypeScriptLexer(RegexLexer): For `TypeScript `_ source code. """ - name = 'TypeScript' - aliases = ['ts'] - filenames = ['*.ts'] - mimetypes = ['text/x-typescript'] + name = "TypeScript" + aliases = ["ts"] + filenames = ["*.ts"] + mimetypes = ["text/x-typescript"] flags = re.DOTALL tokens = { - 'commentsandwhitespace': [(r'\s+', Text), (r'