id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
9,000
delph-in/pydelphin
delphin/mrs/simplemrs.py
_serialize_argument
def _serialize_argument(rargname, value, varprops): """Serialize an MRS argument into the SimpleMRS format.""" _argument = '{rargname}: {value}{props}' if rargname == CONSTARG_ROLE: value = '"{}"'.format(value) props = '' if value in varprops: props = ' [ {} ]'.format( ' '.join( [var_sort(value)] + list(map('{0[0]}: {0[1]}'.format, [(k.upper(), v) for k, v in varprops[value]])) ) ) del varprops[value] # only print props once return _argument.format( rargname=rargname, value=str(value), props=props )
python
def _serialize_argument(rargname, value, varprops): _argument = '{rargname}: {value}{props}' if rargname == CONSTARG_ROLE: value = '"{}"'.format(value) props = '' if value in varprops: props = ' [ {} ]'.format( ' '.join( [var_sort(value)] + list(map('{0[0]}: {0[1]}'.format, [(k.upper(), v) for k, v in varprops[value]])) ) ) del varprops[value] # only print props once return _argument.format( rargname=rargname, value=str(value), props=props )
[ "def", "_serialize_argument", "(", "rargname", ",", "value", ",", "varprops", ")", ":", "_argument", "=", "'{rargname}: {value}{props}'", "if", "rargname", "==", "CONSTARG_ROLE", ":", "value", "=", "'\"{}\"'", ".", "format", "(", "value", ")", "props", "=", "'...
Serialize an MRS argument into the SimpleMRS format.
[ "Serialize", "an", "MRS", "argument", "into", "the", "SimpleMRS", "format", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/simplemrs.py#L430-L449
9,001
delph-in/pydelphin
delphin/mrs/simplemrs.py
_serialize_ep
def _serialize_ep(ep, varprops, version=_default_version): """Serialize an Elementary Predication into the SimpleMRS encoding.""" # ('nodeid', 'pred', 'label', 'args', 'lnk', 'surface', 'base') args = ep[3] arglist = ' '.join([_serialize_argument(rarg, args[rarg], varprops) for rarg in sorted(args, key=rargname_sortkey)]) if version < 1.1 or len(ep) < 6 or ep[5] is None: surface = '' else: surface = ' "%s"' % ep[5] lnk = None if len(ep) < 5 else ep[4] pred = ep[1] predstr = pred.string return '[ {pred}{lnk}{surface} LBL: {label}{s}{args} ]'.format( pred=predstr, lnk=_serialize_lnk(lnk), surface=surface, label=str(ep[2]), s=' ' if arglist else '', args=arglist )
python
def _serialize_ep(ep, varprops, version=_default_version): # ('nodeid', 'pred', 'label', 'args', 'lnk', 'surface', 'base') args = ep[3] arglist = ' '.join([_serialize_argument(rarg, args[rarg], varprops) for rarg in sorted(args, key=rargname_sortkey)]) if version < 1.1 or len(ep) < 6 or ep[5] is None: surface = '' else: surface = ' "%s"' % ep[5] lnk = None if len(ep) < 5 else ep[4] pred = ep[1] predstr = pred.string return '[ {pred}{lnk}{surface} LBL: {label}{s}{args} ]'.format( pred=predstr, lnk=_serialize_lnk(lnk), surface=surface, label=str(ep[2]), s=' ' if arglist else '', args=arglist )
[ "def", "_serialize_ep", "(", "ep", ",", "varprops", ",", "version", "=", "_default_version", ")", ":", "# ('nodeid', 'pred', 'label', 'args', 'lnk', 'surface', 'base')", "args", "=", "ep", "[", "3", "]", "arglist", "=", "' '", ".", "join", "(", "[", "_serialize_ar...
Serialize an Elementary Predication into the SimpleMRS encoding.
[ "Serialize", "an", "Elementary", "Predication", "into", "the", "SimpleMRS", "encoding", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/simplemrs.py#L452-L472
9,002
delph-in/pydelphin
delphin/mrs/simplemrs.py
_serialize_lnk
def _serialize_lnk(lnk): """Serialize a predication lnk to surface form into the SimpleMRS encoding.""" s = "" if lnk is not None: s = '<' if lnk.type == Lnk.CHARSPAN: cfrom, cto = lnk.data s += ''.join([str(cfrom), ':', str(cto)]) elif lnk.type == Lnk.CHARTSPAN: cfrom, cto = lnk.data s += ''.join([str(cfrom), '#', str(cto)]) elif lnk.type == Lnk.TOKENS: s += ' '.join([str(t) for t in lnk.data]) elif lnk.type == Lnk.EDGE: s += ''.join(['@', str(lnk.data)]) s += '>' return s
python
def _serialize_lnk(lnk): s = "" if lnk is not None: s = '<' if lnk.type == Lnk.CHARSPAN: cfrom, cto = lnk.data s += ''.join([str(cfrom), ':', str(cto)]) elif lnk.type == Lnk.CHARTSPAN: cfrom, cto = lnk.data s += ''.join([str(cfrom), '#', str(cto)]) elif lnk.type == Lnk.TOKENS: s += ' '.join([str(t) for t in lnk.data]) elif lnk.type == Lnk.EDGE: s += ''.join(['@', str(lnk.data)]) s += '>' return s
[ "def", "_serialize_lnk", "(", "lnk", ")", ":", "s", "=", "\"\"", "if", "lnk", "is", "not", "None", ":", "s", "=", "'<'", "if", "lnk", ".", "type", "==", "Lnk", ".", "CHARSPAN", ":", "cfrom", ",", "cto", "=", "lnk", ".", "data", "s", "+=", "''",...
Serialize a predication lnk to surface form into the SimpleMRS encoding.
[ "Serialize", "a", "predication", "lnk", "to", "surface", "form", "into", "the", "SimpleMRS", "encoding", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/simplemrs.py#L475-L492
9,003
delph-in/pydelphin
delphin/derivation.py
_UdfNodeBase.to_dict
def to_dict(self, fields=_all_fields, labels=None): """ Encode the node as a dictionary suitable for JSON serialization. Args: fields: if given, this is a whitelist of fields to include on nodes (`daughters` and `form` are always shown) labels: optional label annotations to embed in the derivation dict; the value is a list of lists matching the structure of the derivation (e.g., `["S" ["NP" ["NNS" ["Dogs"]]] ["VP" ["VBZ" ["bark"]]]]`) Returns: dict: the dictionary representation of the structure """ fields = set(fields) diff = fields.difference(_all_fields) if isinstance(labels, Sequence): labels = _map_labels(self, labels) elif labels is None: labels = {} if diff: raise ValueError( 'Invalid field(s): {}'.format(', '.join(diff)) ) return _to_dict(self, fields, labels)
python
def to_dict(self, fields=_all_fields, labels=None): fields = set(fields) diff = fields.difference(_all_fields) if isinstance(labels, Sequence): labels = _map_labels(self, labels) elif labels is None: labels = {} if diff: raise ValueError( 'Invalid field(s): {}'.format(', '.join(diff)) ) return _to_dict(self, fields, labels)
[ "def", "to_dict", "(", "self", ",", "fields", "=", "_all_fields", ",", "labels", "=", "None", ")", ":", "fields", "=", "set", "(", "fields", ")", "diff", "=", "fields", ".", "difference", "(", "_all_fields", ")", "if", "isinstance", "(", "labels", ",",...
Encode the node as a dictionary suitable for JSON serialization. Args: fields: if given, this is a whitelist of fields to include on nodes (`daughters` and `form` are always shown) labels: optional label annotations to embed in the derivation dict; the value is a list of lists matching the structure of the derivation (e.g., `["S" ["NP" ["NNS" ["Dogs"]]] ["VP" ["VBZ" ["bark"]]]]`) Returns: dict: the dictionary representation of the structure
[ "Encode", "the", "node", "as", "a", "dictionary", "suitable", "for", "JSON", "serialization", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/derivation.py#L138-L162
9,004
delph-in/pydelphin
delphin/derivation.py
UdfNode.is_head
def is_head(self): """ Return `True` if the node is a head. A node is a head if it is marked as a head in the UDX format or it has no siblings. `False` is returned if the node is known to not be a head (has a sibling that is a head). Otherwise it is indeterminate whether the node is a head, and `None` is returned. """ if (self._head or self.is_root() or len(getattr(self._parent, 'daughters', [None])) == 1): return True elif any(dtr._head for dtr in self._parent.daughters): return False return None
python
def is_head(self): if (self._head or self.is_root() or len(getattr(self._parent, 'daughters', [None])) == 1): return True elif any(dtr._head for dtr in self._parent.daughters): return False return None
[ "def", "is_head", "(", "self", ")", ":", "if", "(", "self", ".", "_head", "or", "self", ".", "is_root", "(", ")", "or", "len", "(", "getattr", "(", "self", ".", "_parent", ",", "'daughters'", ",", "[", "None", "]", ")", ")", "==", "1", ")", ":"...
Return `True` if the node is a head. A node is a head if it is marked as a head in the UDX format or it has no siblings. `False` is returned if the node is known to not be a head (has a sibling that is a head). Otherwise it is indeterminate whether the node is a head, and `None` is returned.
[ "Return", "True", "if", "the", "node", "is", "a", "head", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/derivation.py#L420-L436
9,005
delph-in/pydelphin
delphin/derivation.py
Derivation.from_string
def from_string(cls, s): """ Instantiate a `Derivation` from a UDF or UDX string representation. The UDF/UDX representations are as output by a processor like the `LKB <http://moin.delph-in.net/LkbTop>`_ or `ACE <http://sweaglesw.org/linguistics/ace/>`_, or from the :meth:`UdfNode.to_udf` or :meth:`UdfNode.to_udx` methods. Args: s (str): UDF or UDX serialization """ if not (s.startswith('(') and s.endswith(')')): raise ValueError( 'Derivations must begin and end with parentheses: ( )' ) s_ = s[1:] # get rid of initial open-parenthesis stack = [] deriv = None try: matches = cls.udf_re.finditer(s_) for match in matches: if match.group('done'): node = stack.pop() if len(stack) == 0: deriv = node break else: stack[-1].daughters.append(node) elif match.group('form'): if len(stack) == 0: raise ValueError('Possible leaf node with no parent.') gd = match.groupdict() # ignore LKB-style start/end data if it exists on gd term = UdfTerminal( _unquote(gd['form']), tokens=_udf_tokens(gd.get('tokens')), parent=stack[-1] if stack else None ) stack[-1].daughters.append(term) elif match.group('id'): gd = match.groupdict() head = None entity, _, type = gd['entity'].partition('@') if entity[0] == '^': entity = entity[1:] head = True if type == '': type = None udf = UdfNode(gd['id'], entity, gd['score'], gd['start'], gd['end'], head=head, type=type, parent=stack[-1] if stack else None) stack.append(udf) elif match.group('root'): udf = UdfNode(None, match.group('root')) stack.append(udf) except (ValueError, AttributeError): raise ValueError('Invalid derivation: %s' % s) if stack or deriv is None: raise ValueError('Invalid derivation; possibly unbalanced ' 'parentheses: %s' % s) return cls(*deriv, head=deriv._head, type=deriv.type)
python
def from_string(cls, s): if not (s.startswith('(') and s.endswith(')')): raise ValueError( 'Derivations must begin and end with parentheses: ( )' ) s_ = s[1:] # get rid of initial open-parenthesis stack = [] deriv = None try: matches = cls.udf_re.finditer(s_) for match in matches: if match.group('done'): node = stack.pop() if len(stack) == 0: deriv = node break else: stack[-1].daughters.append(node) elif match.group('form'): if len(stack) == 0: raise ValueError('Possible leaf node with no parent.') gd = match.groupdict() # ignore LKB-style start/end data if it exists on gd term = UdfTerminal( _unquote(gd['form']), tokens=_udf_tokens(gd.get('tokens')), parent=stack[-1] if stack else None ) stack[-1].daughters.append(term) elif match.group('id'): gd = match.groupdict() head = None entity, _, type = gd['entity'].partition('@') if entity[0] == '^': entity = entity[1:] head = True if type == '': type = None udf = UdfNode(gd['id'], entity, gd['score'], gd['start'], gd['end'], head=head, type=type, parent=stack[-1] if stack else None) stack.append(udf) elif match.group('root'): udf = UdfNode(None, match.group('root')) stack.append(udf) except (ValueError, AttributeError): raise ValueError('Invalid derivation: %s' % s) if stack or deriv is None: raise ValueError('Invalid derivation; possibly unbalanced ' 'parentheses: %s' % s) return cls(*deriv, head=deriv._head, type=deriv.type)
[ "def", "from_string", "(", "cls", ",", "s", ")", ":", "if", "not", "(", "s", ".", "startswith", "(", "'('", ")", "and", "s", ".", "endswith", "(", "')'", ")", ")", ":", "raise", "ValueError", "(", "'Derivations must begin and end with parentheses: ( )'", "...
Instantiate a `Derivation` from a UDF or UDX string representation. The UDF/UDX representations are as output by a processor like the `LKB <http://moin.delph-in.net/LkbTop>`_ or `ACE <http://sweaglesw.org/linguistics/ace/>`_, or from the :meth:`UdfNode.to_udf` or :meth:`UdfNode.to_udx` methods. Args: s (str): UDF or UDX serialization
[ "Instantiate", "a", "Derivation", "from", "a", "UDF", "or", "UDX", "string", "representation", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/derivation.py#L549-L611
9,006
delph-in/pydelphin
delphin/mrs/penman.py
loads
def loads(s, model): """ Deserialize PENMAN graphs from a string Args: s (str): serialized PENMAN graphs model: Xmrs subclass instantiated from decoded triples Returns: a list of objects (of class *model*) """ graphs = penman.loads(s, cls=XMRSCodec) xs = [model.from_triples(g.triples()) for g in graphs] return xs
python
def loads(s, model): graphs = penman.loads(s, cls=XMRSCodec) xs = [model.from_triples(g.triples()) for g in graphs] return xs
[ "def", "loads", "(", "s", ",", "model", ")", ":", "graphs", "=", "penman", ".", "loads", "(", "s", ",", "cls", "=", "XMRSCodec", ")", "xs", "=", "[", "model", ".", "from_triples", "(", "g", ".", "triples", "(", ")", ")", "for", "g", "in", "grap...
Deserialize PENMAN graphs from a string Args: s (str): serialized PENMAN graphs model: Xmrs subclass instantiated from decoded triples Returns: a list of objects (of class *model*)
[ "Deserialize", "PENMAN", "graphs", "from", "a", "string" ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/penman.py#L44-L56
9,007
luckydonald/pytgbot
code_generation/code_generator_online.py
calc_path_and_create_folders
def calc_path_and_create_folders(folder, import_path): """ calculate the path and create the needed folders """ file_path = abspath(path_join(folder, import_path[:import_path.rfind(".")].replace(".", folder_seperator) + ".py")) mkdir_p(dirname(file_path)) return file_path
python
def calc_path_and_create_folders(folder, import_path): file_path = abspath(path_join(folder, import_path[:import_path.rfind(".")].replace(".", folder_seperator) + ".py")) mkdir_p(dirname(file_path)) return file_path
[ "def", "calc_path_and_create_folders", "(", "folder", ",", "import_path", ")", ":", "file_path", "=", "abspath", "(", "path_join", "(", "folder", ",", "import_path", "[", ":", "import_path", ".", "rfind", "(", "\".\"", ")", "]", ".", "replace", "(", "\".\"",...
calculate the path and create the needed folders
[ "calculate", "the", "path", "and", "create", "the", "needed", "folders" ]
67f4b5a1510d4583d40b5477e876b1ef0eb8971b
https://github.com/luckydonald/pytgbot/blob/67f4b5a1510d4583d40b5477e876b1ef0eb8971b/code_generation/code_generator_online.py#L508-L512
9,008
delph-in/pydelphin
delphin/tdl.py
_peek
def _peek(tokens, n=0): """peek and drop comments""" return tokens.peek(n=n, skip=_is_comment, drop=True)
python
def _peek(tokens, n=0): return tokens.peek(n=n, skip=_is_comment, drop=True)
[ "def", "_peek", "(", "tokens", ",", "n", "=", "0", ")", ":", "return", "tokens", ".", "peek", "(", "n", "=", "n", ",", "skip", "=", "_is_comment", ",", "drop", "=", "True", ")" ]
peek and drop comments
[ "peek", "and", "drop", "comments" ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L1043-L1045
9,009
delph-in/pydelphin
delphin/tdl.py
_shift
def _shift(tokens): """pop the next token, then peek the gid of the following""" after = tokens.peek(n=1, skip=_is_comment, drop=True) tok = tokens._buffer.popleft() return tok[0], tok[1], tok[2], after[0]
python
def _shift(tokens): after = tokens.peek(n=1, skip=_is_comment, drop=True) tok = tokens._buffer.popleft() return tok[0], tok[1], tok[2], after[0]
[ "def", "_shift", "(", "tokens", ")", ":", "after", "=", "tokens", ".", "peek", "(", "n", "=", "1", ",", "skip", "=", "_is_comment", ",", "drop", "=", "True", ")", "tok", "=", "tokens", ".", "_buffer", ".", "popleft", "(", ")", "return", "tok", "[...
pop the next token, then peek the gid of the following
[ "pop", "the", "next", "token", "then", "peek", "the", "gid", "of", "the", "following" ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L1053-L1057
9,010
delph-in/pydelphin
delphin/tdl.py
_accumulate
def _accumulate(lexitems): """ Yield lists of tokens based on very simple parsing that checks the level of nesting within a structure. This is probably much faster than the LookaheadIterator method, but it is less safe; an unclosed list or AVM may cause it to build a list including the rest of the file, or it may return a list that doesn't span a full definition. As PyDelphin's goals for TDL parsing do not include speed, this method is not currently used, although it is retained in the source code as an example if future priorities change. """ data = [] stack = [] break_on = 10 in_def = False for item in lexitems: gid = item[0] # only yield comments outside of definitions if gid in (2, 3): if len(data) == 0: yield [item] else: continue elif gid == 20: assert len(data) == 0 yield [item] # the following just checks if the previous definition was not # terminated when the next one is read in elif gid in (7, 8): if in_def: yield data[:-1] data = data[-1:] + [item] stack = [] break_on = 10 else: data.append(item) in_def = True else: data.append(item) if gid == break_on: if len(stack) == 0: yield data data = [] in_def = False else: break_on = stack.pop() elif gid in (13, 14, 15): stack.append(break_on) break_on = gid + 3 if data: yield data
python
def _accumulate(lexitems): data = [] stack = [] break_on = 10 in_def = False for item in lexitems: gid = item[0] # only yield comments outside of definitions if gid in (2, 3): if len(data) == 0: yield [item] else: continue elif gid == 20: assert len(data) == 0 yield [item] # the following just checks if the previous definition was not # terminated when the next one is read in elif gid in (7, 8): if in_def: yield data[:-1] data = data[-1:] + [item] stack = [] break_on = 10 else: data.append(item) in_def = True else: data.append(item) if gid == break_on: if len(stack) == 0: yield data data = [] in_def = False else: break_on = stack.pop() elif gid in (13, 14, 15): stack.append(break_on) break_on = gid + 3 if data: yield data
[ "def", "_accumulate", "(", "lexitems", ")", ":", "data", "=", "[", "]", "stack", "=", "[", "]", "break_on", "=", "10", "in_def", "=", "False", "for", "item", "in", "lexitems", ":", "gid", "=", "item", "[", "0", "]", "# only yield comments outside of defi...
Yield lists of tokens based on very simple parsing that checks the level of nesting within a structure. This is probably much faster than the LookaheadIterator method, but it is less safe; an unclosed list or AVM may cause it to build a list including the rest of the file, or it may return a list that doesn't span a full definition. As PyDelphin's goals for TDL parsing do not include speed, this method is not currently used, although it is retained in the source code as an example if future priorities change.
[ "Yield", "lists", "of", "tokens", "based", "on", "very", "simple", "parsing", "that", "checks", "the", "level", "of", "nesting", "within", "a", "structure", ".", "This", "is", "probably", "much", "faster", "than", "the", "LookaheadIterator", "method", "but", ...
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L1060-L1111
9,011
delph-in/pydelphin
delphin/tdl.py
_lex
def _lex(stream): """ Lex the input stream according to _tdl_lex_re. Yields (gid, token, line_number) """ lines = enumerate(stream, 1) line_no = pos = 0 try: while True: if pos == 0: line_no, line = next(lines) matches = _tdl_lex_re.finditer(line, pos) pos = 0 # reset; only used for multiline patterns for m in matches: gid = m.lastindex if gid <= 2: # potentially multiline patterns if gid == 1: # docstring s, start_line_no, line_no, line, pos = _bounded( '"""', '"""', line, m.end(), line_no, lines) elif gid == 2: # comment s, start_line_no, line_no, line, pos = _bounded( '#|', '|#', line, m.end(), line_no, lines) yield (gid, s, line_no) break elif gid == 30: raise TdlParsingError( ('Syntax error:\n {}\n {}^' .format(line, ' ' * m.start())), line_number=line_no) else: # token = None # if not (6 < gid < 20): # token = m.group(gid) token = m.group(gid) yield (gid, token, line_no) except StopIteration: pass
python
def _lex(stream): lines = enumerate(stream, 1) line_no = pos = 0 try: while True: if pos == 0: line_no, line = next(lines) matches = _tdl_lex_re.finditer(line, pos) pos = 0 # reset; only used for multiline patterns for m in matches: gid = m.lastindex if gid <= 2: # potentially multiline patterns if gid == 1: # docstring s, start_line_no, line_no, line, pos = _bounded( '"""', '"""', line, m.end(), line_no, lines) elif gid == 2: # comment s, start_line_no, line_no, line, pos = _bounded( '#|', '|#', line, m.end(), line_no, lines) yield (gid, s, line_no) break elif gid == 30: raise TdlParsingError( ('Syntax error:\n {}\n {}^' .format(line, ' ' * m.start())), line_number=line_no) else: # token = None # if not (6 < gid < 20): # token = m.group(gid) token = m.group(gid) yield (gid, token, line_no) except StopIteration: pass
[ "def", "_lex", "(", "stream", ")", ":", "lines", "=", "enumerate", "(", "stream", ",", "1", ")", "line_no", "=", "pos", "=", "0", "try", ":", "while", "True", ":", "if", "pos", "==", "0", ":", "line_no", ",", "line", "=", "next", "(", "lines", ...
Lex the input stream according to _tdl_lex_re. Yields (gid, token, line_number)
[ "Lex", "the", "input", "stream", "according", "to", "_tdl_lex_re", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L1114-L1152
9,012
delph-in/pydelphin
delphin/tdl.py
format
def format(obj, indent=0): """ Serialize TDL objects to strings. Args: obj: instance of :class:`Term`, :class:`Conjunction`, or :class:`TypeDefinition` classes or subclasses indent (int): number of spaces to indent the formatted object Returns: str: serialized form of *obj* Example: >>> conj = tdl.Conjunction([ ... tdl.TypeIdentifier('lex-item'), ... tdl.AVM([('SYNSEM.LOCAL.CAT.HEAD.MOD', ... tdl.ConsList(end=tdl.EMPTY_LIST_TYPE))]) ... ]) >>> t = tdl.TypeDefinition('non-mod-lex-item', conj) >>> print(format(t)) non-mod-lex-item := lex-item & [ SYNSEM.LOCAL.CAT.HEAD.MOD < > ]. """ if isinstance(obj, TypeDefinition): return _format_typedef(obj, indent) elif isinstance(obj, Conjunction): return _format_conjunction(obj, indent) elif isinstance(obj, Term): return _format_term(obj, indent) elif isinstance(obj, _MorphSet): return _format_morphset(obj, indent) elif isinstance(obj, _Environment): return _format_environment(obj, indent) elif isinstance(obj, FileInclude): return _format_include(obj, indent) else: raise ValueError('cannot format object as TDL: {!r}'.format(obj))
python
def format(obj, indent=0): if isinstance(obj, TypeDefinition): return _format_typedef(obj, indent) elif isinstance(obj, Conjunction): return _format_conjunction(obj, indent) elif isinstance(obj, Term): return _format_term(obj, indent) elif isinstance(obj, _MorphSet): return _format_morphset(obj, indent) elif isinstance(obj, _Environment): return _format_environment(obj, indent) elif isinstance(obj, FileInclude): return _format_include(obj, indent) else: raise ValueError('cannot format object as TDL: {!r}'.format(obj))
[ "def", "format", "(", "obj", ",", "indent", "=", "0", ")", ":", "if", "isinstance", "(", "obj", ",", "TypeDefinition", ")", ":", "return", "_format_typedef", "(", "obj", ",", "indent", ")", "elif", "isinstance", "(", "obj", ",", "Conjunction", ")", ":"...
Serialize TDL objects to strings. Args: obj: instance of :class:`Term`, :class:`Conjunction`, or :class:`TypeDefinition` classes or subclasses indent (int): number of spaces to indent the formatted object Returns: str: serialized form of *obj* Example: >>> conj = tdl.Conjunction([ ... tdl.TypeIdentifier('lex-item'), ... tdl.AVM([('SYNSEM.LOCAL.CAT.HEAD.MOD', ... tdl.ConsList(end=tdl.EMPTY_LIST_TYPE))]) ... ]) >>> t = tdl.TypeDefinition('non-mod-lex-item', conj) >>> print(format(t)) non-mod-lex-item := lex-item & [ SYNSEM.LOCAL.CAT.HEAD.MOD < > ].
[ "Serialize", "TDL", "objects", "to", "strings", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L1872-L1906
9,013
delph-in/pydelphin
delphin/tdl.py
AVM.normalize
def normalize(self): """ Reduce trivial AVM conjunctions to just the AVM. For example, in `[ ATTR1 [ ATTR2 val ] ]` the value of `ATTR1` could be a conjunction with the sub-AVM `[ ATTR2 val ]`. This method removes the conjunction so the sub-AVM nests directly (equivalent to `[ ATTR1.ATTR2 val ]` in TDL). """ for attr in self._avm: val = self._avm[attr] if isinstance(val, Conjunction): val.normalize() if len(val.terms) == 1 and isinstance(val.terms[0], AVM): self._avm[attr] = val.terms[0] elif isinstance(val, AVM): val.normalize()
python
def normalize(self): for attr in self._avm: val = self._avm[attr] if isinstance(val, Conjunction): val.normalize() if len(val.terms) == 1 and isinstance(val.terms[0], AVM): self._avm[attr] = val.terms[0] elif isinstance(val, AVM): val.normalize()
[ "def", "normalize", "(", "self", ")", ":", "for", "attr", "in", "self", ".", "_avm", ":", "val", "=", "self", ".", "_avm", "[", "attr", "]", "if", "isinstance", "(", "val", ",", "Conjunction", ")", ":", "val", ".", "normalize", "(", ")", "if", "l...
Reduce trivial AVM conjunctions to just the AVM. For example, in `[ ATTR1 [ ATTR2 val ] ]` the value of `ATTR1` could be a conjunction with the sub-AVM `[ ATTR2 val ]`. This method removes the conjunction so the sub-AVM nests directly (equivalent to `[ ATTR1.ATTR2 val ]` in TDL).
[ "Reduce", "trivial", "AVM", "conjunctions", "to", "just", "the", "AVM", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L230-L246
9,014
delph-in/pydelphin
delphin/tdl.py
ConsList.values
def values(self): """ Return the list of values in the ConsList feature structure. """ if self._avm is None: return [] else: vals = [val for _, val in _collect_list_items(self)] # the < a . b > notation puts b on the last REST path, # which is not returned by _collect_list_items() if self.terminated and self[self._last_path] is not None: vals.append(self[self._last_path]) return vals
python
def values(self): if self._avm is None: return [] else: vals = [val for _, val in _collect_list_items(self)] # the < a . b > notation puts b on the last REST path, # which is not returned by _collect_list_items() if self.terminated and self[self._last_path] is not None: vals.append(self[self._last_path]) return vals
[ "def", "values", "(", "self", ")", ":", "if", "self", ".", "_avm", "is", "None", ":", "return", "[", "]", "else", ":", "vals", "=", "[", "val", "for", "_", ",", "val", "in", "_collect_list_items", "(", "self", ")", "]", "# the < a . b > notation puts b...
Return the list of values in the ConsList feature structure.
[ "Return", "the", "list", "of", "values", "in", "the", "ConsList", "feature", "structure", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L327-L339
9,015
delph-in/pydelphin
delphin/tdl.py
ConsList.append
def append(self, value): """ Append an item to the end of an open ConsList. Args: value (:class:`Conjunction`, :class:`Term`): item to add Raises: :class:`TdlError`: when appending to a closed list """ if self._avm is not None and not self.terminated: path = self._last_path if path: path += '.' self[path + LIST_HEAD] = value self._last_path = path + LIST_TAIL self[self._last_path] = AVM() else: raise TdlError('Cannot append to a closed list.')
python
def append(self, value): if self._avm is not None and not self.terminated: path = self._last_path if path: path += '.' self[path + LIST_HEAD] = value self._last_path = path + LIST_TAIL self[self._last_path] = AVM() else: raise TdlError('Cannot append to a closed list.')
[ "def", "append", "(", "self", ",", "value", ")", ":", "if", "self", ".", "_avm", "is", "not", "None", "and", "not", "self", ".", "terminated", ":", "path", "=", "self", ".", "_last_path", "if", "path", ":", "path", "+=", "'.'", "self", "[", "path",...
Append an item to the end of an open ConsList. Args: value (:class:`Conjunction`, :class:`Term`): item to add Raises: :class:`TdlError`: when appending to a closed list
[ "Append", "an", "item", "to", "the", "end", "of", "an", "open", "ConsList", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L341-L358
9,016
delph-in/pydelphin
delphin/tdl.py
ConsList.terminate
def terminate(self, end): """ Set the value of the tail of the list. Adding values via :meth:`append` places them on the `FIRST` feature of some level of the feature structure (e.g., `REST.FIRST`), while :meth:`terminate` places them on the final `REST` feature (e.g., `REST.REST`). If *end* is a :class:`Conjunction` or :class:`Term`, it is typically a :class:`Coreference`, otherwise *end* is set to `tdl.EMPTY_LIST_TYPE` or `tdl.LIST_TYPE`. This method does not necessarily close the list; if *end* is `tdl.LIST_TYPE`, the list is left open, otherwise it is closed. Args: end (str, :class:`Conjunction`, :class:`Term`): value to use as the end of the list. """ if self.terminated: raise TdlError('Cannot terminate a closed list.') if end == LIST_TYPE: self.terminated = False elif end == EMPTY_LIST_TYPE: if self._last_path: self[self._last_path] = None else: self._avm = None self.terminated = True elif self._last_path: self[self._last_path] = end self.terminated = True else: raise TdlError('Empty list must be {} or {}'.format( LIST_TYPE, EMPTY_LIST_TYPE))
python
def terminate(self, end): if self.terminated: raise TdlError('Cannot terminate a closed list.') if end == LIST_TYPE: self.terminated = False elif end == EMPTY_LIST_TYPE: if self._last_path: self[self._last_path] = None else: self._avm = None self.terminated = True elif self._last_path: self[self._last_path] = end self.terminated = True else: raise TdlError('Empty list must be {} or {}'.format( LIST_TYPE, EMPTY_LIST_TYPE))
[ "def", "terminate", "(", "self", ",", "end", ")", ":", "if", "self", ".", "terminated", ":", "raise", "TdlError", "(", "'Cannot terminate a closed list.'", ")", "if", "end", "==", "LIST_TYPE", ":", "self", ".", "terminated", "=", "False", "elif", "end", "=...
Set the value of the tail of the list. Adding values via :meth:`append` places them on the `FIRST` feature of some level of the feature structure (e.g., `REST.FIRST`), while :meth:`terminate` places them on the final `REST` feature (e.g., `REST.REST`). If *end* is a :class:`Conjunction` or :class:`Term`, it is typically a :class:`Coreference`, otherwise *end* is set to `tdl.EMPTY_LIST_TYPE` or `tdl.LIST_TYPE`. This method does not necessarily close the list; if *end* is `tdl.LIST_TYPE`, the list is left open, otherwise it is closed. Args: end (str, :class:`Conjunction`, :class:`Term`): value to use as the end of the list.
[ "Set", "the", "value", "of", "the", "tail", "of", "the", "list", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L360-L393
9,017
delph-in/pydelphin
delphin/tdl.py
Conjunction.normalize
def normalize(self): """ Rearrange the conjunction to a conventional form. This puts any coreference(s) first, followed by type terms, then followed by AVM(s) (including lists). AVMs are normalized via :meth:`AVM.normalize`. """ corefs = [] types = [] avms = [] for term in self._terms: if isinstance(term, TypeTerm): types.append(term) elif isinstance(term, AVM): term.normalize() avms.append(term) elif isinstance(term, Coreference): corefs.append(term) else: raise TdlError('unexpected term {}'.format(term)) self._terms = corefs + types + avms
python
def normalize(self): corefs = [] types = [] avms = [] for term in self._terms: if isinstance(term, TypeTerm): types.append(term) elif isinstance(term, AVM): term.normalize() avms.append(term) elif isinstance(term, Coreference): corefs.append(term) else: raise TdlError('unexpected term {}'.format(term)) self._terms = corefs + types + avms
[ "def", "normalize", "(", "self", ")", ":", "corefs", "=", "[", "]", "types", "=", "[", "]", "avms", "=", "[", "]", "for", "term", "in", "self", ".", "_terms", ":", "if", "isinstance", "(", "term", ",", "TypeTerm", ")", ":", "types", ".", "append"...
Rearrange the conjunction to a conventional form. This puts any coreference(s) first, followed by type terms, then followed by AVM(s) (including lists). AVMs are normalized via :meth:`AVM.normalize`.
[ "Rearrange", "the", "conjunction", "to", "a", "conventional", "form", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L547-L568
9,018
delph-in/pydelphin
delphin/tdl.py
Conjunction.add
def add(self, term): """ Add a term to the conjunction. Args: term (:class:`Term`, :class:`Conjunction`): term to add; if a :class:`Conjunction`, all of its terms are added to the current conjunction. Raises: :class:`TypeError`: when *term* is an invalid type """ if isinstance(term, Conjunction): for term_ in term.terms: self.add(term_) elif isinstance(term, Term): self._terms.append(term) else: raise TypeError('Not a Term or Conjunction')
python
def add(self, term): if isinstance(term, Conjunction): for term_ in term.terms: self.add(term_) elif isinstance(term, Term): self._terms.append(term) else: raise TypeError('Not a Term or Conjunction')
[ "def", "add", "(", "self", ",", "term", ")", ":", "if", "isinstance", "(", "term", ",", "Conjunction", ")", ":", "for", "term_", "in", "term", ".", "terms", ":", "self", ".", "add", "(", "term_", ")", "elif", "isinstance", "(", "term", ",", "Term",...
Add a term to the conjunction. Args: term (:class:`Term`, :class:`Conjunction`): term to add; if a :class:`Conjunction`, all of its terms are added to the current conjunction. Raises: :class:`TypeError`: when *term* is an invalid type
[ "Add", "a", "term", "to", "the", "conjunction", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L575-L592
9,019
delph-in/pydelphin
delphin/tdl.py
Conjunction.types
def types(self): """Return the list of type terms in the conjunction.""" return [term for term in self._terms if isinstance(term, (TypeIdentifier, String, Regex))]
python
def types(self): return [term for term in self._terms if isinstance(term, (TypeIdentifier, String, Regex))]
[ "def", "types", "(", "self", ")", ":", "return", "[", "term", "for", "term", "in", "self", ".", "_terms", "if", "isinstance", "(", "term", ",", "(", "TypeIdentifier", ",", "String", ",", "Regex", ")", ")", "]" ]
Return the list of type terms in the conjunction.
[ "Return", "the", "list", "of", "type", "terms", "in", "the", "conjunction", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L594-L597
9,020
delph-in/pydelphin
delphin/tdl.py
Conjunction.features
def features(self, expand=False): """Return the list of feature-value pairs in the conjunction.""" featvals = [] for term in self._terms: if isinstance(term, AVM): featvals.extend(term.features(expand=expand)) return featvals
python
def features(self, expand=False): featvals = [] for term in self._terms: if isinstance(term, AVM): featvals.extend(term.features(expand=expand)) return featvals
[ "def", "features", "(", "self", ",", "expand", "=", "False", ")", ":", "featvals", "=", "[", "]", "for", "term", "in", "self", ".", "_terms", ":", "if", "isinstance", "(", "term", ",", "AVM", ")", ":", "featvals", ".", "extend", "(", "term", ".", ...
Return the list of feature-value pairs in the conjunction.
[ "Return", "the", "list", "of", "feature", "-", "value", "pairs", "in", "the", "conjunction", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L599-L605
9,021
delph-in/pydelphin
delphin/tdl.py
Conjunction.string
def string(self): """ Return the first string term in the conjunction, or `None`. """ for term in self._terms: if isinstance(term, String): return str(term) return None
python
def string(self): for term in self._terms: if isinstance(term, String): return str(term) return None
[ "def", "string", "(", "self", ")", ":", "for", "term", "in", "self", ".", "_terms", ":", "if", "isinstance", "(", "term", ",", "String", ")", ":", "return", "str", "(", "term", ")", "return", "None" ]
Return the first string term in the conjunction, or `None`.
[ "Return", "the", "first", "string", "term", "in", "the", "conjunction", "or", "None", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L607-L614
9,022
delph-in/pydelphin
delphin/tdl.py
TypeDefinition.documentation
def documentation(self, level='first'): """ Return the documentation of the type. By default, this is the first docstring on a top-level term. By setting *level* to `"top"`, the list of all docstrings on top-level terms is returned, including the type's `docstring` value, if not `None`, as the last item. The docstring for the type itself is available via :attr:`TypeDefinition.docstring`. Args: level (str): `"first"` or `"top"` Returns: a single docstring or a list of docstrings """ docs = (t.docstring for t in list(self.conjunction.terms) + [self] if t.docstring is not None) if level.lower() == 'first': doc = next(docs, None) elif level.lower() == 'top': doc = list(docs) return doc
python
def documentation(self, level='first'): docs = (t.docstring for t in list(self.conjunction.terms) + [self] if t.docstring is not None) if level.lower() == 'first': doc = next(docs, None) elif level.lower() == 'top': doc = list(docs) return doc
[ "def", "documentation", "(", "self", ",", "level", "=", "'first'", ")", ":", "docs", "=", "(", "t", ".", "docstring", "for", "t", "in", "list", "(", "self", ".", "conjunction", ".", "terms", ")", "+", "[", "self", "]", "if", "t", ".", "docstring", ...
Return the documentation of the type. By default, this is the first docstring on a top-level term. By setting *level* to `"top"`, the list of all docstrings on top-level terms is returned, including the type's `docstring` value, if not `None`, as the last item. The docstring for the type itself is available via :attr:`TypeDefinition.docstring`. Args: level (str): `"first"` or `"top"` Returns: a single docstring or a list of docstrings
[ "Return", "the", "documentation", "of", "the", "type", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L668-L690
9,023
delph-in/pydelphin
delphin/tdl.py
TdlDefinition.local_constraints
def local_constraints(self): """ Return the constraints defined in the local AVM. """ cs = [] for feat, val in self._avm.items(): try: if val.supertypes and not val._avm: cs.append((feat, val)) else: for subfeat, subval in val.features(): cs.append(('{}.{}'.format(feat, subfeat), subval)) except AttributeError: cs.append((feat, val)) return cs
python
def local_constraints(self): cs = [] for feat, val in self._avm.items(): try: if val.supertypes and not val._avm: cs.append((feat, val)) else: for subfeat, subval in val.features(): cs.append(('{}.{}'.format(feat, subfeat), subval)) except AttributeError: cs.append((feat, val)) return cs
[ "def", "local_constraints", "(", "self", ")", ":", "cs", "=", "[", "]", "for", "feat", ",", "val", "in", "self", ".", "_avm", ".", "items", "(", ")", ":", "try", ":", "if", "val", ".", "supertypes", "and", "not", "val", ".", "_avm", ":", "cs", ...
Return the constraints defined in the local AVM.
[ "Return", "the", "constraints", "defined", "in", "the", "local", "AVM", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L876-L890
9,024
delph-in/pydelphin
delphin/tdl.py
TdlConsList.values
def values(self): """ Return the list of values. """ def collect(d): if d is None or d.get('FIRST') is None: return [] vals = [d['FIRST']] vals.extend(collect(d.get('REST'))) return vals return collect(self)
python
def values(self): def collect(d): if d is None or d.get('FIRST') is None: return [] vals = [d['FIRST']] vals.extend(collect(d.get('REST'))) return vals return collect(self)
[ "def", "values", "(", "self", ")", ":", "def", "collect", "(", "d", ")", ":", "if", "d", "is", "None", "or", "d", ".", "get", "(", "'FIRST'", ")", "is", "None", ":", "return", "[", "]", "vals", "=", "[", "d", "[", "'FIRST'", "]", "]", "vals",...
Return the list of values.
[ "Return", "the", "list", "of", "values", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/tdl.py#L905-L915
9,025
delph-in/pydelphin
delphin/mrs/semi.py
Variable.from_dict
def from_dict(cls, d): """Instantiate a Variable from a dictionary representation.""" return cls( d['type'], tuple(d['parents']), list(d['properties'].items()) )
python
def from_dict(cls, d): return cls( d['type'], tuple(d['parents']), list(d['properties'].items()) )
[ "def", "from_dict", "(", "cls", ",", "d", ")", ":", "return", "cls", "(", "d", "[", "'type'", "]", ",", "tuple", "(", "d", "[", "'parents'", "]", ")", ",", "list", "(", "d", "[", "'properties'", "]", ".", "items", "(", ")", ")", ")" ]
Instantiate a Variable from a dictionary representation.
[ "Instantiate", "a", "Variable", "from", "a", "dictionary", "representation", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L77-L81
9,026
delph-in/pydelphin
delphin/mrs/semi.py
Role.from_dict
def from_dict(cls, d): """Instantiate a Role from a dictionary representation.""" return cls( d['rargname'], d['value'], list(d.get('properties', {}).items()), d.get('optional', False) )
python
def from_dict(cls, d): return cls( d['rargname'], d['value'], list(d.get('properties', {}).items()), d.get('optional', False) )
[ "def", "from_dict", "(", "cls", ",", "d", ")", ":", "return", "cls", "(", "d", "[", "'rargname'", "]", ",", "d", "[", "'value'", "]", ",", "list", "(", "d", ".", "get", "(", "'properties'", ",", "{", "}", ")", ".", "items", "(", ")", ")", ","...
Instantiate a Role from a dictionary representation.
[ "Instantiate", "a", "Role", "from", "a", "dictionary", "representation", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L107-L114
9,027
delph-in/pydelphin
delphin/mrs/semi.py
Role.to_dict
def to_dict(self): """Return a dictionary representation of the Role.""" d = {'rargname': self.rargname, 'value': self.value} if self.properties: d['properties'] = self.properties if self.optional: d['optional'] = self.optional return d
python
def to_dict(self): d = {'rargname': self.rargname, 'value': self.value} if self.properties: d['properties'] = self.properties if self.optional: d['optional'] = self.optional return d
[ "def", "to_dict", "(", "self", ")", ":", "d", "=", "{", "'rargname'", ":", "self", ".", "rargname", ",", "'value'", ":", "self", ".", "value", "}", "if", "self", ".", "properties", ":", "d", "[", "'properties'", "]", "=", "self", ".", "properties", ...
Return a dictionary representation of the Role.
[ "Return", "a", "dictionary", "representation", "of", "the", "Role", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L116-L123
9,028
delph-in/pydelphin
delphin/mrs/semi.py
Predicate.from_dict
def from_dict(cls, d): """Instantiate a Predicate from a dictionary representation.""" synopses = [tuple(map(Role.from_dict, synopsis)) for synopsis in d.get('synopses', [])] return cls(d['predicate'], tuple(d['parents']), synopses)
python
def from_dict(cls, d): synopses = [tuple(map(Role.from_dict, synopsis)) for synopsis in d.get('synopses', [])] return cls(d['predicate'], tuple(d['parents']), synopses)
[ "def", "from_dict", "(", "cls", ",", "d", ")", ":", "synopses", "=", "[", "tuple", "(", "map", "(", "Role", ".", "from_dict", ",", "synopsis", ")", ")", "for", "synopsis", "in", "d", ".", "get", "(", "'synopses'", ",", "[", "]", ")", "]", "return...
Instantiate a Predicate from a dictionary representation.
[ "Instantiate", "a", "Predicate", "from", "a", "dictionary", "representation", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L144-L148
9,029
delph-in/pydelphin
delphin/mrs/semi.py
Predicate.to_dict
def to_dict(self): """Return a dictionary representation of the Predicate.""" return { 'predicate': self.predicate, 'parents': list(self.supertypes), 'synopses': [[role.to_dict() for role in synopsis] for synopsis in self.synopses] }
python
def to_dict(self): return { 'predicate': self.predicate, 'parents': list(self.supertypes), 'synopses': [[role.to_dict() for role in synopsis] for synopsis in self.synopses] }
[ "def", "to_dict", "(", "self", ")", ":", "return", "{", "'predicate'", ":", "self", ".", "predicate", ",", "'parents'", ":", "list", "(", "self", ".", "supertypes", ")", ",", "'synopses'", ":", "[", "[", "role", ".", "to_dict", "(", ")", "for", "role...
Return a dictionary representation of the Predicate.
[ "Return", "a", "dictionary", "representation", "of", "the", "Predicate", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L150-L157
9,030
delph-in/pydelphin
delphin/mrs/semi.py
SemI.from_dict
def from_dict(cls, d): """Instantiate a SemI from a dictionary representation.""" read = lambda cls: (lambda pair: (pair[0], cls.from_dict(pair[1]))) return cls( variables=map(read(Variable), d.get('variables', {}).items()), properties=map(read(Property), d.get('properties', {}).items()), roles=map(read(Role), d.get('roles', {}).items()), predicates=map(read(Predicate), d.get('predicates', {}).items()) )
python
def from_dict(cls, d): read = lambda cls: (lambda pair: (pair[0], cls.from_dict(pair[1]))) return cls( variables=map(read(Variable), d.get('variables', {}).items()), properties=map(read(Property), d.get('properties', {}).items()), roles=map(read(Role), d.get('roles', {}).items()), predicates=map(read(Predicate), d.get('predicates', {}).items()) )
[ "def", "from_dict", "(", "cls", ",", "d", ")", ":", "read", "=", "lambda", "cls", ":", "(", "lambda", "pair", ":", "(", "pair", "[", "0", "]", ",", "cls", ".", "from_dict", "(", "pair", "[", "1", "]", ")", ")", ")", "return", "cls", "(", "var...
Instantiate a SemI from a dictionary representation.
[ "Instantiate", "a", "SemI", "from", "a", "dictionary", "representation", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L322-L330
9,031
delph-in/pydelphin
delphin/mrs/semi.py
SemI.to_dict
def to_dict(self): """Return a dictionary representation of the SemI.""" make = lambda pair: (pair[0], pair[1].to_dict()) return dict( variables=dict(make(v) for v in self.variables.items()), properties=dict(make(p) for p in self.properties.items()), roles=dict(make(r) for r in self.roles.items()), predicates=dict(make(p) for p in self.predicates.items()) )
python
def to_dict(self): make = lambda pair: (pair[0], pair[1].to_dict()) return dict( variables=dict(make(v) for v in self.variables.items()), properties=dict(make(p) for p in self.properties.items()), roles=dict(make(r) for r in self.roles.items()), predicates=dict(make(p) for p in self.predicates.items()) )
[ "def", "to_dict", "(", "self", ")", ":", "make", "=", "lambda", "pair", ":", "(", "pair", "[", "0", "]", ",", "pair", "[", "1", "]", ".", "to_dict", "(", ")", ")", "return", "dict", "(", "variables", "=", "dict", "(", "make", "(", "v", ")", "...
Return a dictionary representation of the SemI.
[ "Return", "a", "dictionary", "representation", "of", "the", "SemI", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/semi.py#L332-L340
9,032
delph-in/pydelphin
delphin/mrs/components.py
sort_vid_split
def sort_vid_split(vs): """ Split a valid variable string into its variable sort and id. Examples: >>> sort_vid_split('h3') ('h', '3') >>> sort_vid_split('ref-ind12') ('ref-ind', '12') """ match = var_re.match(vs) if match is None: raise ValueError('Invalid variable string: {}'.format(str(vs))) else: return match.groups()
python
def sort_vid_split(vs): match = var_re.match(vs) if match is None: raise ValueError('Invalid variable string: {}'.format(str(vs))) else: return match.groups()
[ "def", "sort_vid_split", "(", "vs", ")", ":", "match", "=", "var_re", ".", "match", "(", "vs", ")", "if", "match", "is", "None", ":", "raise", "ValueError", "(", "'Invalid variable string: {}'", ".", "format", "(", "str", "(", "vs", ")", ")", ")", "els...
Split a valid variable string into its variable sort and id. Examples: >>> sort_vid_split('h3') ('h', '3') >>> sort_vid_split('ref-ind12') ('ref-ind', '12')
[ "Split", "a", "valid", "variable", "string", "into", "its", "variable", "sort", "and", "id", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L31-L45
9,033
delph-in/pydelphin
delphin/mrs/components.py
Lnk.charspan
def charspan(cls, start, end): """ Create a Lnk object for a character span. Args: start: the initial character position (cfrom) end: the final character position (cto) """ return cls(Lnk.CHARSPAN, (int(start), int(end)))
python
def charspan(cls, start, end): return cls(Lnk.CHARSPAN, (int(start), int(end)))
[ "def", "charspan", "(", "cls", ",", "start", ",", "end", ")", ":", "return", "cls", "(", "Lnk", ".", "CHARSPAN", ",", "(", "int", "(", "start", ")", ",", "int", "(", "end", ")", ")", ")" ]
Create a Lnk object for a character span. Args: start: the initial character position (cfrom) end: the final character position (cto)
[ "Create", "a", "Lnk", "object", "for", "a", "character", "span", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L160-L168
9,034
delph-in/pydelphin
delphin/mrs/components.py
Lnk.chartspan
def chartspan(cls, start, end): """ Create a Lnk object for a chart span. Args: start: the initial chart vertex end: the final chart vertex """ return cls(Lnk.CHARTSPAN, (int(start), int(end)))
python
def chartspan(cls, start, end): return cls(Lnk.CHARTSPAN, (int(start), int(end)))
[ "def", "chartspan", "(", "cls", ",", "start", ",", "end", ")", ":", "return", "cls", "(", "Lnk", ".", "CHARTSPAN", ",", "(", "int", "(", "start", ")", ",", "int", "(", "end", ")", ")", ")" ]
Create a Lnk object for a chart span. Args: start: the initial chart vertex end: the final chart vertex
[ "Create", "a", "Lnk", "object", "for", "a", "chart", "span", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L171-L179
9,035
delph-in/pydelphin
delphin/mrs/components.py
Lnk.tokens
def tokens(cls, tokens): """ Create a Lnk object for a token range. Args: tokens: a list of token identifiers """ return cls(Lnk.TOKENS, tuple(map(int, tokens)))
python
def tokens(cls, tokens): return cls(Lnk.TOKENS, tuple(map(int, tokens)))
[ "def", "tokens", "(", "cls", ",", "tokens", ")", ":", "return", "cls", "(", "Lnk", ".", "TOKENS", ",", "tuple", "(", "map", "(", "int", ",", "tokens", ")", ")", ")" ]
Create a Lnk object for a token range. Args: tokens: a list of token identifiers
[ "Create", "a", "Lnk", "object", "for", "a", "token", "range", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L182-L189
9,036
delph-in/pydelphin
delphin/mrs/components.py
_LnkMixin.cfrom
def cfrom(self): """ The initial character position in the surface string. Defaults to -1 if there is no valid cfrom value. """ cfrom = -1 try: if self.lnk.type == Lnk.CHARSPAN: cfrom = self.lnk.data[0] except AttributeError: pass # use default cfrom of -1 return cfrom
python
def cfrom(self): cfrom = -1 try: if self.lnk.type == Lnk.CHARSPAN: cfrom = self.lnk.data[0] except AttributeError: pass # use default cfrom of -1 return cfrom
[ "def", "cfrom", "(", "self", ")", ":", "cfrom", "=", "-", "1", "try", ":", "if", "self", ".", "lnk", ".", "type", "==", "Lnk", ".", "CHARSPAN", ":", "cfrom", "=", "self", ".", "lnk", ".", "data", "[", "0", "]", "except", "AttributeError", ":", ...
The initial character position in the surface string. Defaults to -1 if there is no valid cfrom value.
[ "The", "initial", "character", "position", "in", "the", "surface", "string", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L232-L244
9,037
delph-in/pydelphin
delphin/mrs/components.py
_LnkMixin.cto
def cto(self): """ The final character position in the surface string. Defaults to -1 if there is no valid cto value. """ cto = -1 try: if self.lnk.type == Lnk.CHARSPAN: cto = self.lnk.data[1] except AttributeError: pass # use default cto of -1 return cto
python
def cto(self): cto = -1 try: if self.lnk.type == Lnk.CHARSPAN: cto = self.lnk.data[1] except AttributeError: pass # use default cto of -1 return cto
[ "def", "cto", "(", "self", ")", ":", "cto", "=", "-", "1", "try", ":", "if", "self", ".", "lnk", ".", "type", "==", "Lnk", ".", "CHARSPAN", ":", "cto", "=", "self", ".", "lnk", ".", "data", "[", "1", "]", "except", "AttributeError", ":", "pass"...
The final character position in the surface string. Defaults to -1 if there is no valid cto value.
[ "The", "final", "character", "position", "in", "the", "surface", "string", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L247-L259
9,038
delph-in/pydelphin
delphin/mrs/components.py
Pred.surface
def surface(cls, predstr): """Instantiate a Pred from its quoted string representation.""" lemma, pos, sense, _ = split_pred_string(predstr) return cls(Pred.SURFACE, lemma, pos, sense, predstr)
python
def surface(cls, predstr): lemma, pos, sense, _ = split_pred_string(predstr) return cls(Pred.SURFACE, lemma, pos, sense, predstr)
[ "def", "surface", "(", "cls", ",", "predstr", ")", ":", "lemma", ",", "pos", ",", "sense", ",", "_", "=", "split_pred_string", "(", "predstr", ")", "return", "cls", "(", "Pred", ".", "SURFACE", ",", "lemma", ",", "pos", ",", "sense", ",", "predstr", ...
Instantiate a Pred from its quoted string representation.
[ "Instantiate", "a", "Pred", "from", "its", "quoted", "string", "representation", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L524-L527
9,039
delph-in/pydelphin
delphin/mrs/components.py
Pred.abstract
def abstract(cls, predstr): """Instantiate a Pred from its symbol string.""" lemma, pos, sense, _ = split_pred_string(predstr) return cls(Pred.ABSTRACT, lemma, pos, sense, predstr)
python
def abstract(cls, predstr): lemma, pos, sense, _ = split_pred_string(predstr) return cls(Pred.ABSTRACT, lemma, pos, sense, predstr)
[ "def", "abstract", "(", "cls", ",", "predstr", ")", ":", "lemma", ",", "pos", ",", "sense", ",", "_", "=", "split_pred_string", "(", "predstr", ")", "return", "cls", "(", "Pred", ".", "ABSTRACT", ",", "lemma", ",", "pos", ",", "sense", ",", "predstr"...
Instantiate a Pred from its symbol string.
[ "Instantiate", "a", "Pred", "from", "its", "symbol", "string", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L536-L539
9,040
delph-in/pydelphin
delphin/mrs/components.py
Pred.surface_or_abstract
def surface_or_abstract(cls, predstr): """Instantiate a Pred from either its surface or abstract symbol.""" if predstr.strip('"').lstrip("'").startswith('_'): return cls.surface(predstr) else: return cls.abstract(predstr)
python
def surface_or_abstract(cls, predstr): if predstr.strip('"').lstrip("'").startswith('_'): return cls.surface(predstr) else: return cls.abstract(predstr)
[ "def", "surface_or_abstract", "(", "cls", ",", "predstr", ")", ":", "if", "predstr", ".", "strip", "(", "'\"'", ")", ".", "lstrip", "(", "\"'\"", ")", ".", "startswith", "(", "'_'", ")", ":", "return", "cls", ".", "surface", "(", "predstr", ")", "els...
Instantiate a Pred from either its surface or abstract symbol.
[ "Instantiate", "a", "Pred", "from", "either", "its", "surface", "or", "abstract", "symbol", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L548-L553
9,041
delph-in/pydelphin
delphin/mrs/components.py
Pred.realpred
def realpred(cls, lemma, pos, sense=None): """Instantiate a Pred from its components.""" string_tokens = [lemma] if pos is not None: string_tokens.append(pos) if sense is not None: sense = str(sense) string_tokens.append(sense) predstr = '_'.join([''] + string_tokens + ['rel']) return cls(Pred.REALPRED, lemma, pos, sense, predstr)
python
def realpred(cls, lemma, pos, sense=None): string_tokens = [lemma] if pos is not None: string_tokens.append(pos) if sense is not None: sense = str(sense) string_tokens.append(sense) predstr = '_'.join([''] + string_tokens + ['rel']) return cls(Pred.REALPRED, lemma, pos, sense, predstr)
[ "def", "realpred", "(", "cls", ",", "lemma", ",", "pos", ",", "sense", "=", "None", ")", ":", "string_tokens", "=", "[", "lemma", "]", "if", "pos", "is", "not", "None", ":", "string_tokens", ".", "append", "(", "pos", ")", "if", "sense", "is", "not...
Instantiate a Pred from its components.
[ "Instantiate", "a", "Pred", "from", "its", "components", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L556-L565
9,042
delph-in/pydelphin
delphin/mrs/components.py
Node.properties
def properties(self): """ Morphosemantic property mapping. Unlike :attr:`sortinfo`, this does not include `cvarsort`. """ d = dict(self.sortinfo) if CVARSORT in d: del d[CVARSORT] return d
python
def properties(self): d = dict(self.sortinfo) if CVARSORT in d: del d[CVARSORT] return d
[ "def", "properties", "(", "self", ")", ":", "d", "=", "dict", "(", "self", ".", "sortinfo", ")", "if", "CVARSORT", "in", "d", ":", "del", "d", "[", "CVARSORT", "]", "return", "d" ]
Morphosemantic property mapping. Unlike :attr:`sortinfo`, this does not include `cvarsort`.
[ "Morphosemantic", "property", "mapping", "." ]
7bd2cd63ab7cf74803e1d6547b9ebc014b382abd
https://github.com/delph-in/pydelphin/blob/7bd2cd63ab7cf74803e1d6547b9ebc014b382abd/delphin/mrs/components.py#L762-L771
9,043
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_meta_data.py
EntityRepresentation.update_get_params
def update_get_params(self): """Update HTTP GET params with the given fields that user wants to fetch.""" if isinstance(self._fields, (tuple, list)): # tuples & lists > x,y,z self.get_params["fields"] = ",".join([str(_) for _ in self._fields]) elif isinstance(self._fields, str): self.get_params["fields"] = self._fields
python
def update_get_params(self): if isinstance(self._fields, (tuple, list)): # tuples & lists > x,y,z self.get_params["fields"] = ",".join([str(_) for _ in self._fields]) elif isinstance(self._fields, str): self.get_params["fields"] = self._fields
[ "def", "update_get_params", "(", "self", ")", ":", "if", "isinstance", "(", "self", ".", "_fields", ",", "(", "tuple", ",", "list", ")", ")", ":", "# tuples & lists > x,y,z", "self", ".", "get_params", "[", "\"fields\"", "]", "=", "\",\"", ".", "join", "...
Update HTTP GET params with the given fields that user wants to fetch.
[ "Update", "HTTP", "GET", "params", "with", "the", "given", "fields", "that", "user", "wants", "to", "fetch", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_meta_data.py#L54-L59
9,044
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_meta_data.py
EntityRepresentation._fetch_meta_data
def _fetch_meta_data(self): """Makes an API call to fetch meta data for the given probe and stores the raw data.""" is_success, meta_data = AtlasRequest( url_path=self.API_META_URL.format(self.id), key=self.api_key, server=self.server, verify=self.verify, user_agent=self._user_agent ).get(**self.get_params) self.meta_data = meta_data if not is_success: return False return True
python
def _fetch_meta_data(self): is_success, meta_data = AtlasRequest( url_path=self.API_META_URL.format(self.id), key=self.api_key, server=self.server, verify=self.verify, user_agent=self._user_agent ).get(**self.get_params) self.meta_data = meta_data if not is_success: return False return True
[ "def", "_fetch_meta_data", "(", "self", ")", ":", "is_success", ",", "meta_data", "=", "AtlasRequest", "(", "url_path", "=", "self", ".", "API_META_URL", ".", "format", "(", "self", ".", "id", ")", ",", "key", "=", "self", ".", "api_key", ",", "server", ...
Makes an API call to fetch meta data for the given probe and stores the raw data.
[ "Makes", "an", "API", "call", "to", "fetch", "meta", "data", "for", "the", "given", "probe", "and", "stores", "the", "raw", "data", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_meta_data.py#L61-L75
9,045
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_meta_data.py
Probe._populate_data
def _populate_data(self): """Assing some probe's raw meta data from API response to instance properties""" if self.id is None: self.id = self.meta_data.get("id") self.is_anchor = self.meta_data.get("is_anchor") self.country_code = self.meta_data.get("country_code") self.description = self.meta_data.get("description") self.is_public = self.meta_data.get("is_public") self.asn_v4 = self.meta_data.get("asn_v4") self.asn_v6 = self.meta_data.get("asn_v6") self.address_v4 = self.meta_data.get("address_v4") self.address_v6 = self.meta_data.get("address_v6") self.prefix_v4 = self.meta_data.get("prefix_v4") self.prefix_v6 = self.meta_data.get("prefix_v6") self.geometry = self.meta_data.get("geometry") self.tags = self.meta_data.get("tags") self.status = self.meta_data.get("status", {}).get("name")
python
def _populate_data(self): if self.id is None: self.id = self.meta_data.get("id") self.is_anchor = self.meta_data.get("is_anchor") self.country_code = self.meta_data.get("country_code") self.description = self.meta_data.get("description") self.is_public = self.meta_data.get("is_public") self.asn_v4 = self.meta_data.get("asn_v4") self.asn_v6 = self.meta_data.get("asn_v6") self.address_v4 = self.meta_data.get("address_v4") self.address_v6 = self.meta_data.get("address_v6") self.prefix_v4 = self.meta_data.get("prefix_v4") self.prefix_v6 = self.meta_data.get("prefix_v6") self.geometry = self.meta_data.get("geometry") self.tags = self.meta_data.get("tags") self.status = self.meta_data.get("status", {}).get("name")
[ "def", "_populate_data", "(", "self", ")", ":", "if", "self", ".", "id", "is", "None", ":", "self", ".", "id", "=", "self", ".", "meta_data", ".", "get", "(", "\"id\"", ")", "self", ".", "is_anchor", "=", "self", ".", "meta_data", ".", "get", "(", ...
Assing some probe's raw meta data from API response to instance properties
[ "Assing", "some", "probe", "s", "raw", "meta", "data", "from", "API", "response", "to", "instance", "properties" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_meta_data.py#L90-L106
9,046
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_meta_data.py
Measurement._populate_data
def _populate_data(self): """Assinging some measurement's raw meta data from API response to instance properties""" if self.id is None: self.id = self.meta_data.get("id") self.stop_time = None self.creation_time = None self.start_time = None self.populate_times() self.protocol = self.meta_data.get("af") self.target_ip = self.meta_data.get("target_ip") self.target_asn = self.meta_data.get("target_asn") self.target = self.meta_data.get("target") self.description = self.meta_data.get("description") self.is_oneoff = self.meta_data.get("is_oneoff") self.is_public = self.meta_data.get("is_public") self.interval = self.meta_data.get("interval") self.resolve_on_probe = self.meta_data.get("resolve_on_probe") self.status_id = self.meta_data.get("status", {}).get("id") self.status = self.meta_data.get("status", {}).get("name") self.type = self.get_type() self.result_url = self.meta_data.get("result")
python
def _populate_data(self): if self.id is None: self.id = self.meta_data.get("id") self.stop_time = None self.creation_time = None self.start_time = None self.populate_times() self.protocol = self.meta_data.get("af") self.target_ip = self.meta_data.get("target_ip") self.target_asn = self.meta_data.get("target_asn") self.target = self.meta_data.get("target") self.description = self.meta_data.get("description") self.is_oneoff = self.meta_data.get("is_oneoff") self.is_public = self.meta_data.get("is_public") self.interval = self.meta_data.get("interval") self.resolve_on_probe = self.meta_data.get("resolve_on_probe") self.status_id = self.meta_data.get("status", {}).get("id") self.status = self.meta_data.get("status", {}).get("name") self.type = self.get_type() self.result_url = self.meta_data.get("result")
[ "def", "_populate_data", "(", "self", ")", ":", "if", "self", ".", "id", "is", "None", ":", "self", ".", "id", "=", "self", ".", "meta_data", ".", "get", "(", "\"id\"", ")", "self", ".", "stop_time", "=", "None", "self", ".", "creation_time", "=", ...
Assinging some measurement's raw meta data from API response to instance properties
[ "Assinging", "some", "measurement", "s", "raw", "meta", "data", "from", "API", "response", "to", "instance", "properties" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_meta_data.py#L121-L142
9,047
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_meta_data.py
Measurement.get_type
def get_type(self): """ Getting type of measurement keeping backwards compatibility for v2 API output changes. """ mtype = None if "type" not in self.meta_data: return mtype mtype = self.meta_data["type"] if isinstance(mtype, dict): mtype = self.meta_data.get("type", {}).get("name", "").upper() elif isinstance(mtype, str): mtype = mtype return mtype
python
def get_type(self): mtype = None if "type" not in self.meta_data: return mtype mtype = self.meta_data["type"] if isinstance(mtype, dict): mtype = self.meta_data.get("type", {}).get("name", "").upper() elif isinstance(mtype, str): mtype = mtype return mtype
[ "def", "get_type", "(", "self", ")", ":", "mtype", "=", "None", "if", "\"type\"", "not", "in", "self", ".", "meta_data", ":", "return", "mtype", "mtype", "=", "self", ".", "meta_data", "[", "\"type\"", "]", "if", "isinstance", "(", "mtype", ",", "dict"...
Getting type of measurement keeping backwards compatibility for v2 API output changes.
[ "Getting", "type", "of", "measurement", "keeping", "backwards", "compatibility", "for", "v2", "API", "output", "changes", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_meta_data.py#L144-L159
9,048
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_meta_data.py
Measurement.populate_times
def populate_times(self): """ Populates all different meta data times that comes with measurement if they are present. """ stop_time = self.meta_data.get("stop_time") if stop_time: stop_naive = datetime.utcfromtimestamp(stop_time) self.stop_time = stop_naive.replace(tzinfo=tzutc()) creation_time = self.meta_data.get("creation_time") if creation_time: creation_naive = datetime.utcfromtimestamp(creation_time) self.creation_time = creation_naive.replace(tzinfo=tzutc()) start_time = self.meta_data.get("start_time") if start_time: start_naive = datetime.utcfromtimestamp(start_time) self.start_time = start_naive.replace(tzinfo=tzutc())
python
def populate_times(self): stop_time = self.meta_data.get("stop_time") if stop_time: stop_naive = datetime.utcfromtimestamp(stop_time) self.stop_time = stop_naive.replace(tzinfo=tzutc()) creation_time = self.meta_data.get("creation_time") if creation_time: creation_naive = datetime.utcfromtimestamp(creation_time) self.creation_time = creation_naive.replace(tzinfo=tzutc()) start_time = self.meta_data.get("start_time") if start_time: start_naive = datetime.utcfromtimestamp(start_time) self.start_time = start_naive.replace(tzinfo=tzutc())
[ "def", "populate_times", "(", "self", ")", ":", "stop_time", "=", "self", ".", "meta_data", ".", "get", "(", "\"stop_time\"", ")", "if", "stop_time", ":", "stop_naive", "=", "datetime", ".", "utcfromtimestamp", "(", "stop_time", ")", "self", ".", "stop_time"...
Populates all different meta data times that comes with measurement if they are present.
[ "Populates", "all", "different", "meta", "data", "times", "that", "comes", "with", "measurement", "if", "they", "are", "present", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_meta_data.py#L161-L179
9,049
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/source.py
AtlasChangeSource.set_action
def set_action(self, value): """Setter for action attribute""" if value not in ("remove", "add"): log = "Sources field 'action' should be 'remove' or 'add'." raise MalFormattedSource(log) self._action = value
python
def set_action(self, value): if value not in ("remove", "add"): log = "Sources field 'action' should be 'remove' or 'add'." raise MalFormattedSource(log) self._action = value
[ "def", "set_action", "(", "self", ",", "value", ")", ":", "if", "value", "not", "in", "(", "\"remove\"", ",", "\"add\"", ")", ":", "log", "=", "\"Sources field 'action' should be 'remove' or 'add'.\"", "raise", "MalFormattedSource", "(", "log", ")", "self", ".",...
Setter for action attribute
[ "Setter", "for", "action", "attribute" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/source.py#L206-L211
9,050
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/source.py
AtlasChangeSource.build_api_struct
def build_api_struct(self): """ Calls parent's method and just adds the addtional field 'action', that is required to form the structure that Atlas API is accepting. """ data = super(AtlasChangeSource, self).build_api_struct() data.update({"action": self._action}) return data
python
def build_api_struct(self): data = super(AtlasChangeSource, self).build_api_struct() data.update({"action": self._action}) return data
[ "def", "build_api_struct", "(", "self", ")", ":", "data", "=", "super", "(", "AtlasChangeSource", ",", "self", ")", ".", "build_api_struct", "(", ")", "data", ".", "update", "(", "{", "\"action\"", ":", "self", ".", "_action", "}", ")", "return", "data" ...
Calls parent's method and just adds the addtional field 'action', that is required to form the structure that Atlas API is accepting.
[ "Calls", "parent", "s", "method", "and", "just", "adds", "the", "addtional", "field", "action", "that", "is", "required", "to", "form", "the", "structure", "that", "Atlas", "API", "is", "accepting", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/source.py#L226-L233
9,051
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/measurement.py
AtlasMeasurement.add_option
def add_option(self, **options): """ Adds an option and its value to the class as an attribute and stores it to the used options set. """ for option, value in options.items(): setattr(self, option, value) self._store_option(option)
python
def add_option(self, **options): for option, value in options.items(): setattr(self, option, value) self._store_option(option)
[ "def", "add_option", "(", "self", ",", "*", "*", "options", ")", ":", "for", "option", ",", "value", "in", "options", ".", "items", "(", ")", ":", "setattr", "(", "self", ",", "option", ",", "value", ")", "self", ".", "_store_option", "(", "option", ...
Adds an option and its value to the class as an attribute and stores it to the used options set.
[ "Adds", "an", "option", "and", "its", "value", "to", "the", "class", "as", "an", "attribute", "and", "stores", "it", "to", "the", "used", "options", "set", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/measurement.py#L60-L67
9,052
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/measurement.py
AtlasMeasurement.v2_translator
def v2_translator(self, option): """ This is a temporary function that helps move from v1 API to v2 without breaking already running script and keep backwards compatibility. Translates option name from API v1 to renamed one of v2 API. """ new_option = option new_value = getattr(self, option) renaming_pairs = { "dontfrag": "dont_fragment", "maxhops": "max_hops", "firsthop": "first_hop", "use_NSID": "set_nsid_bit", "cd": "set_cd_bit", "do": "set_do_bit", "qbuf": "include_qbuf", "recursion_desired": "set_rd_bit", "noabuf": "include_abuf" } if option in renaming_pairs.keys(): warninglog = ( "DeprecationWarning: {0} option has been deprecated and " "renamed to {1}." ).format(option, renaming_pairs[option]) print(warninglog) new_option = renaming_pairs[option] # noabuf was changed to include_abuf so we need a double-negative if option == "noabuf": new_value = not new_value return new_option, new_value
python
def v2_translator(self, option): new_option = option new_value = getattr(self, option) renaming_pairs = { "dontfrag": "dont_fragment", "maxhops": "max_hops", "firsthop": "first_hop", "use_NSID": "set_nsid_bit", "cd": "set_cd_bit", "do": "set_do_bit", "qbuf": "include_qbuf", "recursion_desired": "set_rd_bit", "noabuf": "include_abuf" } if option in renaming_pairs.keys(): warninglog = ( "DeprecationWarning: {0} option has been deprecated and " "renamed to {1}." ).format(option, renaming_pairs[option]) print(warninglog) new_option = renaming_pairs[option] # noabuf was changed to include_abuf so we need a double-negative if option == "noabuf": new_value = not new_value return new_option, new_value
[ "def", "v2_translator", "(", "self", ",", "option", ")", ":", "new_option", "=", "option", "new_value", "=", "getattr", "(", "self", ",", "option", ")", "renaming_pairs", "=", "{", "\"dontfrag\"", ":", "\"dont_fragment\"", ",", "\"maxhops\"", ":", "\"max_hops\...
This is a temporary function that helps move from v1 API to v2 without breaking already running script and keep backwards compatibility. Translates option name from API v1 to renamed one of v2 API.
[ "This", "is", "a", "temporary", "function", "that", "helps", "move", "from", "v1", "API", "to", "v2", "without", "breaking", "already", "running", "script", "and", "keep", "backwards", "compatibility", ".", "Translates", "option", "name", "from", "API", "v1", ...
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/measurement.py#L100-L132
9,053
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/stream.py
AtlasStream.connect
def connect(self): """Initiate the channel we want to start streams from.""" self.socketIO = SocketIO( host=self.iosocket_server, port=80, resource=self.iosocket_resource, proxies=self.proxies, headers=self.headers, transports=["websocket"], Namespace=AtlasNamespace, ) self.socketIO.on(self.EVENT_NAME_ERROR, self.handle_error)
python
def connect(self): self.socketIO = SocketIO( host=self.iosocket_server, port=80, resource=self.iosocket_resource, proxies=self.proxies, headers=self.headers, transports=["websocket"], Namespace=AtlasNamespace, ) self.socketIO.on(self.EVENT_NAME_ERROR, self.handle_error)
[ "def", "connect", "(", "self", ")", ":", "self", ".", "socketIO", "=", "SocketIO", "(", "host", "=", "self", ".", "iosocket_server", ",", "port", "=", "80", ",", "resource", "=", "self", ".", "iosocket_resource", ",", "proxies", "=", "self", ".", "prox...
Initiate the channel we want to start streams from.
[ "Initiate", "the", "channel", "we", "want", "to", "start", "streams", "from", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/stream.py#L104-L116
9,054
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/stream.py
AtlasStream.bind_channel
def bind_channel(self, channel, callback): """Bind given channel with the given callback""" # Remove the following list when deprecation time expires if channel in self.CHANNELS: warning = ( "The event name '{}' will soon be deprecated. Use " "the real event name '{}' instead." ).format(channel, self.CHANNELS[channel]) self.handle_error(warning) channel = self.CHANNELS[channel] # ------------------------------------------------------- if channel == self.EVENT_NAME_ERROR: self.error_callback = callback elif channel == self.EVENT_NAME_RESULTS: self.socketIO.on(channel, partial(self.unpack_results, callback)) else: self.socketIO.on(channel, callback)
python
def bind_channel(self, channel, callback): # Remove the following list when deprecation time expires if channel in self.CHANNELS: warning = ( "The event name '{}' will soon be deprecated. Use " "the real event name '{}' instead." ).format(channel, self.CHANNELS[channel]) self.handle_error(warning) channel = self.CHANNELS[channel] # ------------------------------------------------------- if channel == self.EVENT_NAME_ERROR: self.error_callback = callback elif channel == self.EVENT_NAME_RESULTS: self.socketIO.on(channel, partial(self.unpack_results, callback)) else: self.socketIO.on(channel, callback)
[ "def", "bind_channel", "(", "self", ",", "channel", ",", "callback", ")", ":", "# Remove the following list when deprecation time expires", "if", "channel", "in", "self", ".", "CHANNELS", ":", "warning", "=", "(", "\"The event name '{}' will soon be deprecated. Use \"", "...
Bind given channel with the given callback
[ "Bind", "given", "channel", "with", "the", "given", "callback" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/stream.py#L130-L149
9,055
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/stream.py
AtlasStream.start_stream
def start_stream(self, stream_type, **stream_parameters): """Starts new stream for given type with given parameters""" if stream_type: self.subscribe(stream_type, **stream_parameters) else: self.handle_error("You need to set a stream type")
python
def start_stream(self, stream_type, **stream_parameters): if stream_type: self.subscribe(stream_type, **stream_parameters) else: self.handle_error("You need to set a stream type")
[ "def", "start_stream", "(", "self", ",", "stream_type", ",", "*", "*", "stream_parameters", ")", ":", "if", "stream_type", ":", "self", ".", "subscribe", "(", "stream_type", ",", "*", "*", "stream_parameters", ")", "else", ":", "self", ".", "handle_error", ...
Starts new stream for given type with given parameters
[ "Starts", "new", "stream", "for", "given", "type", "with", "given", "parameters" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/stream.py#L151-L156
9,056
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/stream.py
AtlasStream.subscribe
def subscribe(self, stream_type, **parameters): """Subscribe to stream with give parameters.""" parameters["stream_type"] = stream_type if (stream_type == "result") and ("buffering" not in parameters): parameters["buffering"] = True self.socketIO.emit(self.EVENT_NAME_SUBSCRIBE, parameters)
python
def subscribe(self, stream_type, **parameters): parameters["stream_type"] = stream_type if (stream_type == "result") and ("buffering" not in parameters): parameters["buffering"] = True self.socketIO.emit(self.EVENT_NAME_SUBSCRIBE, parameters)
[ "def", "subscribe", "(", "self", ",", "stream_type", ",", "*", "*", "parameters", ")", ":", "parameters", "[", "\"stream_type\"", "]", "=", "stream_type", "if", "(", "stream_type", "==", "\"result\"", ")", "and", "(", "\"buffering\"", "not", "in", "parameter...
Subscribe to stream with give parameters.
[ "Subscribe", "to", "stream", "with", "give", "parameters", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/stream.py#L158-L165
9,057
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/stream.py
AtlasStream.timeout
def timeout(self, seconds=None): """ Times out all streams after n seconds or wait forever if seconds is None """ if seconds is None: self.socketIO.wait() else: self.socketIO.wait(seconds=seconds)
python
def timeout(self, seconds=None): if seconds is None: self.socketIO.wait() else: self.socketIO.wait(seconds=seconds)
[ "def", "timeout", "(", "self", ",", "seconds", "=", "None", ")", ":", "if", "seconds", "is", "None", ":", "self", ".", "socketIO", ".", "wait", "(", ")", "else", ":", "self", ".", "socketIO", ".", "wait", "(", "seconds", "=", "seconds", ")" ]
Times out all streams after n seconds or wait forever if seconds is None
[ "Times", "out", "all", "streams", "after", "n", "seconds", "or", "wait", "forever", "if", "seconds", "is", "None" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/stream.py#L167-L175
9,058
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_listing.py
RequestGenerator.build_url
def build_url(self): """Build the url path based on the filter options.""" if not self.api_filters: return self.url # Reduce complex objects to simpler strings for k, v in self.api_filters.items(): if isinstance(v, datetime): # datetime > UNIX timestamp self.api_filters[k] = int(calendar.timegm(v.timetuple())) if isinstance(v, (tuple, list)): # tuples & lists > x,y,z self.api_filters[k] = ",".join([str(_) for _ in v]) if ( self.id_filter in self.api_filters and len(str(self.api_filters[self.id_filter])) > self.URL_LENGTH_LIMIT ): self.build_url_chunks() return self.split_urls.pop(0) filters = '&'.join("%s=%s" % (k, v) for (k, v) in self.api_filters.items()) return "%s?%s" % (self.url, filters)
python
def build_url(self): if not self.api_filters: return self.url # Reduce complex objects to simpler strings for k, v in self.api_filters.items(): if isinstance(v, datetime): # datetime > UNIX timestamp self.api_filters[k] = int(calendar.timegm(v.timetuple())) if isinstance(v, (tuple, list)): # tuples & lists > x,y,z self.api_filters[k] = ",".join([str(_) for _ in v]) if ( self.id_filter in self.api_filters and len(str(self.api_filters[self.id_filter])) > self.URL_LENGTH_LIMIT ): self.build_url_chunks() return self.split_urls.pop(0) filters = '&'.join("%s=%s" % (k, v) for (k, v) in self.api_filters.items()) return "%s?%s" % (self.url, filters)
[ "def", "build_url", "(", "self", ")", ":", "if", "not", "self", ".", "api_filters", ":", "return", "self", ".", "url", "# Reduce complex objects to simpler strings", "for", "k", ",", "v", "in", "self", ".", "api_filters", ".", "items", "(", ")", ":", "if",...
Build the url path based on the filter options.
[ "Build", "the", "url", "path", "based", "on", "the", "filter", "options", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_listing.py#L55-L77
9,059
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_listing.py
RequestGenerator.build_url_chunks
def build_url_chunks(self): """ If url is too big because of id filter is huge, break id and construct several urls to call them in order to abstract this complexity from user. """ CHUNK_SIZE = 500 id_filter = str(self.api_filters.pop(self.id_filter)).split(',') chuncks = list(self.chunks(id_filter, CHUNK_SIZE)) filters = '&'.join("%s=%s" % (k, v) for (k, v) in self.api_filters.items()) for chunk in chuncks: if filters: url = "{0}?{1}&{2}={3}".format(self.url, filters, self.id_filter, ','.join(chunk)) else: url = "{0}?{1}={2}".format(self.url, self.id_filter, ','.join(chunk)) self.split_urls.append(url)
python
def build_url_chunks(self): CHUNK_SIZE = 500 id_filter = str(self.api_filters.pop(self.id_filter)).split(',') chuncks = list(self.chunks(id_filter, CHUNK_SIZE)) filters = '&'.join("%s=%s" % (k, v) for (k, v) in self.api_filters.items()) for chunk in chuncks: if filters: url = "{0}?{1}&{2}={3}".format(self.url, filters, self.id_filter, ','.join(chunk)) else: url = "{0}?{1}={2}".format(self.url, self.id_filter, ','.join(chunk)) self.split_urls.append(url)
[ "def", "build_url_chunks", "(", "self", ")", ":", "CHUNK_SIZE", "=", "500", "id_filter", "=", "str", "(", "self", ".", "api_filters", ".", "pop", "(", "self", ".", "id_filter", ")", ")", ".", "split", "(", "','", ")", "chuncks", "=", "list", "(", "se...
If url is too big because of id filter is huge, break id and construct several urls to call them in order to abstract this complexity from user.
[ "If", "url", "is", "too", "big", "because", "of", "id", "filter", "is", "huge", "break", "id", "and", "construct", "several", "urls", "to", "call", "them", "in", "order", "to", "abstract", "this", "complexity", "from", "user", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_listing.py#L79-L95
9,060
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_listing.py
RequestGenerator.next_batch
def next_batch(self): """ Querying API for the next batch of objects and store next url and batch of objects. """ is_success, results = AtlasRequest( url_path=self.atlas_url, user_agent=self._user_agent, server=self.server, verify=self.verify, ).get() if not is_success: raise APIResponseError(results) self.total_count = results.get("count") self.atlas_url = self.build_next_url(results.get("next")) self.current_batch = results.get("results", [])
python
def next_batch(self): is_success, results = AtlasRequest( url_path=self.atlas_url, user_agent=self._user_agent, server=self.server, verify=self.verify, ).get() if not is_success: raise APIResponseError(results) self.total_count = results.get("count") self.atlas_url = self.build_next_url(results.get("next")) self.current_batch = results.get("results", [])
[ "def", "next_batch", "(", "self", ")", ":", "is_success", ",", "results", "=", "AtlasRequest", "(", "url_path", "=", "self", ".", "atlas_url", ",", "user_agent", "=", "self", ".", "_user_agent", ",", "server", "=", "self", ".", "server", ",", "verify", "...
Querying API for the next batch of objects and store next url and batch of objects.
[ "Querying", "API", "for", "the", "next", "batch", "of", "objects", "and", "store", "next", "url", "and", "batch", "of", "objects", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_listing.py#L123-L140
9,061
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_listing.py
RequestGenerator.build_next_url
def build_next_url(self, url): """Builds next url in a format compatible with cousteau. Path + query""" if not url: if self.split_urls: # If we had a long request give the next part self.total_count_flag = False # Reset flag for count return self.split_urls.pop(0) else: return None parsed_url = urlparse(url) return "{0}?{1}".format(parsed_url.path, parsed_url.query)
python
def build_next_url(self, url): if not url: if self.split_urls: # If we had a long request give the next part self.total_count_flag = False # Reset flag for count return self.split_urls.pop(0) else: return None parsed_url = urlparse(url) return "{0}?{1}".format(parsed_url.path, parsed_url.query)
[ "def", "build_next_url", "(", "self", ",", "url", ")", ":", "if", "not", "url", ":", "if", "self", ".", "split_urls", ":", "# If we had a long request give the next part", "self", ".", "total_count_flag", "=", "False", "# Reset flag for count", "return", "self", "...
Builds next url in a format compatible with cousteau. Path + query
[ "Builds", "next", "url", "in", "a", "format", "compatible", "with", "cousteau", ".", "Path", "+", "query" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_listing.py#L142-L152
9,062
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/api_listing.py
RequestGenerator.set_total_count
def set_total_count(self, value): """Setter for count attribute. Set should append only one count per splitted url.""" if not self.total_count_flag and value: self._count.append(int(value)) self.total_count_flag = True
python
def set_total_count(self, value): if not self.total_count_flag and value: self._count.append(int(value)) self.total_count_flag = True
[ "def", "set_total_count", "(", "self", ",", "value", ")", ":", "if", "not", "self", ".", "total_count_flag", "and", "value", ":", "self", ".", "_count", ".", "append", "(", "int", "(", "value", ")", ")", "self", ".", "total_count_flag", "=", "True" ]
Setter for count attribute. Set should append only one count per splitted url.
[ "Setter", "for", "count", "attribute", ".", "Set", "should", "append", "only", "one", "count", "per", "splitted", "url", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/api_listing.py#L162-L166
9,063
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasRequest.get_headers
def get_headers(self): """Return header for the HTTP request.""" headers = { "User-Agent": self.http_agent, "Content-Type": "application/json", "Accept": "application/json" } if self.headers: headers.update(self.headers) return headers
python
def get_headers(self): headers = { "User-Agent": self.http_agent, "Content-Type": "application/json", "Accept": "application/json" } if self.headers: headers.update(self.headers) return headers
[ "def", "get_headers", "(", "self", ")", ":", "headers", "=", "{", "\"User-Agent\"", ":", "self", ".", "http_agent", ",", "\"Content-Type\"", ":", "\"application/json\"", ",", "\"Accept\"", ":", "\"application/json\"", "}", "if", "self", ".", "headers", ":", "h...
Return header for the HTTP request.
[ "Return", "header", "for", "the", "HTTP", "request", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L63-L73
9,064
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasRequest.http_method
def http_method(self, method): """ Execute the given HTTP method and returns if it's success or not and the response as a string if not success and as python object after unjson if it's success. """ self.build_url() try: response = self.get_http_method(method) is_success = response.ok try: response_message = response.json() except ValueError: response_message = response.text except requests.exceptions.RequestException as exc: is_success = False response_message = exc.args return is_success, response_message
python
def http_method(self, method): self.build_url() try: response = self.get_http_method(method) is_success = response.ok try: response_message = response.json() except ValueError: response_message = response.text except requests.exceptions.RequestException as exc: is_success = False response_message = exc.args return is_success, response_message
[ "def", "http_method", "(", "self", ",", "method", ")", ":", "self", ".", "build_url", "(", ")", "try", ":", "response", "=", "self", ".", "get_http_method", "(", "method", ")", "is_success", "=", "response", ".", "ok", "try", ":", "response_message", "="...
Execute the given HTTP method and returns if it's success or not and the response as a string if not success and as python object after unjson if it's success.
[ "Execute", "the", "given", "HTTP", "method", "and", "returns", "if", "it", "s", "success", "or", "not", "and", "the", "response", "as", "a", "string", "if", "not", "success", "and", "as", "python", "object", "after", "unjson", "if", "it", "s", "success",...
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L75-L96
9,065
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasRequest.get_http_method
def get_http_method(self, method): """Gets the http method that will be called from the requests library""" return self.http_methods[method](self.url, **self.http_method_args)
python
def get_http_method(self, method): return self.http_methods[method](self.url, **self.http_method_args)
[ "def", "get_http_method", "(", "self", ",", "method", ")", ":", "return", "self", ".", "http_methods", "[", "method", "]", "(", "self", ".", "url", ",", "*", "*", "self", ".", "http_method_args", ")" ]
Gets the http method that will be called from the requests library
[ "Gets", "the", "http", "method", "that", "will", "be", "called", "from", "the", "requests", "library" ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L98-L100
9,066
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasRequest.get
def get(self, **url_params): """ Makes the HTTP GET to the url. """ if url_params: self.http_method_args["params"].update(url_params) return self.http_method("GET")
python
def get(self, **url_params): if url_params: self.http_method_args["params"].update(url_params) return self.http_method("GET")
[ "def", "get", "(", "self", ",", "*", "*", "url_params", ")", ":", "if", "url_params", ":", "self", ".", "http_method_args", "[", "\"params\"", "]", ".", "update", "(", "url_params", ")", "return", "self", ".", "http_method", "(", "\"GET\"", ")" ]
Makes the HTTP GET to the url.
[ "Makes", "the", "HTTP", "GET", "to", "the", "url", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L109-L115
9,067
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasRequest.post
def post(self): """ Makes the HTTP POST to the url sending post_data. """ self._construct_post_data() post_args = {"json": self.post_data} self.http_method_args.update(post_args) return self.http_method("POST")
python
def post(self): self._construct_post_data() post_args = {"json": self.post_data} self.http_method_args.update(post_args) return self.http_method("POST")
[ "def", "post", "(", "self", ")", ":", "self", ".", "_construct_post_data", "(", ")", "post_args", "=", "{", "\"json\"", ":", "self", ".", "post_data", "}", "self", ".", "http_method_args", ".", "update", "(", "post_args", ")", "return", "self", ".", "htt...
Makes the HTTP POST to the url sending post_data.
[ "Makes", "the", "HTTP", "POST", "to", "the", "url", "sending", "post_data", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L117-L126
9,068
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasRequest.clean_time
def clean_time(self, time): """ Transform time field to datetime object if there is any. """ if isinstance(time, int): time = datetime.utcfromtimestamp(time) elif isinstance(time, str): time = parser.parse(time) return time
python
def clean_time(self, time): if isinstance(time, int): time = datetime.utcfromtimestamp(time) elif isinstance(time, str): time = parser.parse(time) return time
[ "def", "clean_time", "(", "self", ",", "time", ")", ":", "if", "isinstance", "(", "time", ",", "int", ")", ":", "time", "=", "datetime", ".", "utcfromtimestamp", "(", "time", ")", "elif", "isinstance", "(", "time", ",", "str", ")", ":", "time", "=", ...
Transform time field to datetime object if there is any.
[ "Transform", "time", "field", "to", "datetime", "object", "if", "there", "is", "any", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L131-L140
9,069
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasCreateRequest._construct_post_data
def _construct_post_data(self): """ Constructs the data structure that is required from the atlas API based on measurements, sources and times user has specified. """ definitions = [msm.build_api_struct() for msm in self.measurements] probes = [source.build_api_struct() for source in self.sources] self.post_data = { "definitions": definitions, "probes": probes, "is_oneoff": self.is_oneoff } if self.is_oneoff: self.post_data.update({"is_oneoff": self.is_oneoff}) if self.start_time: self.post_data.update( {"start_time": int(calendar.timegm(self.start_time.timetuple()))} ) if self.stop_time: self.post_data.update( {"stop_time": int(calendar.timegm(self.stop_time.timetuple()))} ) if self.bill_to: self.post_data.update({"bill_to": self.bill_to})
python
def _construct_post_data(self): definitions = [msm.build_api_struct() for msm in self.measurements] probes = [source.build_api_struct() for source in self.sources] self.post_data = { "definitions": definitions, "probes": probes, "is_oneoff": self.is_oneoff } if self.is_oneoff: self.post_data.update({"is_oneoff": self.is_oneoff}) if self.start_time: self.post_data.update( {"start_time": int(calendar.timegm(self.start_time.timetuple()))} ) if self.stop_time: self.post_data.update( {"stop_time": int(calendar.timegm(self.stop_time.timetuple()))} ) if self.bill_to: self.post_data.update({"bill_to": self.bill_to})
[ "def", "_construct_post_data", "(", "self", ")", ":", "definitions", "=", "[", "msm", ".", "build_api_struct", "(", ")", "for", "msm", "in", "self", ".", "measurements", "]", "probes", "=", "[", "source", ".", "build_api_struct", "(", ")", "for", "source",...
Constructs the data structure that is required from the atlas API based on measurements, sources and times user has specified.
[ "Constructs", "the", "data", "structure", "that", "is", "required", "from", "the", "atlas", "API", "based", "on", "measurements", "sources", "and", "times", "user", "has", "specified", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L180-L206
9,070
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasResultsRequest.clean_probes
def clean_probes(self, probe_ids): """ Checks format of probe ids and transform it to something API understands. """ if isinstance(probe_ids, (tuple, list)): # tuples & lists > x,y,z probe_ids = ",".join([str(_) for _ in probe_ids]) return probe_ids
python
def clean_probes(self, probe_ids): if isinstance(probe_ids, (tuple, list)): # tuples & lists > x,y,z probe_ids = ",".join([str(_) for _ in probe_ids]) return probe_ids
[ "def", "clean_probes", "(", "self", ",", "probe_ids", ")", ":", "if", "isinstance", "(", "probe_ids", ",", "(", "tuple", ",", "list", ")", ")", ":", "# tuples & lists > x,y,z", "probe_ids", "=", "\",\"", ".", "join", "(", "[", "str", "(", "_", ")", "fo...
Checks format of probe ids and transform it to something API understands.
[ "Checks", "format", "of", "probe", "ids", "and", "transform", "it", "to", "something", "API", "understands", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L319-L327
9,071
RIPE-NCC/ripe-atlas-cousteau
ripe/atlas/cousteau/request.py
AtlasResultsRequest.update_http_method_params
def update_http_method_params(self): """ Update HTTP url parameters based on msm_id and query filters if there are any. """ url_params = {} if self.start: url_params.update( {"start": int(calendar.timegm(self.start.timetuple()))} ) if self.stop: url_params.update( {"stop": int(calendar.timegm(self.stop.timetuple()))} ) if self.probe_ids: url_params.update({"probe_ids": self.probe_ids}) self.http_method_args["params"].update(url_params)
python
def update_http_method_params(self): url_params = {} if self.start: url_params.update( {"start": int(calendar.timegm(self.start.timetuple()))} ) if self.stop: url_params.update( {"stop": int(calendar.timegm(self.stop.timetuple()))} ) if self.probe_ids: url_params.update({"probe_ids": self.probe_ids}) self.http_method_args["params"].update(url_params)
[ "def", "update_http_method_params", "(", "self", ")", ":", "url_params", "=", "{", "}", "if", "self", ".", "start", ":", "url_params", ".", "update", "(", "{", "\"start\"", ":", "int", "(", "calendar", ".", "timegm", "(", "self", ".", "start", ".", "ti...
Update HTTP url parameters based on msm_id and query filters if there are any.
[ "Update", "HTTP", "url", "parameters", "based", "on", "msm_id", "and", "query", "filters", "if", "there", "are", "any", "." ]
ffee2556aaa4df86525b88c269bb098de11678ec
https://github.com/RIPE-NCC/ripe-atlas-cousteau/blob/ffee2556aaa4df86525b88c269bb098de11678ec/ripe/atlas/cousteau/request.py#L329-L349
9,072
fuzeman/trakt.py
trakt/interfaces/search.py
SearchInterface.lookup
def lookup(self, id, service=None, media=None, extended=None, **kwargs): """Lookup items by their Trakt, IMDB, TMDB, TVDB, or TVRage ID. **Note:** If you lookup an identifier without a :code:`media` type specified it might return multiple items if the :code:`service` is not globally unique. :param id: Identifier value to lookup :type id: :class:`~python:str` or :class:`~python:int` :param service: Identifier service **Possible values:** - :code:`trakt` - :code:`imdb` - :code:`tmdb` - :code:`tvdb` - :code:`tvrage` :type service: :class:`~python:str` :param media: Desired media type (or :code:`None` to return all matching items) **Possible values:** - :code:`movie` - :code:`show` - :code:`episode` - :code:`person` - :code:`list` :type media: :class:`~python:str` or :class:`~python:list` of :class:`~python:str` :param extended: Level of information to include in response **Possible values:** - :code:`None`: Minimal (e.g. title, year, ids) **(default)** - :code:`full`: Complete :type extended: :class:`~python:str` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Results :rtype: :class:`trakt.objects.media.Media` or :class:`~python:list` of :class:`trakt.objects.media.Media` """ # Expand tuple `id` if type(id) is tuple: if len(id) != 2: raise ValueError() id, service = id # Validate parameters if not service: raise ValueError('Invalid value provided for the "service" parameter') # Build query query = {} if isinstance(media, six.string_types): query['type'] = media elif isinstance(media, list): query['type'] = ','.join(media) if extended: query['extended'] = extended # Send request response = self.http.get( params=[service, id], query=query ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items if not items: return None count = len(items) if count > 1: return SearchMapper.process_many(self.client, items) elif count == 1: return SearchMapper.process(self.client, items[0]) return None
python
def lookup(self, id, service=None, media=None, extended=None, **kwargs): # Expand tuple `id` if type(id) is tuple: if len(id) != 2: raise ValueError() id, service = id # Validate parameters if not service: raise ValueError('Invalid value provided for the "service" parameter') # Build query query = {} if isinstance(media, six.string_types): query['type'] = media elif isinstance(media, list): query['type'] = ','.join(media) if extended: query['extended'] = extended # Send request response = self.http.get( params=[service, id], query=query ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items if not items: return None count = len(items) if count > 1: return SearchMapper.process_many(self.client, items) elif count == 1: return SearchMapper.process(self.client, items[0]) return None
[ "def", "lookup", "(", "self", ",", "id", ",", "service", "=", "None", ",", "media", "=", "None", ",", "extended", "=", "None", ",", "*", "*", "kwargs", ")", ":", "# Expand tuple `id`", "if", "type", "(", "id", ")", "is", "tuple", ":", "if", "len", ...
Lookup items by their Trakt, IMDB, TMDB, TVDB, or TVRage ID. **Note:** If you lookup an identifier without a :code:`media` type specified it might return multiple items if the :code:`service` is not globally unique. :param id: Identifier value to lookup :type id: :class:`~python:str` or :class:`~python:int` :param service: Identifier service **Possible values:** - :code:`trakt` - :code:`imdb` - :code:`tmdb` - :code:`tvdb` - :code:`tvrage` :type service: :class:`~python:str` :param media: Desired media type (or :code:`None` to return all matching items) **Possible values:** - :code:`movie` - :code:`show` - :code:`episode` - :code:`person` - :code:`list` :type media: :class:`~python:str` or :class:`~python:list` of :class:`~python:str` :param extended: Level of information to include in response **Possible values:** - :code:`None`: Minimal (e.g. title, year, ids) **(default)** - :code:`full`: Complete :type extended: :class:`~python:str` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Results :rtype: :class:`trakt.objects.media.Media` or :class:`~python:list` of :class:`trakt.objects.media.Media`
[ "Lookup", "items", "by", "their", "Trakt", "IMDB", "TMDB", "TVDB", "or", "TVRage", "ID", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/search.py#L14-L103
9,073
fuzeman/trakt.py
trakt/interfaces/search.py
SearchInterface.query
def query(self, query, media=None, year=None, fields=None, extended=None, **kwargs): """Search by titles, descriptions, translated titles, aliases, and people. **Note:** Results are ordered by the most relevant score. :param query: Search title or description :type query: :class:`~python:str` :param media: Desired media type (or :code:`None` to return all matching items) **Possible values:** - :code:`movie` - :code:`show` - :code:`episode` - :code:`person` - :code:`list` :type media: :class:`~python:str` or :class:`~python:list` of :class:`~python:str` :param year: Desired media year (or :code:`None` to return all matching items) :type year: :class:`~python:str` or :class:`~python:int` :param fields: Fields to search for :code:`query` (or :code:`None` to search all fields) :type fields: :class:`~python:str` or :class:`~python:list` :param extended: Level of information to include in response **Possible values:** - :code:`None`: Minimal (e.g. title, year, ids) **(default)** - :code:`full`: Complete :type extended: :class:`~python:str` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Results :rtype: :class:`~python:list` of :class:`trakt.objects.media.Media` """ # Validate parameters if not media: warnings.warn( "\"media\" parameter is now required on the Trakt['search'].query() method", DeprecationWarning, stacklevel=2 ) if fields and not media: raise ValueError('"fields" can only be used when the "media" parameter is defined') # Build query query = { 'query': query } if year: query['year'] = year if fields: query['fields'] = fields if extended: query['extended'] = extended # Serialize media items if isinstance(media, list): media = ','.join(media) # Send request response = self.http.get( params=[media], query=query ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items if items is not None: return SearchMapper.process_many(self.client, items) return None
python
def query(self, query, media=None, year=None, fields=None, extended=None, **kwargs): # Validate parameters if not media: warnings.warn( "\"media\" parameter is now required on the Trakt['search'].query() method", DeprecationWarning, stacklevel=2 ) if fields and not media: raise ValueError('"fields" can only be used when the "media" parameter is defined') # Build query query = { 'query': query } if year: query['year'] = year if fields: query['fields'] = fields if extended: query['extended'] = extended # Serialize media items if isinstance(media, list): media = ','.join(media) # Send request response = self.http.get( params=[media], query=query ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items if items is not None: return SearchMapper.process_many(self.client, items) return None
[ "def", "query", "(", "self", ",", "query", ",", "media", "=", "None", ",", "year", "=", "None", ",", "fields", "=", "None", ",", "extended", "=", "None", ",", "*", "*", "kwargs", ")", ":", "# Validate parameters", "if", "not", "media", ":", "warnings...
Search by titles, descriptions, translated titles, aliases, and people. **Note:** Results are ordered by the most relevant score. :param query: Search title or description :type query: :class:`~python:str` :param media: Desired media type (or :code:`None` to return all matching items) **Possible values:** - :code:`movie` - :code:`show` - :code:`episode` - :code:`person` - :code:`list` :type media: :class:`~python:str` or :class:`~python:list` of :class:`~python:str` :param year: Desired media year (or :code:`None` to return all matching items) :type year: :class:`~python:str` or :class:`~python:int` :param fields: Fields to search for :code:`query` (or :code:`None` to search all fields) :type fields: :class:`~python:str` or :class:`~python:list` :param extended: Level of information to include in response **Possible values:** - :code:`None`: Minimal (e.g. title, year, ids) **(default)** - :code:`full`: Complete :type extended: :class:`~python:str` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Results :rtype: :class:`~python:list` of :class:`trakt.objects.media.Media`
[ "Search", "by", "titles", "descriptions", "translated", "titles", "aliases", "and", "people", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/search.py#L105-L187
9,074
fuzeman/trakt.py
trakt/objects/season.py
Season.to_identifier
def to_identifier(self): """Return the season identifier which is compatible with requests that require season definitions. :return: Season identifier/definition :rtype: :class:`~python:dict` """ return { 'number': self.pk, 'episodes': [ episode.to_dict() for episode in self.episodes.values() ] }
python
def to_identifier(self): return { 'number': self.pk, 'episodes': [ episode.to_dict() for episode in self.episodes.values() ] }
[ "def", "to_identifier", "(", "self", ")", ":", "return", "{", "'number'", ":", "self", ".", "pk", ",", "'episodes'", ":", "[", "episode", ".", "to_dict", "(", ")", "for", "episode", "in", "self", ".", "episodes", ".", "values", "(", ")", "]", "}" ]
Return the season identifier which is compatible with requests that require season definitions. :return: Season identifier/definition :rtype: :class:`~python:dict`
[ "Return", "the", "season", "identifier", "which", "is", "compatible", "with", "requests", "that", "require", "season", "definitions", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/season.py#L49-L62
9,075
fuzeman/trakt.py
trakt/objects/season.py
Season.to_dict
def to_dict(self): """Dump season to a dictionary. :return: Season dictionary :rtype: :class:`~python:dict` """ result = self.to_identifier() result.update({ 'ids': dict([ (key, value) for (key, value) in self.keys[1:] # NOTE: keys[0] is the season identifier ]) }) if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) result['in_watchlist'] = self.in_watchlist if self.in_watchlist is not None else 0 # Extended Info if self.first_aired: result['first_aired'] = to_iso8601_datetime(self.first_aired) if self.episode_count: result['episode_count'] = self.episode_count if self.aired_episodes: result['aired_episodes'] = self.aired_episodes return result
python
def to_dict(self): result = self.to_identifier() result.update({ 'ids': dict([ (key, value) for (key, value) in self.keys[1:] # NOTE: keys[0] is the season identifier ]) }) if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) result['in_watchlist'] = self.in_watchlist if self.in_watchlist is not None else 0 # Extended Info if self.first_aired: result['first_aired'] = to_iso8601_datetime(self.first_aired) if self.episode_count: result['episode_count'] = self.episode_count if self.aired_episodes: result['aired_episodes'] = self.aired_episodes return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "self", ".", "to_identifier", "(", ")", "result", ".", "update", "(", "{", "'ids'", ":", "dict", "(", "[", "(", "key", ",", "value", ")", "for", "(", "key", ",", "value", ")", "in", "self", ...
Dump season to a dictionary. :return: Season dictionary :rtype: :class:`~python:dict`
[ "Dump", "season", "to", "a", "dictionary", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/season.py#L69-L100
9,076
fuzeman/trakt.py
trakt/objects/episode.py
Episode.to_dict
def to_dict(self): """Dump episode to a dictionary. :return: Episode dictionary :rtype: :class:`~python:dict` """ result = self.to_identifier() result.update({ 'title': self.title, 'watched': 1 if self.is_watched else 0, 'collected': 1 if self.is_collected else 0, 'plays': self.plays if self.plays is not None else 0, 'in_watchlist': self.in_watchlist if self.in_watchlist is not None else 0, 'progress': self.progress, 'last_watched_at': to_iso8601_datetime(self.last_watched_at), 'collected_at': to_iso8601_datetime(self.collected_at), 'paused_at': to_iso8601_datetime(self.paused_at), 'ids': dict([ (key, value) for (key, value) in self.keys[1:] # NOTE: keys[0] is the (<season>, <episode>) identifier ]) }) if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) # Extended Info if self.first_aired: result['first_aired'] = to_iso8601_datetime(self.first_aired) if self.updated_at: result['updated_at'] = to_iso8601_datetime(self.updated_at) if self.overview: result['overview'] = self.overview if self.available_translations: result['available_translations'] = self.available_translations return result
python
def to_dict(self): result = self.to_identifier() result.update({ 'title': self.title, 'watched': 1 if self.is_watched else 0, 'collected': 1 if self.is_collected else 0, 'plays': self.plays if self.plays is not None else 0, 'in_watchlist': self.in_watchlist if self.in_watchlist is not None else 0, 'progress': self.progress, 'last_watched_at': to_iso8601_datetime(self.last_watched_at), 'collected_at': to_iso8601_datetime(self.collected_at), 'paused_at': to_iso8601_datetime(self.paused_at), 'ids': dict([ (key, value) for (key, value) in self.keys[1:] # NOTE: keys[0] is the (<season>, <episode>) identifier ]) }) if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) # Extended Info if self.first_aired: result['first_aired'] = to_iso8601_datetime(self.first_aired) if self.updated_at: result['updated_at'] = to_iso8601_datetime(self.updated_at) if self.overview: result['overview'] = self.overview if self.available_translations: result['available_translations'] = self.available_translations return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "self", ".", "to_identifier", "(", ")", "result", ".", "update", "(", "{", "'title'", ":", "self", ".", "title", ",", "'watched'", ":", "1", "if", "self", ".", "is_watched", "else", "0", ",", ...
Dump episode to a dictionary. :return: Episode dictionary :rtype: :class:`~python:dict`
[ "Dump", "episode", "to", "a", "dictionary", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/episode.py#L72-L117
9,077
fuzeman/trakt.py
examples/authentication/device.py
Application.on_aborted
def on_aborted(self): """Device authentication aborted. Triggered when device authentication was aborted (either with `DeviceOAuthPoller.stop()` or via the "poll" event) """ print('Authentication aborted') # Authentication aborted self.is_authenticating.acquire() self.is_authenticating.notify_all() self.is_authenticating.release()
python
def on_aborted(self): print('Authentication aborted') # Authentication aborted self.is_authenticating.acquire() self.is_authenticating.notify_all() self.is_authenticating.release()
[ "def", "on_aborted", "(", "self", ")", ":", "print", "(", "'Authentication aborted'", ")", "# Authentication aborted", "self", ".", "is_authenticating", ".", "acquire", "(", ")", "self", ".", "is_authenticating", ".", "notify_all", "(", ")", "self", ".", "is_aut...
Device authentication aborted. Triggered when device authentication was aborted (either with `DeviceOAuthPoller.stop()` or via the "poll" event)
[ "Device", "authentication", "aborted", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/examples/authentication/device.py#L70-L82
9,078
fuzeman/trakt.py
examples/authentication/device.py
Application.on_authenticated
def on_authenticated(self, authorization): """Device authenticated. :param authorization: Authentication token details :type authorization: dict """ # Acquire condition self.is_authenticating.acquire() # Store authorization for future calls self.authorization = authorization print('Authentication successful - authorization: %r' % self.authorization) # Authentication complete self.is_authenticating.notify_all() self.is_authenticating.release()
python
def on_authenticated(self, authorization): # Acquire condition self.is_authenticating.acquire() # Store authorization for future calls self.authorization = authorization print('Authentication successful - authorization: %r' % self.authorization) # Authentication complete self.is_authenticating.notify_all() self.is_authenticating.release()
[ "def", "on_authenticated", "(", "self", ",", "authorization", ")", ":", "# Acquire condition", "self", ".", "is_authenticating", ".", "acquire", "(", ")", "# Store authorization for future calls", "self", ".", "authorization", "=", "authorization", "print", "(", "'Aut...
Device authenticated. :param authorization: Authentication token details :type authorization: dict
[ "Device", "authenticated", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/examples/authentication/device.py#L84-L101
9,079
fuzeman/trakt.py
examples/authentication/device.py
Application.on_expired
def on_expired(self): """Device authentication expired.""" print('Authentication expired') # Authentication expired self.is_authenticating.acquire() self.is_authenticating.notify_all() self.is_authenticating.release()
python
def on_expired(self): print('Authentication expired') # Authentication expired self.is_authenticating.acquire() self.is_authenticating.notify_all() self.is_authenticating.release()
[ "def", "on_expired", "(", "self", ")", ":", "print", "(", "'Authentication expired'", ")", "# Authentication expired", "self", ".", "is_authenticating", ".", "acquire", "(", ")", "self", ".", "is_authenticating", ".", "notify_all", "(", ")", "self", ".", "is_aut...
Device authentication expired.
[ "Device", "authentication", "expired", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/examples/authentication/device.py#L103-L111
9,080
fuzeman/trakt.py
trakt/interfaces/oauth/device.py
DeviceOAuthInterface.poll
def poll(self, device_code, expires_in, interval, **kwargs): """Construct the device authentication poller. :param device_code: Device authentication code :type device_code: str :param expires_in: Device authentication code expiry (in seconds) :type in: int :param interval: Device authentication poll interval :type interval: int :rtype: DeviceOAuthPoller """ return DeviceOAuthPoller(self.client, device_code, expires_in, interval)
python
def poll(self, device_code, expires_in, interval, **kwargs): return DeviceOAuthPoller(self.client, device_code, expires_in, interval)
[ "def", "poll", "(", "self", ",", "device_code", ",", "expires_in", ",", "interval", ",", "*", "*", "kwargs", ")", ":", "return", "DeviceOAuthPoller", "(", "self", ".", "client", ",", "device_code", ",", "expires_in", ",", "interval", ")" ]
Construct the device authentication poller. :param device_code: Device authentication code :type device_code: str :param expires_in: Device authentication code expiry (in seconds) :type in: int :param interval: Device authentication poll interval :type interval: int :rtype: DeviceOAuthPoller
[ "Construct", "the", "device", "authentication", "poller", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/oauth/device.py#L42-L56
9,081
fuzeman/trakt.py
trakt/objects/movie.py
Movie.to_dict
def to_dict(self): """Dump movie to a dictionary. :return: Movie dictionary :rtype: :class:`~python:dict` """ result = self.to_identifier() result.update({ 'watched': 1 if self.is_watched else 0, 'collected': 1 if self.is_collected else 0, 'plays': self.plays if self.plays is not None else 0, 'in_watchlist': self.in_watchlist if self.in_watchlist is not None else 0, 'progress': self.progress, 'last_watched_at': to_iso8601_datetime(self.last_watched_at), 'collected_at': to_iso8601_datetime(self.collected_at), 'paused_at': to_iso8601_datetime(self.paused_at) }) if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) # Extended Info if self.released: result['released'] = to_iso8601_date(self.released) if self.updated_at: result['updated_at'] = to_iso8601_datetime(self.updated_at) if self.overview: result['overview'] = self.overview if self.tagline: result['tagline'] = self.tagline if self.runtime: result['runtime'] = self.runtime if self.certification: result['certification'] = self.certification if self.homepage: result['homepage'] = self.homepage if self.trailer: result['trailer'] = self.trailer if self.language: result['language'] = self.language if self.available_translations: result['available_translations'] = self.available_translations if self.genres: result['genres'] = self.genres return result
python
def to_dict(self): result = self.to_identifier() result.update({ 'watched': 1 if self.is_watched else 0, 'collected': 1 if self.is_collected else 0, 'plays': self.plays if self.plays is not None else 0, 'in_watchlist': self.in_watchlist if self.in_watchlist is not None else 0, 'progress': self.progress, 'last_watched_at': to_iso8601_datetime(self.last_watched_at), 'collected_at': to_iso8601_datetime(self.collected_at), 'paused_at': to_iso8601_datetime(self.paused_at) }) if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) # Extended Info if self.released: result['released'] = to_iso8601_date(self.released) if self.updated_at: result['updated_at'] = to_iso8601_datetime(self.updated_at) if self.overview: result['overview'] = self.overview if self.tagline: result['tagline'] = self.tagline if self.runtime: result['runtime'] = self.runtime if self.certification: result['certification'] = self.certification if self.homepage: result['homepage'] = self.homepage if self.trailer: result['trailer'] = self.trailer if self.language: result['language'] = self.language if self.available_translations: result['available_translations'] = self.available_translations if self.genres: result['genres'] = self.genres return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "self", ".", "to_identifier", "(", ")", "result", ".", "update", "(", "{", "'watched'", ":", "1", "if", "self", ".", "is_watched", "else", "0", ",", "'collected'", ":", "1", "if", "self", ".", ...
Dump movie to a dictionary. :return: Movie dictionary :rtype: :class:`~python:dict`
[ "Dump", "movie", "to", "a", "dictionary", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/movie.py#L123-L183
9,082
fuzeman/trakt.py
trakt/objects/progress.py
Progress.to_dict
def to_dict(self): """Dump progress to a dictionary. :return: Progress dictionary :rtype: :class:`~python:dict` """ result = super(Progress, self).to_dict() label = LABELS['last_progress_change'][self.progress_type] result[label] = to_iso8601_datetime(self.last_progress_change) if self.progress_type == 'watched': result['reset_at'] = self.reset_at result['seasons'] = [ season.to_dict() for season in self.seasons.values() ] if self.hidden_seasons: result['hidden_seasons'] = [ popitems(season.to_dict(), ['number', 'ids']) for season in self.hidden_seasons.values() ] if self.next_episode: result['next_episode'] = popitems(self.next_episode.to_dict(), ['season', 'number', 'title', 'ids']) result['next_episode']['season'] = self.next_episode.keys[0][0] if self.last_episode: result['last_episode'] = popitems(self.last_episode.to_dict(), ['season', 'number', 'title', 'ids']) result['last_episode']['season'] = self.last_episode.keys[0][0] return result
python
def to_dict(self): result = super(Progress, self).to_dict() label = LABELS['last_progress_change'][self.progress_type] result[label] = to_iso8601_datetime(self.last_progress_change) if self.progress_type == 'watched': result['reset_at'] = self.reset_at result['seasons'] = [ season.to_dict() for season in self.seasons.values() ] if self.hidden_seasons: result['hidden_seasons'] = [ popitems(season.to_dict(), ['number', 'ids']) for season in self.hidden_seasons.values() ] if self.next_episode: result['next_episode'] = popitems(self.next_episode.to_dict(), ['season', 'number', 'title', 'ids']) result['next_episode']['season'] = self.next_episode.keys[0][0] if self.last_episode: result['last_episode'] = popitems(self.last_episode.to_dict(), ['season', 'number', 'title', 'ids']) result['last_episode']['season'] = self.last_episode.keys[0][0] return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "super", "(", "Progress", ",", "self", ")", ".", "to_dict", "(", ")", "label", "=", "LABELS", "[", "'last_progress_change'", "]", "[", "self", ".", "progress_type", "]", "result", "[", "label", "]...
Dump progress to a dictionary. :return: Progress dictionary :rtype: :class:`~python:dict`
[ "Dump", "progress", "to", "a", "dictionary", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/progress.py#L108-L142
9,083
fuzeman/trakt.py
trakt/interfaces/scrobble.py
ScrobbleInterface.action
def action(self, action, movie=None, show=None, episode=None, progress=0.0, **kwargs): """Perform scrobble action. :param action: Action to perform (either :code:`start`, :code:`pause` or :code:`stop`) :type action: :class:`~python:str` :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'start', 'progress': 1.25, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict` """ if movie and (show or episode): raise ValueError('Only one media type should be provided') if not movie and not episode: raise ValueError('Missing media item') data = { 'progress': progress, 'app_version': kwargs.pop('app_version', self.client.version), 'app_date': kwargs.pop('app_date', None) } if movie: # TODO validate data['movie'] = movie elif episode: if show: data['show'] = show # TODO validate data['episode'] = episode response = self.http.post( action, data=data, **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) return self.get_data(response, **kwargs)
python
def action(self, action, movie=None, show=None, episode=None, progress=0.0, **kwargs): if movie and (show or episode): raise ValueError('Only one media type should be provided') if not movie and not episode: raise ValueError('Missing media item') data = { 'progress': progress, 'app_version': kwargs.pop('app_version', self.client.version), 'app_date': kwargs.pop('app_date', None) } if movie: # TODO validate data['movie'] = movie elif episode: if show: data['show'] = show # TODO validate data['episode'] = episode response = self.http.post( action, data=data, **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) return self.get_data(response, **kwargs)
[ "def", "action", "(", "self", ",", "action", ",", "movie", "=", "None", ",", "show", "=", "None", ",", "episode", "=", "None", ",", "progress", "=", "0.0", ",", "*", "*", "kwargs", ")", ":", "if", "movie", "and", "(", "show", "or", "episode", ")"...
Perform scrobble action. :param action: Action to perform (either :code:`start`, :code:`pause` or :code:`stop`) :type action: :class:`~python:str` :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'start', 'progress': 1.25, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict`
[ "Perform", "scrobble", "action", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/scrobble.py#L12-L134
9,084
fuzeman/trakt.py
trakt/interfaces/scrobble.py
ScrobbleInterface.start
def start(self, movie=None, show=None, episode=None, progress=0.0, **kwargs): """Send the scrobble "start" action. Use this method when the video initially starts playing or is un-paused. This will remove any playback progress if it exists. **Note:** A watching status will auto expire after the remaining runtime has elapsed. There is no need to re-send every 15 minutes. :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'start', 'progress': 1.25, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict` """ return self.action( 'start', movie, show, episode, progress, **kwargs )
python
def start(self, movie=None, show=None, episode=None, progress=0.0, **kwargs): return self.action( 'start', movie, show, episode, progress, **kwargs )
[ "def", "start", "(", "self", ",", "movie", "=", "None", ",", "show", "=", "None", ",", "episode", "=", "None", ",", "progress", "=", "0.0", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "action", "(", "'start'", ",", "movie", ",", "sh...
Send the scrobble "start" action. Use this method when the video initially starts playing or is un-paused. This will remove any playback progress if it exists. **Note:** A watching status will auto expire after the remaining runtime has elapsed. There is no need to re-send every 15 minutes. :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'start', 'progress': 1.25, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict`
[ "Send", "the", "scrobble", "start", "action", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/scrobble.py#L138-L238
9,085
fuzeman/trakt.py
trakt/interfaces/scrobble.py
ScrobbleInterface.pause
def pause(self, movie=None, show=None, episode=None, progress=0.0, **kwargs): """Send the scrobble "pause' action. Use this method when the video is paused. The playback progress will be saved and :code:`Trakt['sync/playback'].get()` can be used to resume the video from this exact position. Un-pause a video by calling the :code:`Trakt['scrobble'].start()` method again. :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'pause', 'progress': 75, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict` """ return self.action( 'pause', movie, show, episode, progress, **kwargs )
python
def pause(self, movie=None, show=None, episode=None, progress=0.0, **kwargs): return self.action( 'pause', movie, show, episode, progress, **kwargs )
[ "def", "pause", "(", "self", ",", "movie", "=", "None", ",", "show", "=", "None", ",", "episode", "=", "None", ",", "progress", "=", "0.0", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "action", "(", "'pause'", ",", "movie", ",", "sh...
Send the scrobble "pause' action. Use this method when the video is paused. The playback progress will be saved and :code:`Trakt['sync/playback'].get()` can be used to resume the video from this exact position. Un-pause a video by calling the :code:`Trakt['scrobble'].start()` method again. :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'pause', 'progress': 75, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict`
[ "Send", "the", "scrobble", "pause", "action", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/scrobble.py#L242-L340
9,086
fuzeman/trakt.py
trakt/interfaces/scrobble.py
ScrobbleInterface.stop
def stop(self, movie=None, show=None, episode=None, progress=0.0, **kwargs): """Send the scrobble "stop" action. Use this method when the video is stopped or finishes playing on its own. If the progress is above 80%, the video will be scrobbled and the :code:`action` will be set to **scrobble**. If the progress is less than 80%, it will be treated as a *pause* and the :code:`action` will be set to **pause**. The playback progress will be saved and :code:`Trakt['sync/playback'].get()` can be used to resume the video from this exact position. **Note:** If you prefer to use a threshold higher than 80%, you should use :code:`Trakt['scrobble'].pause()` yourself so it doesn't create duplicate scrobbles. :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'scrobble', 'progress': 99.9, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict` """ return self.action( 'stop', movie, show, episode, progress, **kwargs )
python
def stop(self, movie=None, show=None, episode=None, progress=0.0, **kwargs): return self.action( 'stop', movie, show, episode, progress, **kwargs )
[ "def", "stop", "(", "self", ",", "movie", "=", "None", ",", "show", "=", "None", ",", "episode", "=", "None", ",", "progress", "=", "0.0", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "action", "(", "'stop'", ",", "movie", ",", "show...
Send the scrobble "stop" action. Use this method when the video is stopped or finishes playing on its own. If the progress is above 80%, the video will be scrobbled and the :code:`action` will be set to **scrobble**. If the progress is less than 80%, it will be treated as a *pause* and the :code:`action` will be set to **pause**. The playback progress will be saved and :code:`Trakt['sync/playback'].get()` can be used to resume the video from this exact position. **Note:** If you prefer to use a threshold higher than 80%, you should use :code:`Trakt['scrobble'].pause()` yourself so it doesn't create duplicate scrobbles. :param movie: Movie definition (or `None`) **Example:** .. code-block:: python { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'tmdb': 118340 } } :type movie: :class:`~python:dict` :param show: Show definition (or `None`) **Example:** .. code-block:: python { 'title': 'Breaking Bad', 'year': 2008, 'ids': { 'tvdb': 81189 } } :type show: :class:`~python:dict` :param episode: Episode definition (or `None`) **Example:** .. code-block:: python { "season": 3, "number": 11 } :type episode: :class:`~python:dict` :param progress: Current movie/episode progress percentage :type progress: :class:`~python:float` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response (or `None`) **Example:** .. code-block:: python { 'action': 'scrobble', 'progress': 99.9, 'sharing': { 'facebook': true, 'twitter': true, 'tumblr': false }, 'movie': { 'title': 'Guardians of the Galaxy', 'year': 2014, 'ids': { 'trakt': 28, 'slug': 'guardians-of-the-galaxy-2014', 'imdb': 'tt2015381', 'tmdb': 118340 } } } :rtype: :class:`~python:dict`
[ "Send", "the", "scrobble", "stop", "action", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/scrobble.py#L344-L449
9,087
fuzeman/trakt.py
trakt/objects/list/custom.py
CustomList.delete
def delete(self, **kwargs): """Delete the list. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool` """ return self._client['users/*/lists/*'].delete(self.username, self.id, **kwargs)
python
def delete(self, **kwargs): return self._client['users/*/lists/*'].delete(self.username, self.id, **kwargs)
[ "def", "delete", "(", "self", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_client", "[", "'users/*/lists/*'", "]", ".", "delete", "(", "self", ".", "username", ",", "self", ".", "id", ",", "*", "*", "kwargs", ")" ]
Delete the list. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool`
[ "Delete", "the", "list", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/list/custom.py#L86-L96
9,088
fuzeman/trakt.py
trakt/objects/list/custom.py
CustomList.update
def update(self, **kwargs): """Update the list with the current object attributes. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool` """ item = self._client['users/*/lists/*'].update(self.username, self.id, return_type='data', **kwargs) if not item: return False self._update(item) return True
python
def update(self, **kwargs): item = self._client['users/*/lists/*'].update(self.username, self.id, return_type='data', **kwargs) if not item: return False self._update(item) return True
[ "def", "update", "(", "self", ",", "*", "*", "kwargs", ")", ":", "item", "=", "self", ".", "_client", "[", "'users/*/lists/*'", "]", ".", "update", "(", "self", ".", "username", ",", "self", ".", "id", ",", "return_type", "=", "'data'", ",", "*", "...
Update the list with the current object attributes. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool`
[ "Update", "the", "list", "with", "the", "current", "object", "attributes", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/list/custom.py#L98-L114
9,089
fuzeman/trakt.py
trakt/objects/list/custom.py
CustomList.remove
def remove(self, items, **kwargs): """Remove specified items from the list. :param items: Items that should be removed from the list :type items: :class:`~python:list` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response :rtype: :class:`~python:dict` """ return self._client['users/*/lists/*'].remove(self.username, self.id, items, **kwargs)
python
def remove(self, items, **kwargs): return self._client['users/*/lists/*'].remove(self.username, self.id, items, **kwargs)
[ "def", "remove", "(", "self", ",", "items", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_client", "[", "'users/*/lists/*'", "]", ".", "remove", "(", "self", ".", "username", ",", "self", ".", "id", ",", "items", ",", "*", "*", "kwarg...
Remove specified items from the list. :param items: Items that should be removed from the list :type items: :class:`~python:list` :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Response :rtype: :class:`~python:dict`
[ "Remove", "specified", "items", "from", "the", "list", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/list/custom.py#L116-L129
9,090
fuzeman/trakt.py
trakt/objects/list/custom.py
CustomList.like
def like(self, **kwargs): """Like the list. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool` """ return self._client['users/*/lists/*'].like(self.username, self.id, **kwargs)
python
def like(self, **kwargs): return self._client['users/*/lists/*'].like(self.username, self.id, **kwargs)
[ "def", "like", "(", "self", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_client", "[", "'users/*/lists/*'", "]", ".", "like", "(", "self", ".", "username", ",", "self", ".", "id", ",", "*", "*", "kwargs", ")" ]
Like the list. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool`
[ "Like", "the", "list", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/list/custom.py#L135-L145
9,091
fuzeman/trakt.py
trakt/objects/list/custom.py
CustomList.unlike
def unlike(self, **kwargs): """Un-like the list. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool` """ return self._client['users/*/lists/*'].unlike(self.username, self.id, **kwargs)
python
def unlike(self, **kwargs): return self._client['users/*/lists/*'].unlike(self.username, self.id, **kwargs)
[ "def", "unlike", "(", "self", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_client", "[", "'users/*/lists/*'", "]", ".", "unlike", "(", "self", ".", "username", ",", "self", ".", "id", ",", "*", "*", "kwargs", ")" ]
Un-like the list. :param kwargs: Extra request options :type kwargs: :class:`~python:dict` :return: Boolean to indicate if the request was successful :rtype: :class:`~python:bool`
[ "Un", "-", "like", "the", "list", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/list/custom.py#L147-L157
9,092
fuzeman/trakt.py
trakt/interfaces/calendars.py
Base.get
def get(self, source, media, collection=None, start_date=None, days=None, query=None, years=None, genres=None, languages=None, countries=None, runtimes=None, ratings=None, certifications=None, networks=None, status=None, **kwargs): """Retrieve calendar items. The `all` calendar displays info for all shows airing during the specified period. The `my` calendar displays episodes for all shows that have been watched, collected, or watchlisted. :param source: Calendar source (`all` or `my`) :type source: str :param media: Media type (`dvd`, `movies` or `shows`) :type media: str :param collection: Collection type (`new`, `premieres`) :type collection: str or None :param start_date: Start date (defaults to today) :type start_date: datetime or None :param days: Number of days to display (defaults to `7`) :type days: int or None :param query: Search title or description. :type query: str or None :param years: Year or range of years (e.g. `2014`, or `2014-2016`) :type years: int or str or tuple or None :param genres: Genre slugs (e.g. `action`) :type genres: str or list of str or None :param languages: Language codes (e.g. `en`) :type languages: str or list of str or None :param countries: Country codes (e.g. `us`) :type countries: str or list of str or None :param runtimes: Runtime range in minutes (e.g. `30-90`) :type runtimes: str or tuple or None :param ratings: Rating range between `0` and `100` (e.g. `75-100`) :type ratings: str or tuple or None :param certifications: US Content Certification (e.g. `pg-13`, `tv-pg`) :type certifications: str or list of str or None :param networks: (TV) Network name (e.g. `HBO`) :type networks: str or list of str or None :param status: (TV) Show status (e.g. `returning series`, `in production`, ended`) :type status: str or list of str or None :return: Items :rtype: list of trakt.objects.video.Video """ if source not in ['all', 'my']: raise ValueError('Unknown collection type: %s' % (source,)) if media not in ['dvd', 'movies', 'shows']: raise ValueError('Unknown media type: %s' % (media,)) # Default `start_date` to today when only `days` is provided if start_date is None and days: start_date = datetime.utcnow() # Request calendar collection response = self.http.get( '/calendars/%s/%s%s' % ( source, media, ('/' + collection) if collection else '' ), params=[ start_date.strftime('%Y-%m-%d') if start_date else None, days ], query={ 'query': query, 'years': years, 'genres': genres, 'languages': languages, 'countries': countries, 'runtimes': runtimes, 'ratings': ratings, 'certifications': certifications, # TV 'networks': networks, 'status': status }, **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items # Map items if media == 'shows': return SummaryMapper.episodes( self.client, items, parse_show=True ) return SummaryMapper.movies(self.client, items)
python
def get(self, source, media, collection=None, start_date=None, days=None, query=None, years=None, genres=None, languages=None, countries=None, runtimes=None, ratings=None, certifications=None, networks=None, status=None, **kwargs): if source not in ['all', 'my']: raise ValueError('Unknown collection type: %s' % (source,)) if media not in ['dvd', 'movies', 'shows']: raise ValueError('Unknown media type: %s' % (media,)) # Default `start_date` to today when only `days` is provided if start_date is None and days: start_date = datetime.utcnow() # Request calendar collection response = self.http.get( '/calendars/%s/%s%s' % ( source, media, ('/' + collection) if collection else '' ), params=[ start_date.strftime('%Y-%m-%d') if start_date else None, days ], query={ 'query': query, 'years': years, 'genres': genres, 'languages': languages, 'countries': countries, 'runtimes': runtimes, 'ratings': ratings, 'certifications': certifications, # TV 'networks': networks, 'status': status }, **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items # Map items if media == 'shows': return SummaryMapper.episodes( self.client, items, parse_show=True ) return SummaryMapper.movies(self.client, items)
[ "def", "get", "(", "self", ",", "source", ",", "media", ",", "collection", "=", "None", ",", "start_date", "=", "None", ",", "days", "=", "None", ",", "query", "=", "None", ",", "years", "=", "None", ",", "genres", "=", "None", ",", "languages", "=...
Retrieve calendar items. The `all` calendar displays info for all shows airing during the specified period. The `my` calendar displays episodes for all shows that have been watched, collected, or watchlisted. :param source: Calendar source (`all` or `my`) :type source: str :param media: Media type (`dvd`, `movies` or `shows`) :type media: str :param collection: Collection type (`new`, `premieres`) :type collection: str or None :param start_date: Start date (defaults to today) :type start_date: datetime or None :param days: Number of days to display (defaults to `7`) :type days: int or None :param query: Search title or description. :type query: str or None :param years: Year or range of years (e.g. `2014`, or `2014-2016`) :type years: int or str or tuple or None :param genres: Genre slugs (e.g. `action`) :type genres: str or list of str or None :param languages: Language codes (e.g. `en`) :type languages: str or list of str or None :param countries: Country codes (e.g. `us`) :type countries: str or list of str or None :param runtimes: Runtime range in minutes (e.g. `30-90`) :type runtimes: str or tuple or None :param ratings: Rating range between `0` and `100` (e.g. `75-100`) :type ratings: str or tuple or None :param certifications: US Content Certification (e.g. `pg-13`, `tv-pg`) :type certifications: str or list of str or None :param networks: (TV) Network name (e.g. `HBO`) :type networks: str or list of str or None :param status: (TV) Show status (e.g. `returning series`, `in production`, ended`) :type status: str or list of str or None :return: Items :rtype: list of trakt.objects.video.Video
[ "Retrieve", "calendar", "items", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/interfaces/calendars.py#L24-L135
9,093
fuzeman/trakt.py
trakt/objects/show.py
Show.episodes
def episodes(self): """Return a flat episode iterator. :returns: Iterator :code:`((season_num, episode_num), Episode)` :rtype: iterator """ for sk, season in iteritems(self.seasons): # Yield each episode in season for ek, episode in iteritems(season.episodes): yield (sk, ek), episode
python
def episodes(self): for sk, season in iteritems(self.seasons): # Yield each episode in season for ek, episode in iteritems(season.episodes): yield (sk, ek), episode
[ "def", "episodes", "(", "self", ")", ":", "for", "sk", ",", "season", "in", "iteritems", "(", "self", ".", "seasons", ")", ":", "# Yield each episode in season", "for", "ek", ",", "episode", "in", "iteritems", "(", "season", ".", "episodes", ")", ":", "y...
Return a flat episode iterator. :returns: Iterator :code:`((season_num, episode_num), Episode)` :rtype: iterator
[ "Return", "a", "flat", "episode", "iterator", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/show.py#L138-L148
9,094
fuzeman/trakt.py
trakt/objects/show.py
Show.to_dict
def to_dict(self): """Dump show to a dictionary. :return: Show dictionary :rtype: :class:`~python:dict` """ result = self.to_identifier() result['seasons'] = [ season.to_dict() for season in self.seasons.values() ] result['in_watchlist'] = self.in_watchlist if self.in_watchlist is not None else 0 if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) # Extended Info if self.first_aired: result['first_aired'] = to_iso8601_datetime(self.first_aired) if self.updated_at: result['updated_at'] = to_iso8601_datetime(self.updated_at) if self.overview: result['overview'] = self.overview if self.airs: result['airs'] = self.airs if self.runtime: result['runtime'] = self.runtime if self.certification: result['certification'] = self.certification if self.network: result['network'] = self.network if self.country: result['country'] = self.country if self.status: result['status'] = self.status if self.homepage: result['homepage'] = self.homepage if self.language: result['language'] = self.language if self.available_translations: result['available_translations'] = self.available_translations if self.genres: result['genres'] = self.genres if self.aired_episodes: result['aired_episodes'] = self.aired_episodes return result
python
def to_dict(self): result = self.to_identifier() result['seasons'] = [ season.to_dict() for season in self.seasons.values() ] result['in_watchlist'] = self.in_watchlist if self.in_watchlist is not None else 0 if self.rating: result['rating'] = self.rating.value result['rated_at'] = to_iso8601_datetime(self.rating.timestamp) # Extended Info if self.first_aired: result['first_aired'] = to_iso8601_datetime(self.first_aired) if self.updated_at: result['updated_at'] = to_iso8601_datetime(self.updated_at) if self.overview: result['overview'] = self.overview if self.airs: result['airs'] = self.airs if self.runtime: result['runtime'] = self.runtime if self.certification: result['certification'] = self.certification if self.network: result['network'] = self.network if self.country: result['country'] = self.country if self.status: result['status'] = self.status if self.homepage: result['homepage'] = self.homepage if self.language: result['language'] = self.language if self.available_translations: result['available_translations'] = self.available_translations if self.genres: result['genres'] = self.genres if self.aired_episodes: result['aired_episodes'] = self.aired_episodes return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "self", ".", "to_identifier", "(", ")", "result", "[", "'seasons'", "]", "=", "[", "season", ".", "to_dict", "(", ")", "for", "season", "in", "self", ".", "seasons", ".", "values", "(", ")", "...
Dump show to a dictionary. :return: Show dictionary :rtype: :class:`~python:dict`
[ "Dump", "show", "to", "a", "dictionary", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/show.py#L168-L231
9,095
fuzeman/trakt.py
trakt/core/request.py
TraktRequest.construct_url
def construct_url(self): """Construct a full trakt request URI, with `params` and `query`.""" path = [self.path] path.extend(self.params) # Build URL url = self.client.base_url + '/'.join( str(value) for value in path if value ) # Append query parameters (if defined) query = self.encode_query(self.query) if query: url += '?' + query return url
python
def construct_url(self): path = [self.path] path.extend(self.params) # Build URL url = self.client.base_url + '/'.join( str(value) for value in path if value ) # Append query parameters (if defined) query = self.encode_query(self.query) if query: url += '?' + query return url
[ "def", "construct_url", "(", "self", ")", ":", "path", "=", "[", "self", ".", "path", "]", "path", ".", "extend", "(", "self", ".", "params", ")", "# Build URL", "url", "=", "self", ".", "client", ".", "base_url", "+", "'/'", ".", "join", "(", "str...
Construct a full trakt request URI, with `params` and `query`.
[ "Construct", "a", "full", "trakt", "request", "URI", "with", "params", "and", "query", "." ]
14c6b72e3c13ea2975007aeac0c01ad2222b67f3
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/core/request.py#L101-L118
9,096
JamesGardiner/chwrapper
chwrapper/services/search.py
Search.search_officers
def search_officers(self, term, disqualified=False, **kwargs): """Search for officers by name. Args: term (str): Officer name to search on. disqualified (Optional[bool]): True to search for disqualified officers kwargs (dict): additional keywords passed into requests.session.get params keyword. """ search_type = ('officers' if not disqualified else 'disqualified-officers') params = kwargs params['q'] = term baseuri = self._BASE_URI + 'search/{}'.format(search_type) res = self.session.get(baseuri, params=params) self.handle_http_error(res) return res
python
def search_officers(self, term, disqualified=False, **kwargs): search_type = ('officers' if not disqualified else 'disqualified-officers') params = kwargs params['q'] = term baseuri = self._BASE_URI + 'search/{}'.format(search_type) res = self.session.get(baseuri, params=params) self.handle_http_error(res) return res
[ "def", "search_officers", "(", "self", ",", "term", ",", "disqualified", "=", "False", ",", "*", "*", "kwargs", ")", ":", "search_type", "=", "(", "'officers'", "if", "not", "disqualified", "else", "'disqualified-officers'", ")", "params", "=", "kwargs", "pa...
Search for officers by name. Args: term (str): Officer name to search on. disqualified (Optional[bool]): True to search for disqualified officers kwargs (dict): additional keywords passed into requests.session.get params keyword.
[ "Search", "for", "officers", "by", "name", "." ]
50f9cb2f5264c59505e8cc4e45ee6dc5d5669134
https://github.com/JamesGardiner/chwrapper/blob/50f9cb2f5264c59505e8cc4e45ee6dc5d5669134/chwrapper/services/search.py#L68-L85
9,097
JamesGardiner/chwrapper
chwrapper/services/search.py
Search.address
def address(self, num): """Search for company addresses by company number. Args: num (str): Company number to search on. """ url_root = "company/{}/registered-office-address" baseuri = self._BASE_URI + url_root.format(num) res = self.session.get(baseuri) self.handle_http_error(res) return res
python
def address(self, num): url_root = "company/{}/registered-office-address" baseuri = self._BASE_URI + url_root.format(num) res = self.session.get(baseuri) self.handle_http_error(res) return res
[ "def", "address", "(", "self", ",", "num", ")", ":", "url_root", "=", "\"company/{}/registered-office-address\"", "baseuri", "=", "self", ".", "_BASE_URI", "+", "url_root", ".", "format", "(", "num", ")", "res", "=", "self", ".", "session", ".", "get", "("...
Search for company addresses by company number. Args: num (str): Company number to search on.
[ "Search", "for", "company", "addresses", "by", "company", "number", "." ]
50f9cb2f5264c59505e8cc4e45ee6dc5d5669134
https://github.com/JamesGardiner/chwrapper/blob/50f9cb2f5264c59505e8cc4e45ee6dc5d5669134/chwrapper/services/search.py#L100-L110
9,098
JamesGardiner/chwrapper
chwrapper/services/search.py
Search.profile
def profile(self, num): """Search for company profile by company number. Args: num (str): Company number to search on. """ baseuri = self._BASE_URI + "company/{}".format(num) res = self.session.get(baseuri) self.handle_http_error(res) return res
python
def profile(self, num): baseuri = self._BASE_URI + "company/{}".format(num) res = self.session.get(baseuri) self.handle_http_error(res) return res
[ "def", "profile", "(", "self", ",", "num", ")", ":", "baseuri", "=", "self", ".", "_BASE_URI", "+", "\"company/{}\"", ".", "format", "(", "num", ")", "res", "=", "self", ".", "session", ".", "get", "(", "baseuri", ")", "self", ".", "handle_http_error",...
Search for company profile by company number. Args: num (str): Company number to search on.
[ "Search", "for", "company", "profile", "by", "company", "number", "." ]
50f9cb2f5264c59505e8cc4e45ee6dc5d5669134
https://github.com/JamesGardiner/chwrapper/blob/50f9cb2f5264c59505e8cc4e45ee6dc5d5669134/chwrapper/services/search.py#L112-L121
9,099
JamesGardiner/chwrapper
chwrapper/services/search.py
Search.filing_history
def filing_history(self, num, transaction=None, **kwargs): """Search for a company's filling history by company number. Args: num (str): Company number to search on. transaction (Optional[str]): Filing record number. kwargs (dict): additional keywords passed into requests.session.get params keyword. """ baseuri = self._BASE_URI + "company/{}/filing-history".format(num) if transaction is not None: baseuri += "/{}".format(transaction) res = self.session.get(baseuri, params=kwargs) self.handle_http_error(res) return res
python
def filing_history(self, num, transaction=None, **kwargs): baseuri = self._BASE_URI + "company/{}/filing-history".format(num) if transaction is not None: baseuri += "/{}".format(transaction) res = self.session.get(baseuri, params=kwargs) self.handle_http_error(res) return res
[ "def", "filing_history", "(", "self", ",", "num", ",", "transaction", "=", "None", ",", "*", "*", "kwargs", ")", ":", "baseuri", "=", "self", ".", "_BASE_URI", "+", "\"company/{}/filing-history\"", ".", "format", "(", "num", ")", "if", "transaction", "is",...
Search for a company's filling history by company number. Args: num (str): Company number to search on. transaction (Optional[str]): Filing record number. kwargs (dict): additional keywords passed into requests.session.get params keyword.
[ "Search", "for", "a", "company", "s", "filling", "history", "by", "company", "number", "." ]
50f9cb2f5264c59505e8cc4e45ee6dc5d5669134
https://github.com/JamesGardiner/chwrapper/blob/50f9cb2f5264c59505e8cc4e45ee6dc5d5669134/chwrapper/services/search.py#L134-L149