signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def is_dict(etype) -> bool: | return issubclass(type(etype), dict)<EOL> | Determine whether etype is a Dict | f15219:m2 |
def is_iterable(etype) -> bool: | return getattr(etype, '<STR_LIT>', None) is not None and issubclass(etype.__origin__, Iterable)<EOL> | Determine whether etype is a List or other iterable | f15219:m3 |
def union_conforms(element: Union, etype, namespace: Dict[str, Any], conforms: Callable) -> bool: | return any(conforms(element, t, namespace) for t in etype.__args__)<EOL> | Determine whether element conforms to at least one of the types in etype
:param element: element to test
:param etype: type to test against
:param namespace: Namespace to use for resolving forward references
:param conforms: conformance test function
:return: True if element conforms to at least one type in etype | f15219:m4 |
def logger(): | return Logger(cast(TextIO, StringIO()))<EOL> | Return a | f15220:m0 |
def __init__(self, logfile: Optional[TextIO] = None): | self.nerrors = <NUM_LIT:0><EOL>self._logfile = logfile<EOL> | Construct a logging instance
:param logfile: File to log to. If absent, no messages are recorded | f15220:c0:m0 |
def log(self, txt: str) -> bool: | self.nerrors += <NUM_LIT:1><EOL>if self._logfile is not None:<EOL><INDENT>print(txt, file=self._logfile)<EOL><DEDENT>return not self.logging<EOL> | Log txt (if any) to the log file (if any). Return value indicates whether it is ok to terminate on the first
error or whether we need to continue processing.
:param txt: text to log.
:return: True if we aren't logging, False if we are. | f15220:c0:m1 |
@property<EOL><INDENT>def logging(self):<DEDENT> | return self._logfile is not None<EOL> | Return True if errors are being recorded in the log, false if just checking for anything wrong | f15220:c0:m3 |
def getvalue(self) -> Optional[str]: | return self._logfile.read() if self._logfile else None<EOL> | Return the current contents of the log file, if any | f15220:c0:m4 |
def __init__(self, context: JSGContext, **kwargs): | JsonObj.__init__(self)<EOL>self._context = context<EOL>if self._class_name not in context.TYPE_EXCEPTIONS and context.TYPE:<EOL><INDENT>self[context.TYPE] = self._class_name<EOL><DEDENT>for k, v in kwargs.items():<EOL><INDENT>setattr(self, k, kwargs[k])<EOL><DEDENT> | Generic constructor
:param context: Context for TYPE and IGNORE variables
:param kwargs: Initial values - object specific | f15221:c1:m0 |
def __setattr__(self, key: str, value: Any) -> None: | <EOL>if key.startswith('<STR_LIT:_>') or key in self._members or self._context.unvalidated_parm(key):<EOL><INDENT>if key in self._members:<EOL><INDENT>vtype = self._members[key]<EOL>if value is Empty:<EOL><INDENT>self[key] = Empty<EOL><DEDENT>elif value is None:<EOL><INDENT>self[key] = self._map_jsg_type(key, value, vtype)<EOL><DEDENT>else:<EOL><INDENT>self[key] = self._jsg_type_for(key, value, vtype)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>cur_val = self.__dict__.get(key)<EOL>if cur_val is None or not issubclass(type(cur_val), JSGString):<EOL><INDENT>self[key] = value<EOL><DEDENT>else:<EOL><INDENT>self[key] = cur_val.__class__(value)<EOL><DEDENT><DEDENT><DEDENT>elif self._strict:<EOL><INDENT>raise ValueError("<STR_LIT>".format(key, value))<EOL><DEDENT>else:<EOL><INDENT>super().__setattr__(key, value)<EOL><DEDENT> | Attribute setter. Any attribute that is part of the members list or not validated passes. Otherwise
setting is only allowed if the class level _strict mode is False
:param key:
:param value:
:return: | f15221:c1:m1 |
@staticmethod<EOL><INDENT>def _strip_nones(d: Dict[str, Any])-> Dict[str, Any]:<DEDENT> | return OrderedDict({k: None if isinstance(v, JSGNull) else v for k, v in d.items()<EOL>if not k.startswith("<STR_LIT:_>") and v is not None and v is not Empty and<EOL>(issubclass(type(v), JSGObject) or<EOL>(not issubclass(type(v), JSGString) or v.val is not None) and<EOL>(not issubclass(type(v), AnyType) or v.val is not Empty))})<EOL> | An attribute with type None is equivalent to an absent attribute.
:param d: Object with attributes
:return: Object dictionary w/ Nones and underscores removed | f15221:c1:m5 |
def _default(self, obj: object): | return None if obj is JSGNull else obj.val if type(obj) is AnyType elseJSGObject._strip_nones(obj.__dict__) if isinstance(obj, JsonObj)else cast(JSGString, obj).val if issubclass(type(obj), JSGString) else str(obj)<EOL> | Return a serializable version of obj. Overrides JsonObj _default method
:param obj: Object to be serialized
:return: Serialized version of obj | f15221:c1:m7 |
def flatten(l: Iterable) -> List: | rval = []<EOL>for e in l:<EOL><INDENT>if not isinstance(e, str) and isinstance(e, Iterable):<EOL><INDENT>if len(list(e)):<EOL><INDENT>rval += flatten(e)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rval.append(e)<EOL><DEDENT><DEDENT>return rval<EOL> | Return a list of all non-list items in l
:param l: list to be flattened
:return: | f15222:m1 |
def flatten_unique(l: Iterable) -> List: | rval = OrderedDict()<EOL>for e in l:<EOL><INDENT>if not isinstance(e, str) and isinstance(e, Iterable):<EOL><INDENT>for ev in flatten_unique(e):<EOL><INDENT>rval[ev] = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rval[e] = None<EOL><DEDENT><DEDENT>return list(rval.keys())<EOL> | Return a list of UNIQUE non-list items in l | f15222:m2 |
def as_set(l: Iterable) -> Set: | return set(flatten(l))<EOL> | Return the set of all terminals in list l
:param l: | f15222:m3 |
def get_terminal(ctx: ParserRuleContext) -> str: | tkn = None<EOL>for ele_name in identifier_types:<EOL><INDENT>ele = getattr(ctx, ele_name, None)<EOL>if ele and ele():<EOL><INDENT>tkn = ele().getText()[<NUM_LIT:1>:-<NUM_LIT:1>] if ele_name == '<STR_LIT>' else ele().getText()<EOL><DEDENT><DEDENT>return str(tkn)<EOL> | Extract the token for an identifier from the context. Tokens can be:
* ID - The name of a JSG definition
* idref -- A reference to an existing JSG definition
* LEXER_ID - The name of a match pattern definition
* LEXER_ID_REF - A reference to an existing match pattern definition
* STRING -- A JSG item name enclosed in quotes
:param ctx: JSG parser item with some sort of identifier
:return: | f15222:m4 |
def as_token(ctx: ParserRuleContext) -> str: | return esc_kw(get_terminal(ctx))<EOL> | Extract the token for an identifier from the context. Tokens can be:
* ID - The name of a JSG definition
* idref -- A reference to an existing JSG definition
* LEXER_ID - The name of a match pattern definition
* LEXER_ID_REF - A reference to an existing match pattern definition
* STRING -- A JSG item name enclosed in quotes
:param ctx: JSG parser item with some sort of identifier
:return: | f15222:m5 |
def as_tokens(ctx: List[ParserRuleContext]) -> List[str]: | return [as_token(e) for e in ctx]<EOL> | Return a stringified list of identifiers in ctx
:param ctx: JSG parser item with a set of identifiers
:return: | f15222:m6 |
def is_valid_python(tkn: str) -> bool: | try:<EOL><INDENT>root = ast.parse(tkn)<EOL><DEDENT>except SyntaxError:<EOL><INDENT>return False<EOL><DEDENT>return len(root.body) == <NUM_LIT:1> and isinstance(root.body[<NUM_LIT:0>], ast.Expr) and isinstance(root.body[<NUM_LIT:0>].value, ast.Name)<EOL> | Determine whether tkn is a valid python identifier
:param tkn:
:return: | f15222:m7 |
def esc_kw(token: str) -> str: | return token + '<STR_LIT:_>' if keyword.iskeyword(token) else token<EOL> | Escape python keywords
:param token: token
:return: token with '_' suffixed if it is a keyword | f15222:m8 |
@abstractmethod<EOL><INDENT>def python_type(self) -> str:<DEDENT> | ...<EOL> | Return the native python type of this element | f15223:c0:m0 |
@abstractmethod<EOL><INDENT>def signature_type(self) -> str:<DEDENT> | ...<EOL> | Return the formal JSG type of this element | f15223:c0:m1 |
@abstractmethod<EOL><INDENT>def reference_type(self) -> str:<DEDENT> | ...<EOL> | Return how this type should be referenced from other types | f15223:c0:m2 |
@abstractmethod<EOL><INDENT>def mt_value(self) -> str:<DEDENT> | Return the empty (missing) value token fo rthis element | f15223:c0:m3 | |
@abstractmethod<EOL><INDENT>def members_entries(self, all_are_optional: Optional[bool] = False) -> List[Tuple[str, str]]:<DEDENT> | ...<EOL> | Return the name / type initializers for the _members section of the generated python | f15223:c0:m4 |
@abstractmethod<EOL><INDENT>def dependency_list(self) -> List[str]:<DEDENT> | ...<EOL> | Return an ordered list of element names that this is dependent on | f15223:c0:m5 |
def anon_id(self) -> str: | return self._id_factory.next_id()<EOL> | Generate a new anonymous identifier | f15223:c3:m1 |
def is_anon(self, tkn: str) -> bool: | return self._id_factory.is_anon(tkn)<EOL> | Determine whther tkn represents an anonymous identifier | f15223:c3:m2 |
def reference(self, tkn: str): | return self.grammarelts[tkn] if tkn in self.grammarelts else UndefinedElement(tkn)<EOL> | Return the element that tkn represents | f15223:c3:m3 |
def dependency_list(self, tkn: str) -> List[str]: | if tkn not in self.dependency_map:<EOL><INDENT>self.dependency_map[tkn] = [tkn] <EOL>self.dependency_map[tkn] = self.reference(tkn).dependency_list()<EOL><DEDENT>return self.dependency_map[tkn]<EOL> | Return a list all of the grammarelts that depend on tkn
:param tkn:
:return: | f15223:c3:m7 |
def dependencies(self, tkn: str) -> Set[str]: | return set(self.dependency_list(tkn))<EOL> | Return all the items that tkn depends on as a set
:param tkn:
:return: | f15223:c3:m8 |
def undefined_entries(self) -> Set[str]: | return as_set([[d for d in self.dependencies(k) if d not in self.grammarelts]<EOL>for k in self.grammarelts.keys()])<EOL> | Return the set of tokens that are referenced but not defined. | f15223:c3:m9 |
def dependency_closure(self, tkn: str, seen: Optional[Set[str]]=None) -> Set[str]: | if seen is None:<EOL><INDENT>seen = set()<EOL><DEDENT>for k in self.dependencies(tkn):<EOL><INDENT>if k not in seen:<EOL><INDENT>seen.add(k)<EOL>self.dependency_closure(k, seen)<EOL><DEDENT><DEDENT>return seen<EOL> | Determine the transitive closure of tkn's dependencies
:param tkn: root token
:param seen: list of tokens already visited in closure process
:return: dependents, dependents of dependents, etc. | f15223:c3:m10 |
def circular_references(self) -> Set[str]: | rval = set()<EOL>for k in self.grammarelts.keys():<EOL><INDENT>if k in self.dependency_closure(k):<EOL><INDENT>rval.add(k)<EOL><DEDENT><DEDENT>return rval<EOL> | Return the set of recursive (circular) references
:return: | f15223:c3:m11 |
def resolve_circular_references(self) -> None: | circulars = self.circular_references()<EOL>for c in circulars:<EOL><INDENT>fwdref = JSGForwardRef(c)<EOL>self.grammarelts[fwdref.label] = fwdref<EOL>self.forward_refs[c] = fwdref.label<EOL><DEDENT> | Create forward references for all circular references
:return: | f15223:c3:m12 |
def ordered_elements(self) -> str: | from pyjsg.parser_impl.jsg_lexerruleblock_parser import JSGLexerRuleBlock<EOL>from pyjsg.parser_impl.jsg_arrayexpr_parser import JSGArrayExpr<EOL>from pyjsg.parser_impl.jsg_objectexpr_parser import JSGObjectExpr<EOL>from pyjsg.parser_impl.jsg_builtinvaluetype_parser import JSGBuiltinValueType<EOL>from pyjsg.parser_impl.jsg_valuetype_parser import JSGValueType<EOL>state = <NUM_LIT:0><EOL>self.depths = {}<EOL>for k in self.dependency_map.keys():<EOL><INDENT>self.calc_depths(k)<EOL><DEDENT>depth = -<NUM_LIT:1><EOL>max_depth = max(self.depths.values()) if self.depths else <NUM_LIT:0><EOL>while state >= <NUM_LIT:0>:<EOL><INDENT>iter_ = iter([])<EOL>if state == <NUM_LIT:0>:<EOL><INDENT>depth += <NUM_LIT:1><EOL>if depth <= max_depth:<EOL><INDENT>iter_ = (k for k, v in self.grammarelts.items()<EOL>if isinstance(v, (JSGLexerRuleBlock, JSGBuiltinValueType)) and self.depths[k] == depth)<EOL><DEDENT>else:<EOL><INDENT>depth = -<NUM_LIT:1><EOL>state += <NUM_LIT:1><EOL><DEDENT><DEDENT>elif state == <NUM_LIT:1>:<EOL><INDENT>depth += <NUM_LIT:1><EOL>if depth <= max_depth:<EOL><INDENT>iter_ = (k for k, v in self.grammarelts.items()<EOL>if isinstance(v, (JSGObjectExpr, JSGArrayExpr, JSGValueType)) and<EOL>self.depths[k] == depth and k not in self.forward_refs)<EOL><DEDENT>else:<EOL><INDENT>depth = -<NUM_LIT:1><EOL>state += <NUM_LIT:1><EOL><DEDENT><DEDENT>elif state == <NUM_LIT:2>: <EOL><INDENT>depth += <NUM_LIT:1><EOL>if depth <= max_depth:<EOL><INDENT>iter_ = (k for k, v in self.grammarelts.items()<EOL>if isinstance(v, (JSGObjectExpr, JSGArrayExpr, JSGValueType)) and<EOL>self.depths[k] == depth and k in self.forward_refs)<EOL><DEDENT>else:<EOL><INDENT>state = -<NUM_LIT:1><EOL><DEDENT><DEDENT>while state >= <NUM_LIT:0>:<EOL><INDENT>rval = next(iter_, None)<EOL>if rval is None:<EOL><INDENT>break<EOL><DEDENT>yield rval<EOL><DEDENT><DEDENT> | Generator that returns items in ther order needed for the actual python
1) All forward references
2) All lexer items
3) Object / Array definitions in order of increasing dependency depth
Within each category, items are returned alphabetically | f15223:c3:m13 |
def visitArrayExpr(self, ctx: jsgParser.ArrayExprContext): | from pyjsg.parser_impl.jsg_ebnf_parser import JSGEbnf<EOL>from pyjsg.parser_impl.jsg_valuetype_parser import JSGValueType<EOL>self._types = [JSGValueType(self._context, vt) for vt in ctx.valueType()]<EOL>if ctx.ebnfSuffix():<EOL><INDENT>self._ebnf = JSGEbnf(self._context, ctx.ebnfSuffix())<EOL><DEDENT> | arrayExpr: OBRACKET valueType (BAR valueType)* ebnfSuffix? CBRACKET; | f15224:c0:m9 |
def visitBuiltinValueType(self, ctx: jsgParser.BuiltinValueTypeContext): | self._value_type_text = ctx.getText()<EOL>self._typeinfo = self.parserTypeToImplClass[self._value_type_text]<EOL> | valueTypeExpr: JSON_STRING | JSON_NUMBER | JSON_INT | JSON_BOOL | JSON_NULL | JSON_ARRAY | JSON_OBJECT | f15225:c0:m8 |
def as_python(self, name: str) -> str: | if self._map_valuetype:<EOL><INDENT>return self.map_as_python(name)<EOL><DEDENT>else:<EOL><INDENT>return self.obj_as_python(name)<EOL><DEDENT> | Return the python representation of the class represented by this object | f15227:c0:m3 |
def members_entries(self, all_are_optional: bool=False) -> List[Tuple[str, str]]: | rval = []<EOL>if self._members:<EOL><INDENT>for member in self._members:<EOL><INDENT>rval += member.members_entries(all_are_optional)<EOL><DEDENT><DEDENT>elif self._choices:<EOL><INDENT>for choice in self._choices:<EOL><INDENT>rval += self._context.reference(choice).members_entries(True)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT>return rval<EOL> | Return an ordered list of elements for the _members section
:param all_are_optional: True means we're in a choice situation so everything is optional
:return: | f15227:c0:m14 |
def visitObjectExpr(self, ctx: jsgParser.ObjectExprContext): | if not self._name:<EOL><INDENT>self._name = self._context.anon_id()<EOL><DEDENT>if ctx.membersDef():<EOL><INDENT>self.visitChildren(ctx)<EOL><DEDENT>elif ctx.MAPSTO():<EOL><INDENT>if ctx.LEXER_ID_REF():<EOL><INDENT>self._map_name_type = as_token(ctx)<EOL><DEDENT>self._map_valuetype = JSGValueType(self._context, ctx.valueType())<EOL>if ctx.ebnfSuffix():<EOL><INDENT>self._map_ebnf = JSGEbnf(self._context, ctx.ebnfSuffix())<EOL><DEDENT><DEDENT> | objectExpr: OBRACE membersDef? CBRACE
OBRACE (LEXER_ID_REF | ANY)? MAPSTO valueType ebnfSuffix? CBRACE | f15227:c0:m16 |
def visitMembersDef(self, ctx: jsgParser.MembersDefContext): | if not self._name:<EOL><INDENT>self._name = self._context.anon_id()<EOL><DEDENT>if ctx.COMMA(): <EOL><INDENT>self._strict = False<EOL><DEDENT>if not ctx.BAR(): <EOL><INDENT>self.visitChildren(ctx)<EOL><DEDENT>else:<EOL><INDENT>entry = <NUM_LIT:1><EOL>self._add_choice(entry, ctx.member()) <EOL>for alt in ctx.altMemberDef():<EOL><INDENT>entry += <NUM_LIT:1><EOL>self._add_choice(entry, alt.member())<EOL><DEDENT>if ctx.lastComma():<EOL><INDENT>entry += <NUM_LIT:1><EOL>self._add_choice(entry, [])<EOL><DEDENT><DEDENT> | membersDef: COMMA | member+ (BAR altMemberDef)* (BAR lastComma)? ;
altMemberDef: member* ;
member: pairDef COMMA?
lastComma: COMMA ; | f15227:c0:m17 |
def visitMember(self, ctx: jsgParser.MemberContext): | self._strict = ctx.COMMA() is None<EOL>self.visitChildren(ctx)<EOL> | member: pairDef COMMA? | f15227:c0:m18 |
def as_python(self, name: str) -> str: | if self._ruleTokens:<EOL><INDENT>pattern = "<STR_LIT>".format(self._rulePattern, '<STR_LIT:U+002CU+0020>'.join(['<STR_LIT>'.format(v=v) for v in sorted(self._ruleTokens)]))<EOL><DEDENT>else:<EOL><INDENT>pattern = "<STR_LIT>".format(self._rulePattern)<EOL><DEDENT>base_type = self._jsontype.signature_type() if self._jsontype else "<STR_LIT>"<EOL>return python_template.format(name=name, base_type=base_type, pattern=pattern)<EOL> | Return the python representation | f15228:c0:m8 |
def visitLexerAltList(self, ctx: jsgParser.LexerAltListContext): | altlist = ctx.lexerAlt()<EOL>self.visit(altlist[<NUM_LIT:0>])<EOL>for alt in altlist[<NUM_LIT:1>:]:<EOL><INDENT>self._rulePattern += '<STR_LIT:|>'<EOL>self.visit(alt)<EOL><DEDENT> | lexerAltList: lexerAlt (LBAR lexerAlt)* | f15228:c0:m10 |
def visitLexerElement(self, ctx: jsgParser.LexerElementContext): | self.visitChildren(ctx)<EOL>if ctx.ebnfSuffix():<EOL><INDENT>self._rulePattern += ctx.ebnfSuffix().getText()<EOL><DEDENT> | lexerElement: lexerAtom ebnfSuffix? | lexerBlock ebnfSuffix? | f15228:c0:m11 |
def visitLexerBlock(self, ctx: jsgParser.LexerBlockContext): | self._rulePattern += '<STR_LIT:(>'<EOL>self.visitChildren(ctx)<EOL>self._rulePattern += '<STR_LIT:)>'<EOL> | lexerBlock: OPREN lexeraltList CPREN | f15228:c0:m12 |
def visitLexerAtom(self, ctx: jsgParser.LexerAtomContext): | if ctx.LEXER_CHAR_SET() or ctx.ANY():<EOL><INDENT>self._rulePattern += str(ctx.getText())<EOL><DEDENT>else:<EOL><INDENT>self.visitChildren(ctx)<EOL><DEDENT> | lexerAtom : lexerTerminal | LEXER_CHAR_SET | ANY | f15228:c0:m13 |
def visitLexerTerminal(self, ctx: jsgParser.LexerTerminalContext): | if ctx.LEXER_ID():<EOL><INDENT>idtoken = as_token(ctx)<EOL>self._rulePattern += '<STR_LIT>' + idtoken + '<STR_LIT>'<EOL>self._ruleTokens.add(idtoken)<EOL><DEDENT>else:<EOL><INDENT>self.add_string(ctx.getText()[<NUM_LIT:1>:-<NUM_LIT:1>], False)<EOL><DEDENT> | terminal: LEXER_ID | STRING | f15228:c0:m14 |
def python_type(self) -> str: | types = []<EOL>if self._lexeridref:<EOL><INDENT>types.append('<STR_LIT:str>')<EOL><DEDENT>if self._typeid:<EOL><INDENT>types.append(self._context.python_type(self._typeid))<EOL><DEDENT>if self._builtintype:<EOL><INDENT>types.append(self._builtintype.python_type())<EOL><DEDENT>if self._alttypelist:<EOL><INDENT>types += [e.python_type() for e in self._alttypelist]<EOL><DEDENT>if self._arrayDef:<EOL><INDENT>types.append(self._arrayDef.python_type())<EOL><DEDENT>return "<STR_LIT>" if len(types) == <NUM_LIT:0> elsetypes[<NUM_LIT:0>] if len(types) == <NUM_LIT:1> else "<STR_LIT>".format('<STR_LIT:U+002CU+0020>'.join(types))<EOL> | Return the official python type for the value. As an example, an '@int' aps to 'int' or a match pattern
maps to 'str' | f15229:c0:m3 |
def signature_type(self) -> str: | types = []<EOL>if self._lexeridref:<EOL><INDENT>types.append(self._lexeridref)<EOL><DEDENT>if self._typeid:<EOL><INDENT>types.append(self._context.signature_type(self._typeid))<EOL><DEDENT>if self._builtintype:<EOL><INDENT>types.append(self._builtintype.signature_type())<EOL><DEDENT>if self._alttypelist:<EOL><INDENT>types += [e.signature_type() for e in self._alttypelist]<EOL><DEDENT>if self._arrayDef:<EOL><INDENT>types.append(self._arrayDef.signature_type())<EOL><DEDENT>return "<STR_LIT>" if len(types) == <NUM_LIT:0> elsetypes[<NUM_LIT:0>] if len(types) == <NUM_LIT:1> else "<STR_LIT>".format('<STR_LIT:U+002CU+0020>'.join(types))<EOL> | Return the signature type for the value. As an example, an '@int' maps to 'Integer' or a match pattern
maps to the name of the JSGString class | f15229:c0:m4 |
def visitValueType(self, ctx: jsgParser.ValueTypeContext): | if ctx.idref():<EOL><INDENT>self._typeid = as_token(ctx)<EOL><DEDENT>else:<EOL><INDENT>self.visitChildren(ctx)<EOL><DEDENT> | valueType: idref | nonRefValueType | f15229:c0:m9 |
def visitNonRefValueType(self, ctx: jsgParser.NonRefValueTypeContext): | if ctx.LEXER_ID_REF(): <EOL><INDENT>self._lexeridref = as_token(ctx)<EOL><DEDENT>elif ctx.STRING(): <EOL><INDENT>from pyjsg.parser_impl.jsg_lexerruleblock_parser import JSGLexerRuleBlock<EOL>lrb = JSGLexerRuleBlock(self._context)<EOL>lrb.add_string(ctx.getText()[<NUM_LIT:1>:-<NUM_LIT:1>], False)<EOL>self._lexeridref = self._context.anon_id()<EOL>self._context.grammarelts[self._lexeridref] = lrb<EOL><DEDENT>else:<EOL><INDENT>self.visitChildren(ctx)<EOL><DEDENT> | nonRefValueType: LEXER_ID_REF | STRING | builtinValueType | objectExpr | arrayExpr
| OPREN typeAlternatives CPREN | ANY | f15229:c0:m10 |
def members_entries(self, all_are_optional: Optional[bool] = False) -> List[Tuple[str, str]]: | if self._type_reference:<EOL><INDENT>rval: List[Tuple[str, str]] = []<EOL>for n, t in self._context.reference(self._type_reference).members_entries(all_are_optional):<EOL><INDENT>rval.append((n, self._ebnf.signature_cardinality(t, all_are_optional).format(name=n)))<EOL><DEDENT>return rval<EOL><DEDENT>else:<EOL><INDENT>sig = self._ebnf.signature_cardinality(self._typ.reference_type(), all_are_optional)<EOL>return [(name, sig.format(name=name)) for name in self._names]<EOL><DEDENT> | Generate a list quoted raw name, signature type entries for this pairdef, recursively traversing
reference types
:param all_are_optional: If true, all types are forced optional
:return: raw name/ signature type for all elements in this pair | f15230:c0:m3 |
def signatures(self, all_are_optional: Optional[bool] = False) -> List[str]: | if self._type_reference:<EOL><INDENT>ref = self._context.reference(self._type_reference)<EOL>if not getattr(ref, '<STR_LIT>', None):<EOL><INDENT>raise NotImplementedError("<STR_LIT>" + self._type_reference + "<STR_LIT>")<EOL><DEDENT>return self._context.reference(self._type_reference).signatures(all_are_optional)<EOL><DEDENT>else:<EOL><INDENT>return [f"<STR_LIT>" <EOL>f"<STR_LIT>" for rn, cn in self._names.items() if is_valid_python(cn)]<EOL><DEDENT> | Return the __init__ signature element(s) (var: type = default value). Note that signatures are not
generated for non-python names, although we do take the liberty of suffixing a '_' for reserved words
(e.g. class: @int generates "class_: int = None"
:param all_are_optional: If True, all items are considered to be optional
:return: List of signatures | f15230:c0:m9 |
def _initializer_for(self, raw_name: str, cooked_name: str, prefix: Optional[str]) -> List[str]: | mt_val = self._ebnf.mt_value(self._typ)<EOL>rval = []<EOL>if is_valid_python(raw_name):<EOL><INDENT>if prefix:<EOL><INDENT>rval.append(f"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>cons = raw_name<EOL>rval.append(f"<STR_LIT>")<EOL><DEDENT><DEDENT>elif is_valid_python(cooked_name):<EOL><INDENT>if prefix:<EOL><INDENT>rval.append(f"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>cons = f"<STR_LIT>"<EOL>rval.append(f"<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>getter = f"<STR_LIT>"<EOL>if prefix:<EOL><INDENT>rval.append(f"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>rval.append(f"<STR_LIT>")<EOL><DEDENT><DEDENT>return rval<EOL> | Create an initializer entry for the entry
:param raw_name: name unadjusted for python compatibility.
:param cooked_name: name that may or may not be python compatible
:param prefix: owner of the element - used when objects passed as arguments
:return: Initialization statements | f15230:c0:m10 |
def initializers(self, prefix: Optional[str] = None) -> List[str]: | if self._type_reference:<EOL><INDENT>ref = self._context.reference(self._type_reference)<EOL>if not getattr(ref, '<STR_LIT>', None):<EOL><INDENT>raise NotImplementedError("<STR_LIT>" + self._type_reference + "<STR_LIT>")<EOL><DEDENT>return self._context.reference(self._type_reference).initializers(prefix)<EOL><DEDENT>else:<EOL><INDENT>return flatten([self._initializer_for(rn, cn, prefix) for rn, cn in self._names.items()])<EOL><DEDENT> | Return the __init__ initializer assignment block | f15230:c0:m11 |
def visitPairDef(self, ctx: jsgParser.PairDefContext): | if ctx.name(): <EOL><INDENT>self.visitChildren(ctx)<EOL><DEDENT>else:<EOL><INDENT>self._type_reference = as_token(ctx)<EOL>if ctx.ebnfSuffix():<EOL><INDENT>self.visit(ctx.ebnfSuffix())<EOL><DEDENT><DEDENT> | pairDef: name COLON valueType ebnfSuffix?
| idref ebnfSuffix?
| OPREN name (BAR? name)+ CPREN COLON valueType ebnfSuffix? | f15230:c0:m13 |
def visitName(self, ctx: jsgParser.NameContext): | rtkn = get_terminal(ctx)<EOL>tkn = esc_kw(rtkn)<EOL>self._names[rtkn] = tkn<EOL> | name: ID | STRING | f15230:c0:m14 |
def as_python(self, infile, include_original_shex: bool=False): | self._context.resolve_circular_references() <EOL>body = '<STR_LIT>'<EOL>for k in self._context.ordered_elements():<EOL><INDENT>v = self._context.grammarelts[k]<EOL>if isinstance(v, (JSGLexerRuleBlock, JSGObjectExpr)):<EOL><INDENT>body += v.as_python(k)<EOL>if isinstance(v, JSGObjectExpr) and not self._context.has_typeid:<EOL><INDENT>self._context.directives.append(f'<STR_LIT>')<EOL><DEDENT><DEDENT>elif isinstance(v, JSGForwardRef):<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(v, (JSGValueType, JSGArrayExpr)):<EOL><INDENT>body += f"<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>".format(k))<EOL><DEDENT>self._context.forward_refs.pop(k, None)<EOL><DEDENT>body = '<STR_LIT:\n>' + '<STR_LIT:\n>'.join(self._context.directives) + body<EOL>return _jsg_python_template.format(infile=infile,<EOL>original_shex='<STR_LIT>' + self.text if include_original_shex else "<STR_LIT>",<EOL>version=__version__,<EOL>gendate=datetime.datetime.now().strftime("<STR_LIT>"),<EOL>body=body)<EOL> | Return the python representation of the document | f15231:c0:m1 |
def undefined_tokens(self) -> List[str]: | return sorted(self._context.undefined_entries())<EOL> | Return a list of undefined tokens
:return: | f15231:c0:m2 |
def visitTypeDirective(self, ctx: jsgParser.TypeDirectiveContext): | self._context.directives.append('<STR_LIT>'.format(as_token(ctx.name())))<EOL>self._context.has_typeid = True<EOL>self.visitChildren(ctx)<EOL> | directive: '.TYPE' name typeExceptions? SEMI | f15231:c0:m4 |
def visitTypeExceptions(self, ctx: jsgParser.TypeExceptionsContext): | for tkn in as_tokens(ctx.idref()):<EOL><INDENT>self._context.directives.append('<STR_LIT>'.format(tkn))<EOL><DEDENT> | typeExceptions: DASH idref+ | f15231:c0:m5 |
def visitIgnoreDirective(self, ctx: jsgParser.IgnoreDirectiveContext): | for name in as_tokens(ctx.name()):<EOL><INDENT>self._context.directives.append('<STR_LIT>'.format(name))<EOL><DEDENT> | directive: '.IGNORE' name* SEMI | f15231:c0:m6 |
def visitObjectDef(self, ctx: jsgParser.ObjectDefContext): | name = as_token(ctx)<EOL>self._context.grammarelts[name] = JSGObjectExpr(self._context, ctx.objectExpr(), name)<EOL> | objectDef: ID objectExpr | f15231:c0:m7 |
def visitArrayDef(self, ctx: jsgParser.ArrayDefContext): | self._context.grammarelts[as_token(ctx)] = JSGArrayExpr(self._context, ctx.arrayExpr())<EOL> | arrayDef : ID arrayExpr | f15231:c0:m8 |
def visitObjectMacro(self, ctx: jsgParser.ObjectExprContext): | name = as_token(ctx)<EOL>self._context.grammarelts[name] = JSGObjectExpr(self._context, ctx.membersDef(), name)<EOL> | objectMacro : ID EQUALS membersDef SEMI | f15231:c0:m9 |
def visitValueTypeMacro(self, ctx: jsgParser.ValueTypeMacroContext): | self._context.grammarelts[as_token(ctx)] = JSGValueType(self._context, ctx)<EOL> | valueTypeMacro : ID EQUALS nonRefValueType (BAR nonRefValueType)* SEMI | f15231:c0:m10 |
def visitLexerRuleSpec(self, ctx: jsgParser.LexerRuleSpecContext): | self._context.grammarelts[as_token(ctx)] = JSGLexerRuleBlock(self._context, ctx.lexerRuleBlock())<EOL> | lexerRuleSpec: LEXER_ID COLON lexerRuleBlock SEMI | f15231:c0:m11 |
def do_parse(infilename: str, outfilename: str, verbose: bool) -> bool: | python = parse(FileStream(infilename, encoding="<STR_LIT:utf-8>"), infilename)<EOL>if python is not None:<EOL><INDENT>with open(outfilename, '<STR_LIT:w>') as outfile:<EOL><INDENT>outfile.write(python)<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>".format(outfilename))<EOL><DEDENT>return True<EOL><DEDENT>return False<EOL> | Parse the jsg in infilename and save the results in outfilename
:param infilename: file containing jsg
:param outfilename: target python file
:param verbose: verbose output flag
:return: true if success | f15232:m0 |
def parse(input_: Union[str, FileStream], source: str) -> Optional[str]: | <EOL>error_listener = ParseErrorListener()<EOL>if not isinstance(input_, FileStream):<EOL><INDENT>input_ = InputStream(input_)<EOL><DEDENT>lexer = jsgLexer(input_)<EOL>lexer.addErrorListener(error_listener)<EOL>tokens = CommonTokenStream(lexer)<EOL>tokens.fill()<EOL>if error_listener.n_errors:<EOL><INDENT>return None<EOL><DEDENT>parser = jsgParser(tokens)<EOL>parser.addErrorListener(error_listener)<EOL>parse_tree = parser.doc()<EOL>if error_listener.n_errors:<EOL><INDENT>return None<EOL><DEDENT>parser = JSGDocParser()<EOL>parser.visit(parse_tree)<EOL>if parser.undefined_tokens():<EOL><INDENT>for tkn in parser.undefined_tokens():<EOL><INDENT>print("<STR_LIT>" + tkn)<EOL><DEDENT>return None<EOL><DEDENT>return parser.as_python(source)<EOL> | Parse the text in infile and save the results in outfile
:param input_: string or stream to parse
:param source: source name for python file header
:return: python text if successful | f15232:m1 |
def genargs() -> ArgumentParser: | parser = ArgumentParser()<EOL>parser.add_argument("<STR_LIT>", help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", help="<STR_LIT>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", help="<STR_LIT>", action="<STR_LIT:store_true>")<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", help="<STR_LIT>", action="<STR_LIT:store_true>")<EOL>return parser<EOL> | Create a command line parser
:return: parser | f15232:m2 |
def evaluate(module_name: str, fname: str, verbose: bool): | if verbose:<EOL><INDENT>print("<STR_LIT>".format(fname))<EOL><DEDENT>spec = importlib.util.spec_from_file_location(module_name, fname)<EOL>mod = importlib.util.module_from_spec(spec)<EOL>spec.loader.exec_module(mod)<EOL> | Load fname as a module. Will raise an exception if there is an error
:param module_name: resulting name of module
:param fname: name to load | f15232:m3 |
def __init__(self, prefix: Optional[str] = None): | self._nextid = <NUM_LIT:0><EOL>self._prefix = prefix if prefix is not None else default_prefix<EOL>self._anon_re = re.compile(r'<STR_LIT>'.format(self._prefix))<EOL> | Create a factory
:param prefix: Prefix - default_prefix if omitted | f15233:c0:m0 |
@property<EOL><INDENT>def one_optional_element(self) -> bool:<DEDENT> | return self.min == <NUM_LIT:0> and self.max == <NUM_LIT:1><EOL> | Return True if exactly one optional element | f15234:c0:m2 |
@property<EOL><INDENT>def multiple_elements(self) -> bool:<DEDENT> | return self.max is None or self.max > <NUM_LIT:1><EOL> | Return True if cardinality is > 1 | f15234:c0:m3 |
def python_cardinality(self, subject: str, all_are_optional: bool = False) -> str: | if self.multiple_elements:<EOL><INDENT>rval = f"<STR_LIT>"<EOL><DEDENT>elif self.one_optional_element:<EOL><INDENT>rval = subject if subject.startswith("<STR_LIT>") else f"<STR_LIT>"<EOL><DEDENT>elif self.max == <NUM_LIT:0>:<EOL><INDENT>rval = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>rval = subject<EOL><DEDENT>if all_are_optional and not self.one_optional_element:<EOL><INDENT>rval = f"<STR_LIT>"<EOL><DEDENT>return rval<EOL> | Add the appropriate python typing to subject (e.g. Optional, List, ...)
:param subject: Subject to be decorated
:param all_are_optional: Force everything to be optional
:return: Typed subject | f15234:c0:m4 |
def signature_cardinality(self, subject: str, all_are_optional: bool = False) -> str: | if self.multiple_elements:<EOL><INDENT>rval = f"<STR_LIT>"<EOL><DEDENT>elif self.one_optional_element:<EOL><INDENT>rval = subject if subject.startswith("<STR_LIT>") else f"<STR_LIT>"<EOL><DEDENT>elif self.max == <NUM_LIT:0>:<EOL><INDENT>rval = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>rval = subject<EOL><DEDENT>if all_are_optional and not self.one_optional_element:<EOL><INDENT>rval = f"<STR_LIT>"<EOL><DEDENT>return rval<EOL> | Add the appropriate python typing to subject (e.g. Optional, List, ...)
:param subject: Subject to be decorated
:param all_are_optional: Force everything to be optional
:return: Typed subject | f15234:c0:m5 |
def visitEbnfSuffix(self, ctx: jsgParser.EbnfSuffixContext): | self._ebnftext = ctx.getText()<EOL>if ctx.INT():<EOL><INDENT>self.min = int(ctx.INT(<NUM_LIT:0>).getText())<EOL>if ctx.COMMA():<EOL><INDENT>if len(ctx.INT()) > <NUM_LIT:1>:<EOL><INDENT>self.max = int(ctx.INT(<NUM_LIT:1>).getText())<EOL><DEDENT>else:<EOL><INDENT>self.max = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.max = self.min<EOL><DEDENT><DEDENT>elif ctx.QMARK():<EOL><INDENT>self.min = <NUM_LIT:0><EOL>self.max = <NUM_LIT:1><EOL><DEDENT>elif ctx.STAR():<EOL><INDENT>self.min = <NUM_LIT:0><EOL>self.max = None<EOL><DEDENT>elif ctx.PLUS():<EOL><INDENT>self.min = <NUM_LIT:1><EOL>self.max = None<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>".format(self._ebnftext))<EOL><DEDENT> | ebnfSuffix: QMARK | STAR | PLUS | OBRACE INT (COMMA (INT|STAR)?)? CBRACE | f15234:c0:m7 |
def __init__(self, host, mac): | self.resource = '<STR_LIT>'.format(host)<EOL>self._mac = mac<EOL>self.timeout = <NUM_LIT:5><EOL>self.data = None<EOL>self.state = None<EOL>self.consumption = <NUM_LIT:0><EOL>self.brightness = <NUM_LIT:0><EOL>self.color = None<EOL>self.firmware = None<EOL>self.mode = None<EOL>self.transition_time = <NUM_LIT:0><EOL> | Initialize the bulb. | f15247:c0:m0 |
def get_status(self): | try:<EOL><INDENT>request = requests.get(<EOL>'<STR_LIT>'.format(self.resource, URI), timeout=self.timeout)<EOL>raw_data = request.json()<EOL>self.data = raw_data[self._mac]<EOL>return self.data<EOL><DEDENT>except (requests.exceptions.ConnectionError, ValueError):<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT> | Get the details from the bulb. | f15247:c0:m1 |
def get_bulb_state(self): | self.get_status()<EOL>try:<EOL><INDENT>self.state = self.data['<STR_LIT>']<EOL><DEDENT>except TypeError:<EOL><INDENT>self.state = False<EOL><DEDENT>return bool(self.state)<EOL> | Get the relay state. | f15247:c0:m2 |
def get_power(self): | self.get_status()<EOL>try:<EOL><INDENT>self.consumption = self.data['<STR_LIT>']<EOL><DEDENT>except TypeError:<EOL><INDENT>self.consumption = <NUM_LIT:0><EOL><DEDENT>return self.consumption<EOL> | Get current power. | f15247:c0:m3 |
def get_firmware(self): | self.get_status()<EOL>try:<EOL><INDENT>self.firmware = self.data['<STR_LIT>']<EOL><DEDENT>except TypeError:<EOL><INDENT>self.firmware = '<STR_LIT>'<EOL><DEDENT>return self.firmware<EOL> | Get the current firmware version. | f15247:c0:m4 |
def get_brightness(self): | self.get_status()<EOL>try:<EOL><INDENT>self.brightness = self.data['<STR_LIT>'].split('<STR_LIT:;>')[-<NUM_LIT:1>]<EOL><DEDENT>except TypeError:<EOL><INDENT>self.brightness = <NUM_LIT:0><EOL><DEDENT>return self.brightness<EOL> | Get current brightness. | f15247:c0:m5 |
def get_transition_time(self): | self.get_status()<EOL>try:<EOL><INDENT>self.transition_time = self.data['<STR_LIT>']<EOL><DEDENT>except TypeError:<EOL><INDENT>self.transition_time = <NUM_LIT:0><EOL><DEDENT>return self.transition_time<EOL> | Get the transition time in ms. | f15247:c0:m6 |
def get_color(self): | self.get_status()<EOL>try:<EOL><INDENT>self.color = self.data['<STR_LIT>']<EOL>self.mode = self.data['<STR_LIT>']<EOL><DEDENT>except TypeError:<EOL><INDENT>self.color = <NUM_LIT:0><EOL>self.mode = '<STR_LIT>'<EOL><DEDENT>return {'<STR_LIT>': self.color, '<STR_LIT>': self.mode}<EOL> | Get current color. | f15247:c0:m7 |
def set_on(self): | try:<EOL><INDENT>request = requests.post(<EOL>'<STR_LIT>'.format(self.resource, URI, self._mac),<EOL>data={'<STR_LIT:action>': '<STR_LIT>'}, timeout=self.timeout)<EOL>if request.status_code == <NUM_LIT:200>:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT> | Turn the bulb on with the previous settings. | f15247:c0:m8 |
def set_color_hex(self, value): | data = {<EOL>'<STR_LIT:action>': '<STR_LIT>',<EOL>'<STR_LIT>': value,<EOL>}<EOL>try:<EOL><INDENT>request = requests.post(<EOL>'<STR_LIT>'.format(self.resource, URI, self._mac),<EOL>json=data, timeout=self.timeout)<EOL>if request.status_code == <NUM_LIT:200>:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT> | Turn the bulb on with the given color as HEX.
white: FF000000
red: 00FF0000
green: 0000FF00
blue: 000000FF | f15247:c0:m9 |
def set_color_hsv(self, hue, saturation, value): | try:<EOL><INDENT>data = "<STR_LIT>".format(hue, saturation, value)<EOL>request = requests.post(<EOL>'<STR_LIT>'.format(self.resource, URI, self._mac),<EOL>data=data, timeout=self.timeout)<EOL>if request.status_code == <NUM_LIT:200>:<EOL><INDENT>self.data['<STR_LIT>'] = True<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT> | Turn the bulb on with the given values as HSV. | f15247:c0:m10 |
def set_white(self): | self.set_color_hsv(<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:100>)<EOL> | Turn the bulb on, full white. | f15247:c0:m11 |
def set_rainbow(self, duration): | for i in range(<NUM_LIT:0>, <NUM_LIT>):<EOL><INDENT>self.set_color_hsv(i, <NUM_LIT:100>, <NUM_LIT:100>)<EOL>time.sleep(duration/<NUM_LIT>)<EOL><DEDENT> | Turn the bulb on and create a rainbow. | f15247:c0:m12 |
def set_sunrise(self, duration): | self.set_transition_time(duration/<NUM_LIT:100>)<EOL>for i in range(<NUM_LIT:0>, duration):<EOL><INDENT>try:<EOL><INDENT>data = "<STR_LIT>".format(i)<EOL>request = requests.post(<EOL>'<STR_LIT>'.format(self.resource, URI, self._mac),<EOL>data=data, timeout=self.timeout)<EOL>if request.status_code == <NUM_LIT:200>:<EOL><INDENT>self.data['<STR_LIT>'] = True<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT>time.sleep(duration/<NUM_LIT:100>)<EOL><DEDENT> | Turn the bulb on and create a sunrise. | f15247:c0:m13 |
def set_flashing(self, duration, hsv1, hsv2): | self.set_transition_time(<NUM_LIT:100>)<EOL>for step in range(<NUM_LIT:0>, int(duration/<NUM_LIT:2>)):<EOL><INDENT>self.set_color_hsv(hsv1[<NUM_LIT:0>], hsv1[<NUM_LIT:1>], hsv1[<NUM_LIT:2>])<EOL>time.sleep(<NUM_LIT:1>)<EOL>self.set_color_hsv(hsv2[<NUM_LIT:0>], hsv2[<NUM_LIT:1>], hsv2[<NUM_LIT:2>])<EOL>time.sleep(<NUM_LIT:1>)<EOL><DEDENT> | Turn the bulb on, flashing with two colors. | f15247:c0:m14 |
def set_transition_time(self, value): | try:<EOL><INDENT>request = requests.post(<EOL>'<STR_LIT>'.format(self.resource, URI, self._mac),<EOL>data={'<STR_LIT>': value}, timeout=self.timeout)<EOL>if request.status_code == <NUM_LIT:200>:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT> | Set the transition time in ms. | f15247:c0:m15 |
def set_off(self): | try:<EOL><INDENT>request = requests.post(<EOL>'<STR_LIT>'.format(self.resource, URI, self._mac),<EOL>data={'<STR_LIT:action>': '<STR_LIT>'}, timeout=self.timeout)<EOL>if request.status_code == <NUM_LIT:200>:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise exceptions.MyStromConnectionError()<EOL><DEDENT> | Turn the bulb off. | f15247:c0:m16 |
@click.group()<EOL>@click.version_option()<EOL>def main(): | Simple command-line tool to get and set the values of a myStrom devices.
This tool can set the targets of a myStrom button for the different
available actions single, double, long and touch. | f15248:m0 | |
@main.group('<STR_LIT>')<EOL>def config(): | Get and set the configuration of a myStrom device. | f15248:m1 | |
@config.command('<STR_LIT>')<EOL>@click.option('<STR_LIT>', prompt="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>@click.option('<STR_LIT>', prompt="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>def read_config(ip, mac): | click.echo("<STR_LIT>" % ip)<EOL>request = requests.get(<EOL>'<STR_LIT>'.format(ip, URI, mac), timeout=TIMEOUT)<EOL>print(request.json())<EOL> | Read the current configuration of a myStrom device. | f15248:m2 |
@main.group('<STR_LIT>')<EOL>def button(): | Get and set details of a myStrom button. | f15248:m3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.