partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | mutable_model_prepared | Make sure all related model class are created and marked as dependency
when a mutable model class is prepared | mutant/contrib/related/management/__init__.py | def mutable_model_prepared(signal, sender, definition, existing_model_class,
**kwargs):
"""
Make sure all related model class are created and marked as dependency
when a mutable model class is prepared
"""
referenced_models = set()
# Collect all model class the obsolet... | def mutable_model_prepared(signal, sender, definition, existing_model_class,
**kwargs):
"""
Make sure all related model class are created and marked as dependency
when a mutable model class is prepared
"""
referenced_models = set()
# Collect all model class the obsolet... | [
"Make",
"sure",
"all",
"related",
"model",
"class",
"are",
"created",
"and",
"marked",
"as",
"dependency",
"when",
"a",
"mutable",
"model",
"class",
"is",
"prepared"
] | charettes/django-mutant | python | https://github.com/charettes/django-mutant/blob/865a1b712ce30501901c4691ce2110ab03f0f93b/mutant/contrib/related/management/__init__.py#L13-L47 | [
"def",
"mutable_model_prepared",
"(",
"signal",
",",
"sender",
",",
"definition",
",",
"existing_model_class",
",",
"*",
"*",
"kwargs",
")",
":",
"referenced_models",
"=",
"set",
"(",
")",
"# Collect all model class the obsolete model class was referring to",
"if",
"exi... | 865a1b712ce30501901c4691ce2110ab03f0f93b |
train | _model_class_from_pk | Helper used to unpickle MutableModel model class from their definition
pk. | mutant/models/model/__init__.py | def _model_class_from_pk(definition_cls, definition_pk):
"""
Helper used to unpickle MutableModel model class from their definition
pk.
"""
try:
return definition_cls.objects.get(pk=definition_pk).model_class()
except definition_cls.DoesNotExist:
pass | def _model_class_from_pk(definition_cls, definition_pk):
"""
Helper used to unpickle MutableModel model class from their definition
pk.
"""
try:
return definition_cls.objects.get(pk=definition_pk).model_class()
except definition_cls.DoesNotExist:
pass | [
"Helper",
"used",
"to",
"unpickle",
"MutableModel",
"model",
"class",
"from",
"their",
"definition",
"pk",
"."
] | charettes/django-mutant | python | https://github.com/charettes/django-mutant/blob/865a1b712ce30501901c4691ce2110ab03f0f93b/mutant/models/model/__init__.py#L30-L38 | [
"def",
"_model_class_from_pk",
"(",
"definition_cls",
",",
"definition_pk",
")",
":",
"try",
":",
"return",
"definition_cls",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"definition_pk",
")",
".",
"model_class",
"(",
")",
"except",
"definition_cls",
".",
"Does... | 865a1b712ce30501901c4691ce2110ab03f0f93b |
train | OrderingFieldDefinition.clean | Make sure the lookup makes sense | mutant/models/model/__init__.py | def clean(self):
"""
Make sure the lookup makes sense
"""
if self.lookup == '?': # Randomly sort
return
else:
lookups = self.lookup.split(LOOKUP_SEP)
opts = self.model_def.model_class()._meta
valid = True
while len(look... | def clean(self):
"""
Make sure the lookup makes sense
"""
if self.lookup == '?': # Randomly sort
return
else:
lookups = self.lookup.split(LOOKUP_SEP)
opts = self.model_def.model_class()._meta
valid = True
while len(look... | [
"Make",
"sure",
"the",
"lookup",
"makes",
"sense"
] | charettes/django-mutant | python | https://github.com/charettes/django-mutant/blob/865a1b712ce30501901c4691ce2110ab03f0f93b/mutant/models/model/__init__.py#L436-L460 | [
"def",
"clean",
"(",
"self",
")",
":",
"if",
"self",
".",
"lookup",
"==",
"'?'",
":",
"# Randomly sort",
"return",
"else",
":",
"lookups",
"=",
"self",
".",
"lookup",
".",
"split",
"(",
"LOOKUP_SEP",
")",
"opts",
"=",
"self",
".",
"model_def",
".",
"... | 865a1b712ce30501901c4691ce2110ab03f0f93b |
train | lorentz_deriv | Compute the time-derivative of a Lorentz system. | make_lorenz_animation.py | def lorentz_deriv((x, y, z), t0, sigma=10., beta=8./3, rho=28.0):
"""Compute the time-derivative of a Lorentz system."""
return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z] | def lorentz_deriv((x, y, z), t0, sigma=10., beta=8./3, rho=28.0):
"""Compute the time-derivative of a Lorentz system."""
return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z] | [
"Compute",
"the",
"time",
"-",
"derivative",
"of",
"a",
"Lorentz",
"system",
"."
] | jakevdp/JSAnimation | python | https://github.com/jakevdp/JSAnimation/blob/d290db11ebb5427769b76fc532f2d10c4ea3391f/make_lorenz_animation.py#L20-L22 | [
"def",
"lorentz_deriv",
"(",
"(",
"x",
",",
"y",
",",
"z",
")",
",",
"t0",
",",
"sigma",
"=",
"10.",
",",
"beta",
"=",
"8.",
"/",
"3",
",",
"rho",
"=",
"28.0",
")",
":",
"return",
"[",
"sigma",
"*",
"(",
"y",
"-",
"x",
")",
",",
"x",
"*",... | d290db11ebb5427769b76fc532f2d10c4ea3391f |
train | buildParser | Builds the parser for reading the command line arguments | scripts/bag_graph.py | def buildParser():
''' Builds the parser for reading the command line arguments'''
parser = argparse.ArgumentParser(description='Bagfile reader')
parser.add_argument('-b', '--bag', help='Bag file to read',
required=True, type=str)
parser.add_argument('-s', '--series',
... | def buildParser():
''' Builds the parser for reading the command line arguments'''
parser = argparse.ArgumentParser(description='Bagfile reader')
parser.add_argument('-b', '--bag', help='Bag file to read',
required=True, type=str)
parser.add_argument('-s', '--series',
... | [
"Builds",
"the",
"parser",
"for",
"reading",
"the",
"command",
"line",
"arguments"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/scripts/bag_graph.py#L10-L24 | [
"def",
"buildParser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Bagfile reader'",
")",
"parser",
".",
"add_argument",
"(",
"'-b'",
",",
"'--bag'",
",",
"help",
"=",
"'Bag file to read'",
",",
"required",
"=",
... | c2af9f22537102696dffdf2e61790362726a8403 |
train | parse_series_args | Return which topics and which field keys need to be examined
for plotting | scripts/bag_graph.py | def parse_series_args(topics, fields):
'''Return which topics and which field keys need to be examined
for plotting'''
keys = {}
for field in fields:
for topic in topics:
if field.startswith(topic):
keys[field] = (topic, field[len(topic) + 1:])
return keys | def parse_series_args(topics, fields):
'''Return which topics and which field keys need to be examined
for plotting'''
keys = {}
for field in fields:
for topic in topics:
if field.startswith(topic):
keys[field] = (topic, field[len(topic) + 1:])
return keys | [
"Return",
"which",
"topics",
"and",
"which",
"field",
"keys",
"need",
"to",
"be",
"examined",
"for",
"plotting"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/scripts/bag_graph.py#L27-L36 | [
"def",
"parse_series_args",
"(",
"topics",
",",
"fields",
")",
":",
"keys",
"=",
"{",
"}",
"for",
"field",
"in",
"fields",
":",
"for",
"topic",
"in",
"topics",
":",
"if",
"field",
".",
"startswith",
"(",
"topic",
")",
":",
"keys",
"[",
"field",
"]",
... | c2af9f22537102696dffdf2e61790362726a8403 |
train | bag_to_dataframe | Read in a rosbag file and create a pandas data frame that
is indexed by the time the message was recorded in the bag.
:bag_name: String name for the bag file
:include: None, String, or List Topics to include in the dataframe
if None all topics added, if string it is used as regular
... | src/rosbag_pandas/rosbag_pandas.py | def bag_to_dataframe(bag_name, include=None, exclude=None, parse_header=False, seconds=False):
'''
Read in a rosbag file and create a pandas data frame that
is indexed by the time the message was recorded in the bag.
:bag_name: String name for the bag file
:include: None, String, or List Topics to... | def bag_to_dataframe(bag_name, include=None, exclude=None, parse_header=False, seconds=False):
'''
Read in a rosbag file and create a pandas data frame that
is indexed by the time the message was recorded in the bag.
:bag_name: String name for the bag file
:include: None, String, or List Topics to... | [
"Read",
"in",
"a",
"rosbag",
"file",
"and",
"create",
"a",
"pandas",
"data",
"frame",
"that",
"is",
"indexed",
"by",
"the",
"time",
"the",
"message",
"was",
"recorded",
"in",
"the",
"bag",
"."
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L15-L98 | [
"def",
"bag_to_dataframe",
"(",
"bag_name",
",",
"include",
"=",
"None",
",",
"exclude",
"=",
"None",
",",
"parse_header",
"=",
"False",
",",
"seconds",
"=",
"False",
")",
":",
"# get list of topics to parse",
"yaml_info",
"=",
"get_bag_info",
"(",
"bag_name",
... | c2af9f22537102696dffdf2e61790362726a8403 |
train | get_length | Find the length (# of rows) in the created dataframe | src/rosbag_pandas/rosbag_pandas.py | def get_length(topics, yaml_info):
'''
Find the length (# of rows) in the created dataframe
'''
total = 0
info = yaml_info['topics']
for topic in topics:
for t in info:
if t['topic'] == topic:
total = total + t['messages']
break
return tota... | def get_length(topics, yaml_info):
'''
Find the length (# of rows) in the created dataframe
'''
total = 0
info = yaml_info['topics']
for topic in topics:
for t in info:
if t['topic'] == topic:
total = total + t['messages']
break
return tota... | [
"Find",
"the",
"length",
"(",
"#",
"of",
"rows",
")",
"in",
"the",
"created",
"dataframe"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L101-L112 | [
"def",
"get_length",
"(",
"topics",
",",
"yaml_info",
")",
":",
"total",
"=",
"0",
"info",
"=",
"yaml_info",
"[",
"'topics'",
"]",
"for",
"topic",
"in",
"topics",
":",
"for",
"t",
"in",
"info",
":",
"if",
"t",
"[",
"'topic'",
"]",
"==",
"topic",
":... | c2af9f22537102696dffdf2e61790362726a8403 |
train | create_data_map | Create a data map for usage when parsing the bag | src/rosbag_pandas/rosbag_pandas.py | def create_data_map(msgs_to_read):
'''
Create a data map for usage when parsing the bag
'''
dmap = {}
for topic in msgs_to_read.keys():
base_name = get_key_name(topic) + '__'
fields = {}
for f in msgs_to_read[topic]:
key = (base_name + f).replace('.', '_')
... | def create_data_map(msgs_to_read):
'''
Create a data map for usage when parsing the bag
'''
dmap = {}
for topic in msgs_to_read.keys():
base_name = get_key_name(topic) + '__'
fields = {}
for f in msgs_to_read[topic]:
key = (base_name + f).replace('.', '_')
... | [
"Create",
"a",
"data",
"map",
"for",
"usage",
"when",
"parsing",
"the",
"bag"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L115-L127 | [
"def",
"create_data_map",
"(",
"msgs_to_read",
")",
":",
"dmap",
"=",
"{",
"}",
"for",
"topic",
"in",
"msgs_to_read",
".",
"keys",
"(",
")",
":",
"base_name",
"=",
"get_key_name",
"(",
"topic",
")",
"+",
"'__'",
"fields",
"=",
"{",
"}",
"for",
"f",
"... | c2af9f22537102696dffdf2e61790362726a8403 |
train | prune_topics | prune the topics. If include is None add all to the set of topics to
use if include is a string regex match that string,
if it is a list use the list
If exclude is None do nothing, if string remove the topics with regex,
if it is a list remove those topics | src/rosbag_pandas/rosbag_pandas.py | def prune_topics(bag_topics, include, exclude):
'''prune the topics. If include is None add all to the set of topics to
use if include is a string regex match that string,
if it is a list use the list
If exclude is None do nothing, if string remove the topics with regex,
if it is a l... | def prune_topics(bag_topics, include, exclude):
'''prune the topics. If include is None add all to the set of topics to
use if include is a string regex match that string,
if it is a list use the list
If exclude is None do nothing, if string remove the topics with regex,
if it is a l... | [
"prune",
"the",
"topics",
".",
"If",
"include",
"is",
"None",
"add",
"all",
"to",
"the",
"set",
"of",
"topics",
"to",
"use",
"if",
"include",
"is",
"a",
"string",
"regex",
"match",
"that",
"string",
"if",
"it",
"is",
"a",
"list",
"use",
"the",
"list"... | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L130-L177 | [
"def",
"prune_topics",
"(",
"bag_topics",
",",
"include",
",",
"exclude",
")",
":",
"topics_to_use",
"=",
"set",
"(",
")",
"# add all of the topics",
"if",
"include",
"is",
"None",
":",
"for",
"t",
"in",
"bag_topics",
":",
"topics_to_use",
".",
"add",
"(",
... | c2af9f22537102696dffdf2e61790362726a8403 |
train | get_msg_info | Get info from all of the messages about what they contain
and will be added to the dataframe | src/rosbag_pandas/rosbag_pandas.py | def get_msg_info(yaml_info, topics, parse_header=True):
'''
Get info from all of the messages about what they contain
and will be added to the dataframe
'''
topic_info = yaml_info['topics']
msgs = {}
classes = {}
for topic in topics:
base_key = get_key_name(topic)
msg_pa... | def get_msg_info(yaml_info, topics, parse_header=True):
'''
Get info from all of the messages about what they contain
and will be added to the dataframe
'''
topic_info = yaml_info['topics']
msgs = {}
classes = {}
for topic in topics:
base_key = get_key_name(topic)
msg_pa... | [
"Get",
"info",
"from",
"all",
"of",
"the",
"messages",
"about",
"what",
"they",
"contain",
"and",
"will",
"be",
"added",
"to",
"the",
"dataframe"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L180-L204 | [
"def",
"get_msg_info",
"(",
"yaml_info",
",",
"topics",
",",
"parse_header",
"=",
"True",
")",
":",
"topic_info",
"=",
"yaml_info",
"[",
"'topics'",
"]",
"msgs",
"=",
"{",
"}",
"classes",
"=",
"{",
"}",
"for",
"topic",
"in",
"topics",
":",
"base_key",
... | c2af9f22537102696dffdf2e61790362726a8403 |
train | get_bag_info | Get uamle dict of the bag information
by calling the subprocess -- used to create correct sized
arrays | src/rosbag_pandas/rosbag_pandas.py | def get_bag_info(bag_file):
'''Get uamle dict of the bag information
by calling the subprocess -- used to create correct sized
arrays'''
# Get the info on the bag
bag_info = yaml.load(subprocess.Popen(
['rosbag', 'info', '--yaml', bag_file],
stdout=subprocess.PIPE).communicate()[0])
... | def get_bag_info(bag_file):
'''Get uamle dict of the bag information
by calling the subprocess -- used to create correct sized
arrays'''
# Get the info on the bag
bag_info = yaml.load(subprocess.Popen(
['rosbag', 'info', '--yaml', bag_file],
stdout=subprocess.PIPE).communicate()[0])
... | [
"Get",
"uamle",
"dict",
"of",
"the",
"bag",
"information",
"by",
"calling",
"the",
"subprocess",
"--",
"used",
"to",
"create",
"correct",
"sized",
"arrays"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L207-L215 | [
"def",
"get_bag_info",
"(",
"bag_file",
")",
":",
"# Get the info on the bag",
"bag_info",
"=",
"yaml",
".",
"load",
"(",
"subprocess",
".",
"Popen",
"(",
"[",
"'rosbag'",
",",
"'info'",
",",
"'--yaml'",
",",
"bag_file",
"]",
",",
"stdout",
"=",
"subprocess"... | c2af9f22537102696dffdf2e61790362726a8403 |
train | get_topics | Returns the names of all of the topics in the bag, and prints them
to stdout if requested | src/rosbag_pandas/rosbag_pandas.py | def get_topics(yaml_info):
''' Returns the names of all of the topics in the bag, and prints them
to stdout if requested
'''
# Pull out the topic info
names = []
# Store all of the topics in a dictionary
topics = yaml_info['topics']
for topic in topics:
names.append(topic['to... | def get_topics(yaml_info):
''' Returns the names of all of the topics in the bag, and prints them
to stdout if requested
'''
# Pull out the topic info
names = []
# Store all of the topics in a dictionary
topics = yaml_info['topics']
for topic in topics:
names.append(topic['to... | [
"Returns",
"the",
"names",
"of",
"all",
"of",
"the",
"topics",
"in",
"the",
"bag",
"and",
"prints",
"them",
"to",
"stdout",
"if",
"requested"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L218-L229 | [
"def",
"get_topics",
"(",
"yaml_info",
")",
":",
"# Pull out the topic info",
"names",
"=",
"[",
"]",
"# Store all of the topics in a dictionary",
"topics",
"=",
"yaml_info",
"[",
"'topics'",
"]",
"for",
"topic",
"in",
"topics",
":",
"names",
".",
"append",
"(",
... | c2af9f22537102696dffdf2e61790362726a8403 |
train | get_base_fields | function to get the full names of every message field in the message | src/rosbag_pandas/rosbag_pandas.py | def get_base_fields(msg, prefix='', parse_header=True):
'''function to get the full names of every message field in the message'''
slots = msg.__slots__
ret_val = []
msg_types = dict()
for i in slots:
slot_msg = getattr(msg, i)
if not parse_header and i == 'header':
conti... | def get_base_fields(msg, prefix='', parse_header=True):
'''function to get the full names of every message field in the message'''
slots = msg.__slots__
ret_val = []
msg_types = dict()
for i in slots:
slot_msg = getattr(msg, i)
if not parse_header and i == 'header':
conti... | [
"function",
"to",
"get",
"the",
"full",
"names",
"of",
"every",
"message",
"field",
"in",
"the",
"message"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L232-L254 | [
"def",
"get_base_fields",
"(",
"msg",
",",
"prefix",
"=",
"''",
",",
"parse_header",
"=",
"True",
")",
":",
"slots",
"=",
"msg",
".",
"__slots__",
"ret_val",
"=",
"[",
"]",
"msg_types",
"=",
"dict",
"(",
")",
"for",
"i",
"in",
"slots",
":",
"slot_msg... | c2af9f22537102696dffdf2e61790362726a8403 |
train | get_message_data | get the datapoint from the dot delimited message field key
e.g. translation.x looks up translation than x and returns the value found
in x | src/rosbag_pandas/rosbag_pandas.py | def get_message_data(msg, key):
'''get the datapoint from the dot delimited message field key
e.g. translation.x looks up translation than x and returns the value found
in x'''
data = msg
paths = key.split('.')
for i in paths:
data = getattr(data, i)
return data | def get_message_data(msg, key):
'''get the datapoint from the dot delimited message field key
e.g. translation.x looks up translation than x and returns the value found
in x'''
data = msg
paths = key.split('.')
for i in paths:
data = getattr(data, i)
return data | [
"get",
"the",
"datapoint",
"from",
"the",
"dot",
"delimited",
"message",
"field",
"key",
"e",
".",
"g",
".",
"translation",
".",
"x",
"looks",
"up",
"translation",
"than",
"x",
"and",
"returns",
"the",
"value",
"found",
"in",
"x"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/src/rosbag_pandas/rosbag_pandas.py#L257-L265 | [
"def",
"get_message_data",
"(",
"msg",
",",
"key",
")",
":",
"data",
"=",
"msg",
"paths",
"=",
"key",
".",
"split",
"(",
"'.'",
")",
"for",
"i",
"in",
"paths",
":",
"data",
"=",
"getattr",
"(",
"data",
",",
"i",
")",
"return",
"data"
] | c2af9f22537102696dffdf2e61790362726a8403 |
train | buildParser | Builds the parser for reading the command line arguments | scripts/bag2csv.py | def buildParser():
''' Builds the parser for reading the command line arguments'''
parser = argparse.ArgumentParser(
description='Script to parse bagfile to csv file')
parser.add_argument('bag', help='Bag file to read',
type=str)
parser.add_argument('-i', '--include',
... | def buildParser():
''' Builds the parser for reading the command line arguments'''
parser = argparse.ArgumentParser(
description='Script to parse bagfile to csv file')
parser.add_argument('bag', help='Bag file to read',
type=str)
parser.add_argument('-i', '--include',
... | [
"Builds",
"the",
"parser",
"for",
"reading",
"the",
"command",
"line",
"arguments"
] | aktaylor08/RosbagPandas | python | https://github.com/aktaylor08/RosbagPandas/blob/c2af9f22537102696dffdf2e61790362726a8403/scripts/bag2csv.py#L11-L32 | [
"def",
"buildParser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Script to parse bagfile to csv file'",
")",
"parser",
".",
"add_argument",
"(",
"'bag'",
",",
"help",
"=",
"'Bag file to read'",
",",
"type",
"=",
"... | c2af9f22537102696dffdf2e61790362726a8403 |
train | Senderable.jsonify_payload | Dump the payload to JSON | webhooks/senders/base.py | def jsonify_payload(self):
""" Dump the payload to JSON """
# Assume already json serialized
if isinstance(self.payload, string_types):
return self.payload
return json.dumps(self.payload, cls=StandardJSONEncoder) | def jsonify_payload(self):
""" Dump the payload to JSON """
# Assume already json serialized
if isinstance(self.payload, string_types):
return self.payload
return json.dumps(self.payload, cls=StandardJSONEncoder) | [
"Dump",
"the",
"payload",
"to",
"JSON"
] | pydanny/webhooks | python | https://github.com/pydanny/webhooks/blob/84aa1c0b8f995308f4f5977270c9a0532abc16cc/webhooks/senders/base.py#L94-L99 | [
"def",
"jsonify_payload",
"(",
"self",
")",
":",
"# Assume already json serialized",
"if",
"isinstance",
"(",
"self",
".",
"payload",
",",
"string_types",
")",
":",
"return",
"self",
".",
"payload",
"return",
"json",
".",
"dumps",
"(",
"self",
".",
"payload",
... | 84aa1c0b8f995308f4f5977270c9a0532abc16cc |
train | Senderable._send | Send the webhook method | webhooks/senders/base.py | def _send(self):
""" Send the webhook method """
payload = self.payload
sending_metadata = {'success': False}
post_attributes = {'timeout': self.timeout}
if self.custom_headers:
post_attributes['headers'] = self.custom_headers
if not post_attributes.get('hea... | def _send(self):
""" Send the webhook method """
payload = self.payload
sending_metadata = {'success': False}
post_attributes = {'timeout': self.timeout}
if self.custom_headers:
post_attributes['headers'] = self.custom_headers
if not post_attributes.get('hea... | [
"Send",
"the",
"webhook",
"method"
] | pydanny/webhooks | python | https://github.com/pydanny/webhooks/blob/84aa1c0b8f995308f4f5977270c9a0532abc16cc/webhooks/senders/base.py#L114-L196 | [
"def",
"_send",
"(",
"self",
")",
":",
"payload",
"=",
"self",
".",
"payload",
"sending_metadata",
"=",
"{",
"'success'",
":",
"False",
"}",
"post_attributes",
"=",
"{",
"'timeout'",
":",
"self",
".",
"timeout",
"}",
"if",
"self",
".",
"custom_headers",
... | 84aa1c0b8f995308f4f5977270c9a0532abc16cc |
train | SenderKeyMessage.verifySignature | :type signatureKey: ECPublicKey | axolotl/protocol/senderkeymessage.py | def verifySignature(self, signatureKey):
"""
:type signatureKey: ECPublicKey
"""
try:
parts = ByteUtil.split(self.serialized,
len(self.serialized) - self.__class__.SIGNATURE_LENGTH,
self.__class__.SIGNATURE... | def verifySignature(self, signatureKey):
"""
:type signatureKey: ECPublicKey
"""
try:
parts = ByteUtil.split(self.serialized,
len(self.serialized) - self.__class__.SIGNATURE_LENGTH,
self.__class__.SIGNATURE... | [
":",
"type",
"signatureKey",
":",
"ECPublicKey"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/protocol/senderkeymessage.py#L76-L88 | [
"def",
"verifySignature",
"(",
"self",
",",
"signatureKey",
")",
":",
"try",
":",
"parts",
"=",
"ByteUtil",
".",
"split",
"(",
"self",
".",
"serialized",
",",
"len",
"(",
"self",
".",
"serialized",
")",
"-",
"self",
".",
"__class__",
".",
"SIGNATURE_LENG... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SenderKeyMessage.getSignature | :type signatureKey: ECPrivateKey
:type serialized: bytearray | axolotl/protocol/senderkeymessage.py | def getSignature(self, signatureKey, serialized):
"""
:type signatureKey: ECPrivateKey
:type serialized: bytearray
"""
try:
return Curve.calculateSignature(signatureKey, serialized)
except InvalidKeyException as e:
raise AssertionError(e) | def getSignature(self, signatureKey, serialized):
"""
:type signatureKey: ECPrivateKey
:type serialized: bytearray
"""
try:
return Curve.calculateSignature(signatureKey, serialized)
except InvalidKeyException as e:
raise AssertionError(e) | [
":",
"type",
"signatureKey",
":",
"ECPrivateKey",
":",
"type",
"serialized",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/protocol/senderkeymessage.py#L90-L98 | [
"def",
"getSignature",
"(",
"self",
",",
"signatureKey",
",",
"serialized",
")",
":",
"try",
":",
"return",
"Curve",
".",
"calculateSignature",
"(",
"signatureKey",
",",
"serialized",
")",
"except",
"InvalidKeyException",
"as",
"e",
":",
"raise",
"AssertionError... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionBuilder.process | :param sessionRecord:
:param message:
:type message: PreKeyWhisperMessage | axolotl/sessionbuilder.py | def process(self, sessionRecord, message):
"""
:param sessionRecord:
:param message:
:type message: PreKeyWhisperMessage
"""
messageVersion = message.getMessageVersion()
theirIdentityKey = message.getIdentityKey()
unsignedPreKeyId = None
if not ... | def process(self, sessionRecord, message):
"""
:param sessionRecord:
:param message:
:type message: PreKeyWhisperMessage
"""
messageVersion = message.getMessageVersion()
theirIdentityKey = message.getIdentityKey()
unsignedPreKeyId = None
if not ... | [
":",
"param",
"sessionRecord",
":",
":",
"param",
"message",
":",
":",
"type",
"message",
":",
"PreKeyWhisperMessage"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessionbuilder.py#L32-L56 | [
"def",
"process",
"(",
"self",
",",
"sessionRecord",
",",
"message",
")",
":",
"messageVersion",
"=",
"message",
".",
"getMessageVersion",
"(",
")",
"theirIdentityKey",
"=",
"message",
".",
"getIdentityKey",
"(",
")",
"unsignedPreKeyId",
"=",
"None",
"if",
"no... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionBuilder.processV2 | :type sessionRecord: SessionRecord
:type message: PreKeyWhisperMessage | axolotl/sessionbuilder.py | def processV2(self, sessionRecord, message):
"""
:type sessionRecord: SessionRecord
:type message: PreKeyWhisperMessage
"""
if message.getPreKeyId() is None:
raise InvalidKeyIdException("V2 message requires one time prekey id!")
if not self.preKeyStore.conta... | def processV2(self, sessionRecord, message):
"""
:type sessionRecord: SessionRecord
:type message: PreKeyWhisperMessage
"""
if message.getPreKeyId() is None:
raise InvalidKeyIdException("V2 message requires one time prekey id!")
if not self.preKeyStore.conta... | [
":",
"type",
"sessionRecord",
":",
"SessionRecord",
":",
"type",
"message",
":",
"PreKeyWhisperMessage"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessionbuilder.py#L58-L98 | [
"def",
"processV2",
"(",
"self",
",",
"sessionRecord",
",",
"message",
")",
":",
"if",
"message",
".",
"getPreKeyId",
"(",
")",
"is",
"None",
":",
"raise",
"InvalidKeyIdException",
"(",
"\"V2 message requires one time prekey id!\"",
")",
"if",
"not",
"self",
"."... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionBuilder.processV3 | :param sessionRecord:
:param message:
:type message: PreKeyWhisperMessage
:return: | axolotl/sessionbuilder.py | def processV3(self, sessionRecord, message):
"""
:param sessionRecord:
:param message:
:type message: PreKeyWhisperMessage
:return:
"""
if sessionRecord.hasSessionState(message.getMessageVersion(), message.getBaseKey().serialize()):
logger.warn("We've... | def processV3(self, sessionRecord, message):
"""
:param sessionRecord:
:param message:
:type message: PreKeyWhisperMessage
:return:
"""
if sessionRecord.hasSessionState(message.getMessageVersion(), message.getBaseKey().serialize()):
logger.warn("We've... | [
":",
"param",
"sessionRecord",
":",
":",
"param",
"message",
":",
":",
"type",
"message",
":",
"PreKeyWhisperMessage",
":",
"return",
":"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessionbuilder.py#L100-L138 | [
"def",
"processV3",
"(",
"self",
",",
"sessionRecord",
",",
"message",
")",
":",
"if",
"sessionRecord",
".",
"hasSessionState",
"(",
"message",
".",
"getMessageVersion",
"(",
")",
",",
"message",
".",
"getBaseKey",
"(",
")",
".",
"serialize",
"(",
")",
")"... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionBuilder.processPreKeyBundle | :type preKey: PreKeyBundle | axolotl/sessionbuilder.py | def processPreKeyBundle(self, preKey):
"""
:type preKey: PreKeyBundle
"""
if not self.identityKeyStore.isTrustedIdentity(self.recipientId, preKey.getIdentityKey()):
raise UntrustedIdentityException(self.recipientId, preKey.getIdentityKey())
if preKey.getSignedPreKey(... | def processPreKeyBundle(self, preKey):
"""
:type preKey: PreKeyBundle
"""
if not self.identityKeyStore.isTrustedIdentity(self.recipientId, preKey.getIdentityKey()):
raise UntrustedIdentityException(self.recipientId, preKey.getIdentityKey())
if preKey.getSignedPreKey(... | [
":",
"type",
"preKey",
":",
"PreKeyBundle"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessionbuilder.py#L140-L186 | [
"def",
"processPreKeyBundle",
"(",
"self",
",",
"preKey",
")",
":",
"if",
"not",
"self",
".",
"identityKeyStore",
".",
"isTrustedIdentity",
"(",
"self",
".",
"recipientId",
",",
"preKey",
".",
"getIdentityKey",
"(",
")",
")",
":",
"raise",
"UntrustedIdentityEx... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | GroupSessionBuilder.process | :type senderKeyName: SenderKeyName
:type senderKeyDistributionMessage: SenderKeyDistributionMessage | axolotl/groups/groupsessionbuilder.py | def process(self, senderKeyName, senderKeyDistributionMessage):
"""
:type senderKeyName: SenderKeyName
:type senderKeyDistributionMessage: SenderKeyDistributionMessage
"""
senderKeyRecord = self.senderKeyStore.loadSenderKey(senderKeyName)
senderKeyRecord.addSenderKeyState... | def process(self, senderKeyName, senderKeyDistributionMessage):
"""
:type senderKeyName: SenderKeyName
:type senderKeyDistributionMessage: SenderKeyDistributionMessage
"""
senderKeyRecord = self.senderKeyStore.loadSenderKey(senderKeyName)
senderKeyRecord.addSenderKeyState... | [
":",
"type",
"senderKeyName",
":",
"SenderKeyName",
":",
"type",
"senderKeyDistributionMessage",
":",
"SenderKeyDistributionMessage"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/groupsessionbuilder.py#L10-L20 | [
"def",
"process",
"(",
"self",
",",
"senderKeyName",
",",
"senderKeyDistributionMessage",
")",
":",
"senderKeyRecord",
"=",
"self",
".",
"senderKeyStore",
".",
"loadSenderKey",
"(",
"senderKeyName",
")",
"senderKeyRecord",
".",
"addSenderKeyState",
"(",
"senderKeyDist... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | GroupSessionBuilder.create | :type senderKeyName: SenderKeyName | axolotl/groups/groupsessionbuilder.py | def create(self, senderKeyName):
"""
:type senderKeyName: SenderKeyName
"""
try:
senderKeyRecord = self.senderKeyStore.loadSenderKey(senderKeyName);
if senderKeyRecord.isEmpty() :
senderKeyRecord.setSenderKeyState(KeyHelper.generateSenderKeyId(),
... | def create(self, senderKeyName):
"""
:type senderKeyName: SenderKeyName
"""
try:
senderKeyRecord = self.senderKeyStore.loadSenderKey(senderKeyName);
if senderKeyRecord.isEmpty() :
senderKeyRecord.setSenderKeyState(KeyHelper.generateSenderKeyId(),
... | [
":",
"type",
"senderKeyName",
":",
"SenderKeyName"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/groupsessionbuilder.py#L23-L44 | [
"def",
"create",
"(",
"self",
",",
"senderKeyName",
")",
":",
"try",
":",
"senderKeyRecord",
"=",
"self",
".",
"senderKeyStore",
".",
"loadSenderKey",
"(",
"senderKeyName",
")",
"if",
"senderKeyRecord",
".",
"isEmpty",
"(",
")",
":",
"senderKeyRecord",
".",
... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | RatchetingSession.initializeSession | :type sessionState: SessionState
:type sessionVersion: int
:type parameters: SymmetricAxolotlParameters | axolotl/ratchet/ratchetingsession.py | def initializeSession(sessionState, sessionVersion, parameters):
"""
:type sessionState: SessionState
:type sessionVersion: int
:type parameters: SymmetricAxolotlParameters
"""
if RatchetingSession.isAlice(parameters.getOurBaseKey().getPublicKey(), parameters.getTheirBase... | def initializeSession(sessionState, sessionVersion, parameters):
"""
:type sessionState: SessionState
:type sessionVersion: int
:type parameters: SymmetricAxolotlParameters
"""
if RatchetingSession.isAlice(parameters.getOurBaseKey().getPublicKey(), parameters.getTheirBase... | [
":",
"type",
"sessionState",
":",
"SessionState",
":",
"type",
"sessionVersion",
":",
"int",
":",
"type",
"parameters",
":",
"SymmetricAxolotlParameters"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/ratchet/ratchetingsession.py#L14-L37 | [
"def",
"initializeSession",
"(",
"sessionState",
",",
"sessionVersion",
",",
"parameters",
")",
":",
"if",
"RatchetingSession",
".",
"isAlice",
"(",
"parameters",
".",
"getOurBaseKey",
"(",
")",
".",
"getPublicKey",
"(",
")",
",",
"parameters",
".",
"getTheirBas... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | RatchetingSession.initializeSessionAsAlice | :type sessionState: SessionState
:type sessionVersion: int
:type parameters: AliceAxolotlParameters | axolotl/ratchet/ratchetingsession.py | def initializeSessionAsAlice(sessionState, sessionVersion, parameters):
"""
:type sessionState: SessionState
:type sessionVersion: int
:type parameters: AliceAxolotlParameters
"""
sessionState.setSessionVersion(sessionVersion)
sessionState.setRemoteIdentityKey(par... | def initializeSessionAsAlice(sessionState, sessionVersion, parameters):
"""
:type sessionState: SessionState
:type sessionVersion: int
:type parameters: AliceAxolotlParameters
"""
sessionState.setSessionVersion(sessionVersion)
sessionState.setRemoteIdentityKey(par... | [
":",
"type",
"sessionState",
":",
"SessionState",
":",
"type",
"sessionVersion",
":",
"int",
":",
"type",
"parameters",
":",
"AliceAxolotlParameters"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/ratchet/ratchetingsession.py#L40-L72 | [
"def",
"initializeSessionAsAlice",
"(",
"sessionState",
",",
"sessionVersion",
",",
"parameters",
")",
":",
"sessionState",
".",
"setSessionVersion",
"(",
"sessionVersion",
")",
"sessionState",
".",
"setRemoteIdentityKey",
"(",
"parameters",
".",
"getTheirIdentityKey",
... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | RatchetingSession.initializeSessionAsBob | :type sessionState: SessionState
:type sessionVersion: int
:type parameters: BobAxolotlParameters | axolotl/ratchet/ratchetingsession.py | def initializeSessionAsBob(sessionState, sessionVersion, parameters):
"""
:type sessionState: SessionState
:type sessionVersion: int
:type parameters: BobAxolotlParameters
"""
sessionState.setSessionVersion(sessionVersion)
sessionState.setRemoteIdentityKey(paramet... | def initializeSessionAsBob(sessionState, sessionVersion, parameters):
"""
:type sessionState: SessionState
:type sessionVersion: int
:type parameters: BobAxolotlParameters
"""
sessionState.setSessionVersion(sessionVersion)
sessionState.setRemoteIdentityKey(paramet... | [
":",
"type",
"sessionState",
":",
"SessionState",
":",
"type",
"sessionVersion",
":",
"int",
":",
"type",
"parameters",
":",
"BobAxolotlParameters"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/ratchet/ratchetingsession.py#L75-L104 | [
"def",
"initializeSessionAsBob",
"(",
"sessionState",
",",
"sessionVersion",
",",
"parameters",
")",
":",
"sessionState",
".",
"setSessionVersion",
"(",
"sessionVersion",
")",
"sessionState",
".",
"setRemoteIdentityKey",
"(",
"parameters",
".",
"getTheirIdentityKey",
"(... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SenderKeyRecord.addSenderKeyState | :type id: int
:type iteration: int
:type chainKey: bytearray
:type signatureKey: ECPublicKey | axolotl/groups/state/senderkeyrecord.py | def addSenderKeyState(self, id, iteration, chainKey, signatureKey):
"""
:type id: int
:type iteration: int
:type chainKey: bytearray
:type signatureKey: ECPublicKey
"""
self.senderKeyStates.append(SenderKeyState(id, iteration, chainKey, signatureKey)) | def addSenderKeyState(self, id, iteration, chainKey, signatureKey):
"""
:type id: int
:type iteration: int
:type chainKey: bytearray
:type signatureKey: ECPublicKey
"""
self.senderKeyStates.append(SenderKeyState(id, iteration, chainKey, signatureKey)) | [
":",
"type",
"id",
":",
"int",
":",
"type",
"iteration",
":",
"int",
":",
"type",
"chainKey",
":",
"bytearray",
":",
"type",
"signatureKey",
":",
"ECPublicKey"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/state/senderkeyrecord.py#L35-L42 | [
"def",
"addSenderKeyState",
"(",
"self",
",",
"id",
",",
"iteration",
",",
"chainKey",
",",
"signatureKey",
")",
":",
"self",
".",
"senderKeyStates",
".",
"append",
"(",
"SenderKeyState",
"(",
"id",
",",
"iteration",
",",
"chainKey",
",",
"signatureKey",
")"... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SenderKeyRecord.setSenderKeyState | :type id: int
:type iteration: int
:type chainKey: bytearray
:type signatureKey: ECKeyPair | axolotl/groups/state/senderkeyrecord.py | def setSenderKeyState(self, id, iteration, chainKey, signatureKey):
"""
:type id: int
:type iteration: int
:type chainKey: bytearray
:type signatureKey: ECKeyPair
"""
del self.senderKeyStates[:]
self.senderKeyStates.append(SenderKeyState(id, iteration, cha... | def setSenderKeyState(self, id, iteration, chainKey, signatureKey):
"""
:type id: int
:type iteration: int
:type chainKey: bytearray
:type signatureKey: ECKeyPair
"""
del self.senderKeyStates[:]
self.senderKeyStates.append(SenderKeyState(id, iteration, cha... | [
":",
"type",
"id",
":",
"int",
":",
"type",
"iteration",
":",
"int",
":",
"type",
"chainKey",
":",
"bytearray",
":",
"type",
"signatureKey",
":",
"ECKeyPair"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/state/senderkeyrecord.py#L44-L52 | [
"def",
"setSenderKeyState",
"(",
"self",
",",
"id",
",",
"iteration",
",",
"chainKey",
",",
"signatureKey",
")",
":",
"del",
"self",
".",
"senderKeyStates",
"[",
":",
"]",
"self",
".",
"senderKeyStates",
".",
"append",
"(",
"SenderKeyState",
"(",
"id",
","... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionCipher.encrypt | :type paddedMessage: str | axolotl/sessioncipher.py | def encrypt(self, paddedMessage):
"""
:type paddedMessage: str
"""
# TODO: make this less ugly and python 2 and 3 compatible
# paddedMessage = bytearray(paddedMessage.encode() if (sys.version_info >= (3, 0) and not type(paddedMessage) in (bytes, bytearray)) or type(paddedMessage)... | def encrypt(self, paddedMessage):
"""
:type paddedMessage: str
"""
# TODO: make this less ugly and python 2 and 3 compatible
# paddedMessage = bytearray(paddedMessage.encode() if (sys.version_info >= (3, 0) and not type(paddedMessage) in (bytes, bytearray)) or type(paddedMessage)... | [
":",
"type",
"paddedMessage",
":",
"str"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessioncipher.py#L34-L72 | [
"def",
"encrypt",
"(",
"self",
",",
"paddedMessage",
")",
":",
"# TODO: make this less ugly and python 2 and 3 compatible",
"# paddedMessage = bytearray(paddedMessage.encode() if (sys.version_info >= (3, 0) and not type(paddedMessage) in (bytes, bytearray)) or type(paddedMessage) is unicode else p... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionCipher.decryptMsg | :type ciphertext: WhisperMessage
:type textMsg: Bool set this to False if you are decrypting bytes
instead of string | axolotl/sessioncipher.py | def decryptMsg(self, ciphertext, textMsg=True):
"""
:type ciphertext: WhisperMessage
:type textMsg: Bool set this to False if you are decrypting bytes
instead of string
"""
if not self.sessionStore.containsSession(self.recipientId, self.deviceId):
... | def decryptMsg(self, ciphertext, textMsg=True):
"""
:type ciphertext: WhisperMessage
:type textMsg: Bool set this to False if you are decrypting bytes
instead of string
"""
if not self.sessionStore.containsSession(self.recipientId, self.deviceId):
... | [
":",
"type",
"ciphertext",
":",
"WhisperMessage",
":",
"type",
"textMsg",
":",
"Bool",
"set",
"this",
"to",
"False",
"if",
"you",
"are",
"decrypting",
"bytes",
"instead",
"of",
"string"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessioncipher.py#L74-L89 | [
"def",
"decryptMsg",
"(",
"self",
",",
"ciphertext",
",",
"textMsg",
"=",
"True",
")",
":",
"if",
"not",
"self",
".",
"sessionStore",
".",
"containsSession",
"(",
"self",
".",
"recipientId",
",",
"self",
".",
"deviceId",
")",
":",
"raise",
"NoSessionExcept... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionCipher.decryptPkmsg | :type ciphertext: PreKeyWhisperMessage | axolotl/sessioncipher.py | def decryptPkmsg(self, ciphertext, textMsg=True):
"""
:type ciphertext: PreKeyWhisperMessage
"""
sessionRecord = self.sessionStore.loadSession(self.recipientId, self.deviceId)
unsignedPreKeyId = self.sessionBuilder.process(sessionRecord, ciphertext)
plaintext = self.decry... | def decryptPkmsg(self, ciphertext, textMsg=True):
"""
:type ciphertext: PreKeyWhisperMessage
"""
sessionRecord = self.sessionStore.loadSession(self.recipientId, self.deviceId)
unsignedPreKeyId = self.sessionBuilder.process(sessionRecord, ciphertext)
plaintext = self.decry... | [
":",
"type",
"ciphertext",
":",
"PreKeyWhisperMessage"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessioncipher.py#L91-L105 | [
"def",
"decryptPkmsg",
"(",
"self",
",",
"ciphertext",
",",
"textMsg",
"=",
"True",
")",
":",
"sessionRecord",
"=",
"self",
".",
"sessionStore",
".",
"loadSession",
"(",
"self",
".",
"recipientId",
",",
"self",
".",
"deviceId",
")",
"unsignedPreKeyId",
"=",
... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionCipher.decryptWithSessionRecord | :type sessionRecord: SessionRecord
:type cipherText: WhisperMessage | axolotl/sessioncipher.py | def decryptWithSessionRecord(self, sessionRecord, cipherText):
"""
:type sessionRecord: SessionRecord
:type cipherText: WhisperMessage
"""
previousStates = sessionRecord.getPreviousSessionStates()
exceptions = []
try:
sessionState = SessionState(sessi... | def decryptWithSessionRecord(self, sessionRecord, cipherText):
"""
:type sessionRecord: SessionRecord
:type cipherText: WhisperMessage
"""
previousStates = sessionRecord.getPreviousSessionStates()
exceptions = []
try:
sessionState = SessionState(sessi... | [
":",
"type",
"sessionRecord",
":",
"SessionRecord",
":",
"type",
"cipherText",
":",
"WhisperMessage"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessioncipher.py#L107-L134 | [
"def",
"decryptWithSessionRecord",
"(",
"self",
",",
"sessionRecord",
",",
"cipherText",
")",
":",
"previousStates",
"=",
"sessionRecord",
".",
"getPreviousSessionStates",
"(",
")",
"exceptions",
"=",
"[",
"]",
"try",
":",
"sessionState",
"=",
"SessionState",
"(",... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionCipher.getCiphertext | :type version: int
:type messageKeys: MessageKeys
:type plainText: bytearray | axolotl/sessioncipher.py | def getCiphertext(self, version, messageKeys, plainText):
"""
:type version: int
:type messageKeys: MessageKeys
:type plainText: bytearray
"""
cipher = None
if version >= 3:
cipher = self.getCipher(messageKeys.getCipherKey(), messageKeys.getIv())
... | def getCiphertext(self, version, messageKeys, plainText):
"""
:type version: int
:type messageKeys: MessageKeys
:type plainText: bytearray
"""
cipher = None
if version >= 3:
cipher = self.getCipher(messageKeys.getCipherKey(), messageKeys.getIv())
... | [
":",
"type",
"version",
":",
"int",
":",
"type",
"messageKeys",
":",
"MessageKeys",
":",
"type",
"plainText",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/sessioncipher.py#L197-L209 | [
"def",
"getCiphertext",
"(",
"self",
",",
"version",
",",
"messageKeys",
",",
"plainText",
")",
":",
"cipher",
"=",
"None",
"if",
"version",
">=",
"3",
":",
"cipher",
"=",
"self",
".",
"getCipher",
"(",
"messageKeys",
".",
"getCipherKey",
"(",
")",
",",
... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | Curve.calculateAgreement | :type publicKey: ECPublicKey
:type privateKey: ECPrivateKey | axolotl/ecc/curve.py | def calculateAgreement(publicKey, privateKey):
"""
:type publicKey: ECPublicKey
:type privateKey: ECPrivateKey
"""
if publicKey.getType() != privateKey.getType():
raise InvalidKeyException("Public and private keys must be of the same type!")
if publicKey.getT... | def calculateAgreement(publicKey, privateKey):
"""
:type publicKey: ECPublicKey
:type privateKey: ECPrivateKey
"""
if publicKey.getType() != privateKey.getType():
raise InvalidKeyException("Public and private keys must be of the same type!")
if publicKey.getT... | [
":",
"type",
"publicKey",
":",
"ECPublicKey",
":",
"type",
"privateKey",
":",
"ECPrivateKey"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/ecc/curve.py#L53-L64 | [
"def",
"calculateAgreement",
"(",
"publicKey",
",",
"privateKey",
")",
":",
"if",
"publicKey",
".",
"getType",
"(",
")",
"!=",
"privateKey",
".",
"getType",
"(",
")",
":",
"raise",
"InvalidKeyException",
"(",
"\"Public and private keys must be of the same type!\"",
... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | Curve.verifySignature | :type ecPublicSigningKey: ECPublicKey
:type message: bytearray
:type signature: bytearray | axolotl/ecc/curve.py | def verifySignature(ecPublicSigningKey, message, signature):
"""
:type ecPublicSigningKey: ECPublicKey
:type message: bytearray
:type signature: bytearray
"""
if ecPublicSigningKey.getType() == Curve.DJB_TYPE:
result = _curve.verifySignature(ecPublicSigningKe... | def verifySignature(ecPublicSigningKey, message, signature):
"""
:type ecPublicSigningKey: ECPublicKey
:type message: bytearray
:type signature: bytearray
"""
if ecPublicSigningKey.getType() == Curve.DJB_TYPE:
result = _curve.verifySignature(ecPublicSigningKe... | [
":",
"type",
"ecPublicSigningKey",
":",
"ECPublicKey",
":",
"type",
"message",
":",
"bytearray",
":",
"type",
"signature",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/ecc/curve.py#L67-L78 | [
"def",
"verifySignature",
"(",
"ecPublicSigningKey",
",",
"message",
",",
"signature",
")",
":",
"if",
"ecPublicSigningKey",
".",
"getType",
"(",
")",
"==",
"Curve",
".",
"DJB_TYPE",
":",
"result",
"=",
"_curve",
".",
"verifySignature",
"(",
"ecPublicSigningKey"... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | Curve.calculateSignature | :type privateSigningKey: ECPrivateKey
:type message: bytearray | axolotl/ecc/curve.py | def calculateSignature(privateSigningKey, message):
"""
:type privateSigningKey: ECPrivateKey
:type message: bytearray
"""
if privateSigningKey.getType() == Curve.DJB_TYPE:
rand = os.urandom(64)
res = _curve.calculateSignature(rand, privateSigningKey.getP... | def calculateSignature(privateSigningKey, message):
"""
:type privateSigningKey: ECPrivateKey
:type message: bytearray
"""
if privateSigningKey.getType() == Curve.DJB_TYPE:
rand = os.urandom(64)
res = _curve.calculateSignature(rand, privateSigningKey.getP... | [
":",
"type",
"privateSigningKey",
":",
"ECPrivateKey",
":",
"type",
"message",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/ecc/curve.py#L81-L91 | [
"def",
"calculateSignature",
"(",
"privateSigningKey",
",",
"message",
")",
":",
"if",
"privateSigningKey",
".",
"getType",
"(",
")",
"==",
"Curve",
".",
"DJB_TYPE",
":",
"rand",
"=",
"os",
".",
"urandom",
"(",
"64",
")",
"res",
"=",
"_curve",
".",
"calc... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | GroupCipher.encrypt | :type paddedPlaintext: str | axolotl/groups/groupcipher.py | def encrypt(self, paddedPlaintext):
"""
:type paddedPlaintext: str
"""
# TODO: make this less ugly and python 2 and 3 compatible
# paddedMessage = bytearray(paddedMessage.encode() if (sys.version_info >= (3, 0) and not type(paddedMessage) in (bytes, bytearray)) or type(paddedMess... | def encrypt(self, paddedPlaintext):
"""
:type paddedPlaintext: str
"""
# TODO: make this less ugly and python 2 and 3 compatible
# paddedMessage = bytearray(paddedMessage.encode() if (sys.version_info >= (3, 0) and not type(paddedMessage) in (bytes, bytearray)) or type(paddedMess... | [
":",
"type",
"paddedPlaintext",
":",
"str"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/groupcipher.py#L23-L50 | [
"def",
"encrypt",
"(",
"self",
",",
"paddedPlaintext",
")",
":",
"# TODO: make this less ugly and python 2 and 3 compatible",
"# paddedMessage = bytearray(paddedMessage.encode() if (sys.version_info >= (3, 0) and not type(paddedMessage) in (bytes, bytearray)) or type(paddedMessage) is unicode else... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | GroupCipher.decrypt | :type senderKeyMessageBytes: bytearray | axolotl/groups/groupcipher.py | def decrypt(self, senderKeyMessageBytes):
"""
:type senderKeyMessageBytes: bytearray
"""
try:
record = self.senderKeyStore.loadSenderKey(self.senderKeyName)
if record.isEmpty():
raise NoSessionException("No sender key for: %s" % self.senderKeyName)... | def decrypt(self, senderKeyMessageBytes):
"""
:type senderKeyMessageBytes: bytearray
"""
try:
record = self.senderKeyStore.loadSenderKey(self.senderKeyName)
if record.isEmpty():
raise NoSessionException("No sender key for: %s" % self.senderKeyName)... | [
":",
"type",
"senderKeyMessageBytes",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/groupcipher.py#L52-L73 | [
"def",
"decrypt",
"(",
"self",
",",
"senderKeyMessageBytes",
")",
":",
"try",
":",
"record",
"=",
"self",
".",
"senderKeyStore",
".",
"loadSenderKey",
"(",
"self",
".",
"senderKeyName",
")",
"if",
"record",
".",
"isEmpty",
"(",
")",
":",
"raise",
"NoSessio... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | GroupCipher.getPlainText | :type iv: bytearray
:type key: bytearray
:type ciphertext: bytearray | axolotl/groups/groupcipher.py | def getPlainText(self, iv, key, ciphertext):
"""
:type iv: bytearray
:type key: bytearray
:type ciphertext: bytearray
"""
try:
cipher = AESCipher(key, iv)
plaintext = cipher.decrypt(ciphertext)
if sys.version_info >= (3, 0):
... | def getPlainText(self, iv, key, ciphertext):
"""
:type iv: bytearray
:type key: bytearray
:type ciphertext: bytearray
"""
try:
cipher = AESCipher(key, iv)
plaintext = cipher.decrypt(ciphertext)
if sys.version_info >= (3, 0):
... | [
":",
"type",
"iv",
":",
"bytearray",
":",
"type",
"key",
":",
"bytearray",
":",
"type",
"ciphertext",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/groupcipher.py#L95-L108 | [
"def",
"getPlainText",
"(",
"self",
",",
"iv",
",",
"key",
",",
"ciphertext",
")",
":",
"try",
":",
"cipher",
"=",
"AESCipher",
"(",
"key",
",",
"iv",
")",
"plaintext",
"=",
"cipher",
".",
"decrypt",
"(",
"ciphertext",
")",
"if",
"sys",
".",
"version... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | GroupCipher.getCipherText | :type iv: bytearray
:type key: bytearray
:type plaintext: bytearray | axolotl/groups/groupcipher.py | def getCipherText(self, iv, key, plaintext):
"""
:type iv: bytearray
:type key: bytearray
:type plaintext: bytearray
"""
cipher = AESCipher(key, iv)
return cipher.encrypt(bytes(plaintext)) | def getCipherText(self, iv, key, plaintext):
"""
:type iv: bytearray
:type key: bytearray
:type plaintext: bytearray
"""
cipher = AESCipher(key, iv)
return cipher.encrypt(bytes(plaintext)) | [
":",
"type",
"iv",
":",
"bytearray",
":",
"type",
"key",
":",
"bytearray",
":",
"type",
"plaintext",
":",
"bytearray"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/groups/groupcipher.py#L110-L117 | [
"def",
"getCipherText",
"(",
"self",
",",
"iv",
",",
"key",
",",
"plaintext",
")",
":",
"cipher",
"=",
"AESCipher",
"(",
"key",
",",
"iv",
")",
"return",
"cipher",
".",
"encrypt",
"(",
"bytes",
"(",
"plaintext",
")",
")"
] | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionState.setPendingKeyExchange | :type sequence: int
:type ourBaseKey: ECKeyPair
:type ourRatchetKey: ECKeyPair
:type ourIdentityKey: IdentityKeyPair | axolotl/state/sessionstate.py | def setPendingKeyExchange(self, sequence, ourBaseKey, ourRatchetKey, ourIdentityKey):
"""
:type sequence: int
:type ourBaseKey: ECKeyPair
:type ourRatchetKey: ECKeyPair
:type ourIdentityKey: IdentityKeyPair
"""
structure = self.sessionStructure.PendingKeyExchange... | def setPendingKeyExchange(self, sequence, ourBaseKey, ourRatchetKey, ourIdentityKey):
"""
:type sequence: int
:type ourBaseKey: ECKeyPair
:type ourRatchetKey: ECKeyPair
:type ourIdentityKey: IdentityKeyPair
"""
structure = self.sessionStructure.PendingKeyExchange... | [
":",
"type",
"sequence",
":",
"int",
":",
"type",
"ourBaseKey",
":",
"ECKeyPair",
":",
"type",
"ourRatchetKey",
":",
"ECKeyPair",
":",
"type",
"ourIdentityKey",
":",
"IdentityKeyPair"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/state/sessionstate.py#L194-L210 | [
"def",
"setPendingKeyExchange",
"(",
"self",
",",
"sequence",
",",
"ourBaseKey",
",",
"ourRatchetKey",
",",
"ourIdentityKey",
")",
":",
"structure",
"=",
"self",
".",
"sessionStructure",
".",
"PendingKeyExchange",
"(",
")",
"structure",
".",
"sequence",
"=",
"se... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | SessionState.setUnacknowledgedPreKeyMessage | :type preKeyId: int
:type signedPreKeyId: int
:type baseKey: ECPublicKey | axolotl/state/sessionstate.py | def setUnacknowledgedPreKeyMessage(self, preKeyId, signedPreKeyId, baseKey):
"""
:type preKeyId: int
:type signedPreKeyId: int
:type baseKey: ECPublicKey
"""
self.sessionStructure.pendingPreKey.signedPreKeyId = signedPreKeyId
self.sessionStructure.pendingPreKey.ba... | def setUnacknowledgedPreKeyMessage(self, preKeyId, signedPreKeyId, baseKey):
"""
:type preKeyId: int
:type signedPreKeyId: int
:type baseKey: ECPublicKey
"""
self.sessionStructure.pendingPreKey.signedPreKeyId = signedPreKeyId
self.sessionStructure.pendingPreKey.ba... | [
":",
"type",
"preKeyId",
":",
"int",
":",
"type",
"signedPreKeyId",
":",
"int",
":",
"type",
"baseKey",
":",
"ECPublicKey"
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/state/sessionstate.py#L234-L244 | [
"def",
"setUnacknowledgedPreKeyMessage",
"(",
"self",
",",
"preKeyId",
",",
"signedPreKeyId",
",",
"baseKey",
")",
":",
"self",
".",
"sessionStructure",
".",
"pendingPreKey",
".",
"signedPreKeyId",
"=",
"signedPreKeyId",
"self",
".",
"sessionStructure",
".",
"pendin... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | KeyHelper.generateIdentityKeyPair | Generate an identity key pair. Clients should only do this once,
at install time.
@return the generated IdentityKeyPair. | axolotl/util/keyhelper.py | def generateIdentityKeyPair():
"""
Generate an identity key pair. Clients should only do this once,
at install time.
@return the generated IdentityKeyPair.
"""
keyPair = Curve.generateKeyPair()
publicKey = IdentityKey(keyPair.getPublicKey())
serialized = ... | def generateIdentityKeyPair():
"""
Generate an identity key pair. Clients should only do this once,
at install time.
@return the generated IdentityKeyPair.
"""
keyPair = Curve.generateKeyPair()
publicKey = IdentityKey(keyPair.getPublicKey())
serialized = ... | [
"Generate",
"an",
"identity",
"key",
"pair",
".",
"Clients",
"should",
"only",
"do",
"this",
"once",
"at",
"install",
"time",
"."
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/util/keyhelper.py#L21-L34 | [
"def",
"generateIdentityKeyPair",
"(",
")",
":",
"keyPair",
"=",
"Curve",
".",
"generateKeyPair",
"(",
")",
"publicKey",
"=",
"IdentityKey",
"(",
"keyPair",
".",
"getPublicKey",
"(",
")",
")",
"serialized",
"=",
"'0a21056e8936e8367f768a7bba008ade7cf58407bdc7a6aae293e2... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | KeyHelper.generatePreKeys | Generate a list of PreKeys. Clients should do this at install time, and
subsequently any time the list of PreKeys stored on the server runs low.
PreKey IDs are shorts, so they will eventually be repeated. Clients should
store PreKeys in a circular buffer, so that they are repeated as infreque... | axolotl/util/keyhelper.py | def generatePreKeys(start, count):
"""
Generate a list of PreKeys. Clients should do this at install time, and
subsequently any time the list of PreKeys stored on the server runs low.
PreKey IDs are shorts, so they will eventually be repeated. Clients should
store PreKeys in a... | def generatePreKeys(start, count):
"""
Generate a list of PreKeys. Clients should do this at install time, and
subsequently any time the list of PreKeys stored on the server runs low.
PreKey IDs are shorts, so they will eventually be repeated. Clients should
store PreKeys in a... | [
"Generate",
"a",
"list",
"of",
"PreKeys",
".",
"Clients",
"should",
"do",
"this",
"at",
"install",
"time",
"and",
"subsequently",
"any",
"time",
"the",
"list",
"of",
"PreKeys",
"stored",
"on",
"the",
"server",
"runs",
"low",
"."
] | tgalal/python-axolotl | python | https://github.com/tgalal/python-axolotl/blob/0c681af4b756f556e23a9bf961abfbc6f82800cc/axolotl/util/keyhelper.py#L54-L73 | [
"def",
"generatePreKeys",
"(",
"start",
",",
"count",
")",
":",
"results",
"=",
"[",
"]",
"start",
"-=",
"1",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"count",
")",
":",
"preKeyId",
"=",
"(",
"(",
"start",
"+",
"i",
")",
"%",
"(",
"Medium",
".... | 0c681af4b756f556e23a9bf961abfbc6f82800cc |
train | Enum.choices | Choices for Enum
:return: List of tuples (<value>, <human-readable value>)
:rtype: list | django_enumfield/enum.py | def choices(cls, blank=False):
""" Choices for Enum
:return: List of tuples (<value>, <human-readable value>)
:rtype: list
"""
choices = sorted([(key, value) for key, value in cls.values.items()], key=lambda x: x[0])
if blank:
choices.insert(0, ('', Enum.Value... | def choices(cls, blank=False):
""" Choices for Enum
:return: List of tuples (<value>, <human-readable value>)
:rtype: list
"""
choices = sorted([(key, value) for key, value in cls.values.items()], key=lambda x: x[0])
if blank:
choices.insert(0, ('', Enum.Value... | [
"Choices",
"for",
"Enum",
":",
"return",
":",
"List",
"of",
"tuples",
"(",
"<value",
">",
"<human",
"-",
"readable",
"value",
">",
")",
":",
"rtype",
":",
"list"
] | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/enum.py#L69-L77 | [
"def",
"choices",
"(",
"cls",
",",
"blank",
"=",
"False",
")",
":",
"choices",
"=",
"sorted",
"(",
"[",
"(",
"key",
",",
"value",
")",
"for",
"key",
",",
"value",
"in",
"cls",
".",
"values",
".",
"items",
"(",
")",
"]",
",",
"key",
"=",
"lambda... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | Enum.get | Get Enum.Value object matching the value argument.
:param name_or_numeric: Integer value or attribute name
:type name_or_numeric: int or str
:rtype: Enum.Value | django_enumfield/enum.py | def get(cls, name_or_numeric):
""" Get Enum.Value object matching the value argument.
:param name_or_numeric: Integer value or attribute name
:type name_or_numeric: int or str
:rtype: Enum.Value
"""
if isinstance(name_or_numeric, six.string_types):
name_or_num... | def get(cls, name_or_numeric):
""" Get Enum.Value object matching the value argument.
:param name_or_numeric: Integer value or attribute name
:type name_or_numeric: int or str
:rtype: Enum.Value
"""
if isinstance(name_or_numeric, six.string_types):
name_or_num... | [
"Get",
"Enum",
".",
"Value",
"object",
"matching",
"the",
"value",
"argument",
".",
":",
"param",
"name_or_numeric",
":",
"Integer",
"value",
"or",
"attribute",
"name",
":",
"type",
"name_or_numeric",
":",
"int",
"or",
"str",
":",
"rtype",
":",
"Enum",
"."... | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/enum.py#L105-L114 | [
"def",
"get",
"(",
"cls",
",",
"name_or_numeric",
")",
":",
"if",
"isinstance",
"(",
"name_or_numeric",
",",
"six",
".",
"string_types",
")",
":",
"name_or_numeric",
"=",
"getattr",
"(",
"cls",
",",
"name_or_numeric",
".",
"upper",
"(",
")",
")",
"return",... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | Enum.items | :return: List of tuples consisting of every enum value in the form [('NAME', value), ...]
:rtype: list | django_enumfield/enum.py | def items(cls):
"""
:return: List of tuples consisting of every enum value in the form [('NAME', value), ...]
:rtype: list
"""
items = [(value.name, key) for key, value in cls.values.items()]
return sorted(items, key=lambda x: x[1]) | def items(cls):
"""
:return: List of tuples consisting of every enum value in the form [('NAME', value), ...]
:rtype: list
"""
items = [(value.name, key) for key, value in cls.values.items()]
return sorted(items, key=lambda x: x[1]) | [
":",
"return",
":",
"List",
"of",
"tuples",
"consisting",
"of",
"every",
"enum",
"value",
"in",
"the",
"form",
"[",
"(",
"NAME",
"value",
")",
"...",
"]",
":",
"rtype",
":",
"list"
] | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/enum.py#L137-L143 | [
"def",
"items",
"(",
"cls",
")",
":",
"items",
"=",
"[",
"(",
"value",
".",
"name",
",",
"key",
")",
"for",
"key",
",",
"value",
"in",
"cls",
".",
"values",
".",
"items",
"(",
")",
"]",
"return",
"sorted",
"(",
"items",
",",
"key",
"=",
"lambda... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | Enum.is_valid_transition | Will check if to_value is a valid transition from from_value. Returns true if it is a valid transition.
:param from_value: Start transition point
:param to_value: End transition point
:type from_value: int
:type to_value: int
:return: Success flag
:rtype: bool | django_enumfield/enum.py | def is_valid_transition(cls, from_value, to_value):
""" Will check if to_value is a valid transition from from_value. Returns true if it is a valid transition.
:param from_value: Start transition point
:param to_value: End transition point
:type from_value: int
:type to_value: in... | def is_valid_transition(cls, from_value, to_value):
""" Will check if to_value is a valid transition from from_value. Returns true if it is a valid transition.
:param from_value: Start transition point
:param to_value: End transition point
:type from_value: int
:type to_value: in... | [
"Will",
"check",
"if",
"to_value",
"is",
"a",
"valid",
"transition",
"from",
"from_value",
".",
"Returns",
"true",
"if",
"it",
"is",
"a",
"valid",
"transition",
".",
":",
"param",
"from_value",
":",
"Start",
"transition",
"point",
":",
"param",
"to_value",
... | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/enum.py#L146-L158 | [
"def",
"is_valid_transition",
"(",
"cls",
",",
"from_value",
",",
"to_value",
")",
":",
"try",
":",
"return",
"from_value",
"==",
"to_value",
"or",
"from_value",
"in",
"cls",
".",
"transition_origins",
"(",
"to_value",
")",
"except",
"KeyError",
":",
"return",... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | EnumField._setup_validation | User a customer setter for the field to validate new value against the old one.
The current value is set as '_enum_[att_name]' on the model instance. | django_enumfield/db/fields.py | def _setup_validation(self, sender, **kwargs):
"""
User a customer setter for the field to validate new value against the old one.
The current value is set as '_enum_[att_name]' on the model instance.
"""
att_name = self.get_attname()
private_att_name = '_enum_%s' % att_n... | def _setup_validation(self, sender, **kwargs):
"""
User a customer setter for the field to validate new value against the old one.
The current value is set as '_enum_[att_name]' on the model instance.
"""
att_name = self.get_attname()
private_att_name = '_enum_%s' % att_n... | [
"User",
"a",
"customer",
"setter",
"for",
"the",
"field",
"to",
"validate",
"new",
"value",
"against",
"the",
"old",
"one",
".",
"The",
"current",
"value",
"is",
"set",
"as",
"_enum_",
"[",
"att_name",
"]",
"on",
"the",
"model",
"instance",
"."
] | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/db/fields.py#L27-L57 | [
"def",
"_setup_validation",
"(",
"self",
",",
"sender",
",",
"*",
"*",
"kwargs",
")",
":",
"att_name",
"=",
"self",
".",
"get_attname",
"(",
")",
"private_att_name",
"=",
"'_enum_%s'",
"%",
"att_name",
"enum",
"=",
"self",
".",
"enum",
"def",
"set_enum",
... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | validate_valid_transition | Validate that to_value is a valid choice and that to_value is a valid transition from from_value. | django_enumfield/validators.py | def validate_valid_transition(enum, from_value, to_value):
"""
Validate that to_value is a valid choice and that to_value is a valid transition from from_value.
"""
validate_available_choice(enum, to_value)
if hasattr(enum, '_transitions') and not enum.is_valid_transition(from_value, to_value):
... | def validate_valid_transition(enum, from_value, to_value):
"""
Validate that to_value is a valid choice and that to_value is a valid transition from from_value.
"""
validate_available_choice(enum, to_value)
if hasattr(enum, '_transitions') and not enum.is_valid_transition(from_value, to_value):
... | [
"Validate",
"that",
"to_value",
"is",
"a",
"valid",
"choice",
"and",
"that",
"to_value",
"is",
"a",
"valid",
"transition",
"from",
"from_value",
"."
] | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/validators.py#L7-L18 | [
"def",
"validate_valid_transition",
"(",
"enum",
",",
"from_value",
",",
"to_value",
")",
":",
"validate_available_choice",
"(",
"enum",
",",
"to_value",
")",
"if",
"hasattr",
"(",
"enum",
",",
"'_transitions'",
")",
"and",
"not",
"enum",
".",
"is_valid_transiti... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | validate_available_choice | Validate that to_value is defined as a value in enum. | django_enumfield/validators.py | def validate_available_choice(enum, to_value):
"""
Validate that to_value is defined as a value in enum.
"""
if to_value is None:
return
if type(to_value) is not int:
try:
to_value = int(to_value)
except ValueError:
message_str = "'{value}' cannot be ... | def validate_available_choice(enum, to_value):
"""
Validate that to_value is defined as a value in enum.
"""
if to_value is None:
return
if type(to_value) is not int:
try:
to_value = int(to_value)
except ValueError:
message_str = "'{value}' cannot be ... | [
"Validate",
"that",
"to_value",
"is",
"defined",
"as",
"a",
"value",
"in",
"enum",
"."
] | 5monkeys/django-enumfield | python | https://github.com/5monkeys/django-enumfield/blob/6cf20c0fba013d39960af0f4d2c9a3b399955eb3/django_enumfield/validators.py#L21-L38 | [
"def",
"validate_available_choice",
"(",
"enum",
",",
"to_value",
")",
":",
"if",
"to_value",
"is",
"None",
":",
"return",
"if",
"type",
"(",
"to_value",
")",
"is",
"not",
"int",
":",
"try",
":",
"to_value",
"=",
"int",
"(",
"to_value",
")",
"except",
... | 6cf20c0fba013d39960af0f4d2c9a3b399955eb3 |
train | NXOSDriver._get_diff | Get a diff between running config and a proposed file. | napalm_nxos/nxos.py | def _get_diff(self, cp_file):
"""Get a diff between running config and a proposed file."""
diff = []
self._create_sot_file()
diff_out = self.device.show(
'show diff rollback-patch file {0} file {1}'.format(
'sot_file', self.replace_file.split('/')[-1]), raw_te... | def _get_diff(self, cp_file):
"""Get a diff between running config and a proposed file."""
diff = []
self._create_sot_file()
diff_out = self.device.show(
'show diff rollback-patch file {0} file {1}'.format(
'sot_file', self.replace_file.split('/')[-1]), raw_te... | [
"Get",
"a",
"diff",
"between",
"running",
"config",
"and",
"a",
"proposed",
"file",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos/nxos.py#L252-L270 | [
"def",
"_get_diff",
"(",
"self",
",",
"cp_file",
")",
":",
"diff",
"=",
"[",
"]",
"self",
".",
"_create_sot_file",
"(",
")",
"diff_out",
"=",
"self",
".",
"device",
".",
"show",
"(",
"'show diff rollback-patch file {0} file {1}'",
".",
"format",
"(",
"'sot_f... | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | NXOSDriver._save_config | Save the current running config to the given file. | napalm_nxos/nxos.py | def _save_config(self, filename):
"""Save the current running config to the given file."""
self.device.show('checkpoint file {}'.format(filename), raw_text=True) | def _save_config(self, filename):
"""Save the current running config to the given file."""
self.device.show('checkpoint file {}'.format(filename), raw_text=True) | [
"Save",
"the",
"current",
"running",
"config",
"to",
"the",
"given",
"file",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos/nxos.py#L305-L307 | [
"def",
"_save_config",
"(",
"self",
",",
"filename",
")",
":",
"self",
".",
"device",
".",
"show",
"(",
"'checkpoint file {}'",
".",
"format",
"(",
"filename",
")",
",",
"raw_text",
"=",
"True",
")"
] | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | JunOSDriver.open | Open the connection wit the device. | napalm_junos/junos.py | def open(self):
"""Open the connection wit the device."""
try:
self.device.open()
except ConnectTimeoutError as cte:
raise ConnectionException(cte.message)
self.device.timeout = self.timeout
self.device._conn._session.transport.set_keepalive(self.keepalive... | def open(self):
"""Open the connection wit the device."""
try:
self.device.open()
except ConnectTimeoutError as cte:
raise ConnectionException(cte.message)
self.device.timeout = self.timeout
self.device._conn._session.transport.set_keepalive(self.keepalive... | [
"Open",
"the",
"connection",
"wit",
"the",
"device",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L104-L118 | [
"def",
"open",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"device",
".",
"open",
"(",
")",
"except",
"ConnectTimeoutError",
"as",
"cte",
":",
"raise",
"ConnectionException",
"(",
"cte",
".",
"message",
")",
"self",
".",
"device",
".",
"timeout",
"... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver._lock | Lock the config DB. | napalm_junos/junos.py | def _lock(self):
"""Lock the config DB."""
if not self.locked:
self.device.cu.lock()
self.locked = True | def _lock(self):
"""Lock the config DB."""
if not self.locked:
self.device.cu.lock()
self.locked = True | [
"Lock",
"the",
"config",
"DB",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L126-L130 | [
"def",
"_lock",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"locked",
":",
"self",
".",
"device",
".",
"cu",
".",
"lock",
"(",
")",
"self",
".",
"locked",
"=",
"True"
] | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver._unlock | Unlock the config DB. | napalm_junos/junos.py | def _unlock(self):
"""Unlock the config DB."""
if self.locked:
self.device.cu.unlock()
self.locked = False | def _unlock(self):
"""Unlock the config DB."""
if self.locked:
self.device.cu.unlock()
self.locked = False | [
"Unlock",
"the",
"config",
"DB",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L132-L136 | [
"def",
"_unlock",
"(",
"self",
")",
":",
"if",
"self",
".",
"locked",
":",
"self",
".",
"device",
".",
"cu",
".",
"unlock",
"(",
")",
"self",
".",
"locked",
"=",
"False"
] | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.compare_config | Compare candidate config with running. | napalm_junos/junos.py | def compare_config(self):
"""Compare candidate config with running."""
diff = self.device.cu.diff()
if diff is None:
return ''
else:
return diff.strip() | def compare_config(self):
"""Compare candidate config with running."""
diff = self.device.cu.diff()
if diff is None:
return ''
else:
return diff.strip() | [
"Compare",
"candidate",
"config",
"with",
"running",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L229-L236 | [
"def",
"compare_config",
"(",
"self",
")",
":",
"diff",
"=",
"self",
".",
"device",
".",
"cu",
".",
"diff",
"(",
")",
"if",
"diff",
"is",
"None",
":",
"return",
"''",
"else",
":",
"return",
"diff",
".",
"strip",
"(",
")"
] | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.commit_config | Commit configuration. | napalm_junos/junos.py | def commit_config(self):
"""Commit configuration."""
self.device.cu.commit(ignore_warning=self.ignore_warning)
if not self.config_lock:
self._unlock() | def commit_config(self):
"""Commit configuration."""
self.device.cu.commit(ignore_warning=self.ignore_warning)
if not self.config_lock:
self._unlock() | [
"Commit",
"configuration",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L238-L242 | [
"def",
"commit_config",
"(",
"self",
")",
":",
"self",
".",
"device",
".",
"cu",
".",
"commit",
"(",
"ignore_warning",
"=",
"self",
".",
"ignore_warning",
")",
"if",
"not",
"self",
".",
"config_lock",
":",
"self",
".",
"_unlock",
"(",
")"
] | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.discard_config | Discard changes (rollback 0). | napalm_junos/junos.py | def discard_config(self):
"""Discard changes (rollback 0)."""
self.device.cu.rollback(rb_id=0)
if not self.config_lock:
self._unlock() | def discard_config(self):
"""Discard changes (rollback 0)."""
self.device.cu.rollback(rb_id=0)
if not self.config_lock:
self._unlock() | [
"Discard",
"changes",
"(",
"rollback",
"0",
")",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L244-L248 | [
"def",
"discard_config",
"(",
"self",
")",
":",
"self",
".",
"device",
".",
"cu",
".",
"rollback",
"(",
"rb_id",
"=",
"0",
")",
"if",
"not",
"self",
".",
"config_lock",
":",
"self",
".",
"_unlock",
"(",
")"
] | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_facts | Return facts of the device. | napalm_junos/junos.py | def get_facts(self):
"""Return facts of the device."""
output = self.device.facts
uptime = self.device.uptime or -1
interfaces = junos_views.junos_iface_table(self.device)
interfaces.get()
interface_list = interfaces.keys()
return {
'vendor': u'Juni... | def get_facts(self):
"""Return facts of the device."""
output = self.device.facts
uptime = self.device.uptime or -1
interfaces = junos_views.junos_iface_table(self.device)
interfaces.get()
interface_list = interfaces.keys()
return {
'vendor': u'Juni... | [
"Return",
"facts",
"of",
"the",
"device",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L255-L274 | [
"def",
"get_facts",
"(",
"self",
")",
":",
"output",
"=",
"self",
".",
"device",
".",
"facts",
"uptime",
"=",
"self",
".",
"device",
".",
"uptime",
"or",
"-",
"1",
"interfaces",
"=",
"junos_views",
".",
"junos_iface_table",
"(",
"self",
".",
"device",
... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_interfaces | Return interfaces details. | napalm_junos/junos.py | def get_interfaces(self):
"""Return interfaces details."""
result = {}
interfaces = junos_views.junos_iface_table(self.device)
interfaces.get()
# convert all the tuples to our pre-defined dict structure
for iface in interfaces.keys():
result[iface] = {
... | def get_interfaces(self):
"""Return interfaces details."""
result = {}
interfaces = junos_views.junos_iface_table(self.device)
interfaces.get()
# convert all the tuples to our pre-defined dict structure
for iface in interfaces.keys():
result[iface] = {
... | [
"Return",
"interfaces",
"details",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L276-L309 | [
"def",
"get_interfaces",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"interfaces",
"=",
"junos_views",
".",
"junos_iface_table",
"(",
"self",
".",
"device",
")",
"interfaces",
".",
"get",
"(",
")",
"# convert all the tuples to our pre-defined dict structure",
... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver._get_address_family | Function to derive address family from a junos table name.
:params table: The name of the routing table
:returns: address family | napalm_junos/junos.py | def _get_address_family(table):
"""
Function to derive address family from a junos table name.
:params table: The name of the routing table
:returns: address family
"""
address_family_mapping = {
'inet': 'ipv4',
'inet6': 'ipv6',
'inetf... | def _get_address_family(table):
"""
Function to derive address family from a junos table name.
:params table: The name of the routing table
:returns: address family
"""
address_family_mapping = {
'inet': 'ipv4',
'inet6': 'ipv6',
'inetf... | [
"Function",
"to",
"derive",
"address",
"family",
"from",
"a",
"junos",
"table",
"name",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L451-L468 | [
"def",
"_get_address_family",
"(",
"table",
")",
":",
"address_family_mapping",
"=",
"{",
"'inet'",
":",
"'ipv4'",
",",
"'inet6'",
":",
"'ipv6'",
",",
"'inetflow'",
":",
"'flow'",
"}",
"family",
"=",
"table",
".",
"split",
"(",
"'.'",
")",
"[",
"-",
"2",... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_bgp_neighbors | Return BGP neighbors details. | napalm_junos/junos.py | def get_bgp_neighbors(self):
"""Return BGP neighbors details."""
bgp_neighbor_data = {}
default_neighbor_details = {
'local_as': 0,
'remote_as': 0,
'remote_id': '',
'is_up': False,
'is_enabled': False,
'description': '',
... | def get_bgp_neighbors(self):
"""Return BGP neighbors details."""
bgp_neighbor_data = {}
default_neighbor_details = {
'local_as': 0,
'remote_as': 0,
'remote_id': '',
'is_up': False,
'is_enabled': False,
'description': '',
... | [
"Return",
"BGP",
"neighbors",
"details",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L516-L628 | [
"def",
"get_bgp_neighbors",
"(",
"self",
")",
":",
"bgp_neighbor_data",
"=",
"{",
"}",
"default_neighbor_details",
"=",
"{",
"'local_as'",
":",
"0",
",",
"'remote_as'",
":",
"0",
",",
"'remote_id'",
":",
"''",
",",
"'is_up'",
":",
"False",
",",
"'is_enabled'... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_lldp_neighbors | Return LLDP neighbors details. | napalm_junos/junos.py | def get_lldp_neighbors(self):
"""Return LLDP neighbors details."""
lldp = junos_views.junos_lldp_table(self.device)
try:
lldp.get()
except RpcError as rpcerr:
# this assumes the library runs in an environment
# able to handle logs
# otherwi... | def get_lldp_neighbors(self):
"""Return LLDP neighbors details."""
lldp = junos_views.junos_lldp_table(self.device)
try:
lldp.get()
except RpcError as rpcerr:
# this assumes the library runs in an environment
# able to handle logs
# otherwi... | [
"Return",
"LLDP",
"neighbors",
"details",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L630-L650 | [
"def",
"get_lldp_neighbors",
"(",
"self",
")",
":",
"lldp",
"=",
"junos_views",
".",
"junos_lldp_table",
"(",
"self",
".",
"device",
")",
"try",
":",
"lldp",
".",
"get",
"(",
")",
"except",
"RpcError",
"as",
"rpcerr",
":",
"# this assumes the library runs in a... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_lldp_neighbors_detail | Detailed view of the LLDP neighbors. | napalm_junos/junos.py | def get_lldp_neighbors_detail(self, interface=''):
"""Detailed view of the LLDP neighbors."""
lldp_neighbors = {}
lldp_table = junos_views.junos_lldp_neighbors_detail_table(self.device)
try:
lldp_table.get()
except RpcError as rpcerr:
# this assumes the l... | def get_lldp_neighbors_detail(self, interface=''):
"""Detailed view of the LLDP neighbors."""
lldp_neighbors = {}
lldp_table = junos_views.junos_lldp_neighbors_detail_table(self.device)
try:
lldp_table.get()
except RpcError as rpcerr:
# this assumes the l... | [
"Detailed",
"view",
"of",
"the",
"LLDP",
"neighbors",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L652-L698 | [
"def",
"get_lldp_neighbors_detail",
"(",
"self",
",",
"interface",
"=",
"''",
")",
":",
"lldp_neighbors",
"=",
"{",
"}",
"lldp_table",
"=",
"junos_views",
".",
"junos_lldp_neighbors_detail_table",
"(",
"self",
".",
"device",
")",
"try",
":",
"lldp_table",
".",
... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_arp_table | Return the ARP table. | napalm_junos/junos.py | def get_arp_table(self):
"""Return the ARP table."""
# could use ArpTable
# from jnpr.junos.op.phyport import ArpTable
# and simply use it
# but
# we need:
# - filters
# - group by VLAN ID
# - hostname & TTE fields as well
arp_table ... | def get_arp_table(self):
"""Return the ARP table."""
# could use ArpTable
# from jnpr.junos.op.phyport import ArpTable
# and simply use it
# but
# we need:
# - filters
# - group by VLAN ID
# - hostname & TTE fields as well
arp_table ... | [
"Return",
"the",
"ARP",
"table",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1198-L1223 | [
"def",
"get_arp_table",
"(",
"self",
")",
":",
"# could use ArpTable",
"# from jnpr.junos.op.phyport import ArpTable",
"# and simply use it",
"# but",
"# we need:",
"# - filters",
"# - group by VLAN ID",
"# - hostname & TTE fields as well",
"arp_table",
"=",
"[",
"]",
"arp_... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_ntp_peers | Return the NTP peers configured on the device. | napalm_junos/junos.py | def get_ntp_peers(self):
"""Return the NTP peers configured on the device."""
ntp_table = junos_views.junos_ntp_peers_config_table(self.device)
ntp_table.get()
ntp_peers = ntp_table.items()
if not ntp_peers:
return {}
return {napalm_base.helpers.ip(peer[0])... | def get_ntp_peers(self):
"""Return the NTP peers configured on the device."""
ntp_table = junos_views.junos_ntp_peers_config_table(self.device)
ntp_table.get()
ntp_peers = ntp_table.items()
if not ntp_peers:
return {}
return {napalm_base.helpers.ip(peer[0])... | [
"Return",
"the",
"NTP",
"peers",
"configured",
"on",
"the",
"device",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1225-L1235 | [
"def",
"get_ntp_peers",
"(",
"self",
")",
":",
"ntp_table",
"=",
"junos_views",
".",
"junos_ntp_peers_config_table",
"(",
"self",
".",
"device",
")",
"ntp_table",
".",
"get",
"(",
")",
"ntp_peers",
"=",
"ntp_table",
".",
"items",
"(",
")",
"if",
"not",
"nt... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_ntp_servers | Return the NTP servers configured on the device. | napalm_junos/junos.py | def get_ntp_servers(self):
"""Return the NTP servers configured on the device."""
ntp_table = junos_views.junos_ntp_servers_config_table(self.device)
ntp_table.get()
ntp_servers = ntp_table.items()
if not ntp_servers:
return {}
return {napalm_base.helpers.i... | def get_ntp_servers(self):
"""Return the NTP servers configured on the device."""
ntp_table = junos_views.junos_ntp_servers_config_table(self.device)
ntp_table.get()
ntp_servers = ntp_table.items()
if not ntp_servers:
return {}
return {napalm_base.helpers.i... | [
"Return",
"the",
"NTP",
"servers",
"configured",
"on",
"the",
"device",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1237-L1247 | [
"def",
"get_ntp_servers",
"(",
"self",
")",
":",
"ntp_table",
"=",
"junos_views",
".",
"junos_ntp_servers_config_table",
"(",
"self",
".",
"device",
")",
"ntp_table",
".",
"get",
"(",
")",
"ntp_servers",
"=",
"ntp_table",
".",
"items",
"(",
")",
"if",
"not",... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_ntp_stats | Return NTP stats (associations). | napalm_junos/junos.py | def get_ntp_stats(self):
"""Return NTP stats (associations)."""
# NTP Peers does not have XML RPC defined
# thus we need to retrieve raw text and parse...
# :(
ntp_stats = []
REGEX = (
'^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)'
'\s+([a-zA-Z0-9\.]+)\s+... | def get_ntp_stats(self):
"""Return NTP stats (associations)."""
# NTP Peers does not have XML RPC defined
# thus we need to retrieve raw text and parse...
# :(
ntp_stats = []
REGEX = (
'^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)'
'\s+([a-zA-Z0-9\.]+)\s+... | [
"Return",
"NTP",
"stats",
"(",
"associations",
")",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1249-L1290 | [
"def",
"get_ntp_stats",
"(",
"self",
")",
":",
"# NTP Peers does not have XML RPC defined",
"# thus we need to retrieve raw text and parse...",
"# :(",
"ntp_stats",
"=",
"[",
"]",
"REGEX",
"=",
"(",
"'^\\s?(\\+|\\*|x|-)?([a-zA-Z0-9\\.+-:]+)'",
"'\\s+([a-zA-Z0-9\\.]+)\\s+([0-9]{1,2}... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_mac_address_table | Return the MAC address table. | napalm_junos/junos.py | def get_mac_address_table(self):
"""Return the MAC address table."""
mac_address_table = []
if self.device.facts.get('personality', '') in ['SWITCH']: # for EX & QFX devices
if self.device.facts.get('switch_style', '') in ['VLAN_L2NG']: # for L2NG devices
mac_table... | def get_mac_address_table(self):
"""Return the MAC address table."""
mac_address_table = []
if self.device.facts.get('personality', '') in ['SWITCH']: # for EX & QFX devices
if self.device.facts.get('switch_style', '') in ['VLAN_L2NG']: # for L2NG devices
mac_table... | [
"Return",
"the",
"MAC",
"address",
"table",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1337-L1376 | [
"def",
"get_mac_address_table",
"(",
"self",
")",
":",
"mac_address_table",
"=",
"[",
"]",
"if",
"self",
".",
"device",
".",
"facts",
".",
"get",
"(",
"'personality'",
",",
"''",
")",
"in",
"[",
"'SWITCH'",
"]",
":",
"# for EX & QFX devices",
"if",
"self",... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_probes_config | Return the configuration of the RPM probes. | napalm_junos/junos.py | def get_probes_config(self):
"""Return the configuration of the RPM probes."""
probes = {}
probes_table = junos_views.junos_rpm_probes_config_table(self.device)
probes_table.get()
probes_table_items = probes_table.items()
for probe_test in probes_table_items:
... | def get_probes_config(self):
"""Return the configuration of the RPM probes."""
probes = {}
probes_table = junos_views.junos_rpm_probes_config_table(self.device)
probes_table.get()
probes_table_items = probes_table.items()
for probe_test in probes_table_items:
... | [
"Return",
"the",
"configuration",
"of",
"the",
"RPM",
"probes",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1539-L1572 | [
"def",
"get_probes_config",
"(",
"self",
")",
":",
"probes",
"=",
"{",
"}",
"probes_table",
"=",
"junos_views",
".",
"junos_rpm_probes_config_table",
"(",
"self",
".",
"device",
")",
"probes_table",
".",
"get",
"(",
")",
"probes_table_items",
"=",
"probes_table"... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.get_probes_results | Return the results of the RPM probes. | napalm_junos/junos.py | def get_probes_results(self):
"""Return the results of the RPM probes."""
probes_results = {}
probes_results_table = junos_views.junos_rpm_probes_results_table(self.device)
probes_results_table.get()
probes_results_items = probes_results_table.items()
for probe_result i... | def get_probes_results(self):
"""Return the results of the RPM probes."""
probes_results = {}
probes_results_table = junos_views.junos_rpm_probes_results_table(self.device)
probes_results_table.get()
probes_results_items = probes_results_table.items()
for probe_result i... | [
"Return",
"the",
"results",
"of",
"the",
"RPM",
"probes",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1574-L1601 | [
"def",
"get_probes_results",
"(",
"self",
")",
":",
"probes_results",
"=",
"{",
"}",
"probes_results_table",
"=",
"junos_views",
".",
"junos_rpm_probes_results_table",
"(",
"self",
".",
"device",
")",
"probes_results_table",
".",
"get",
"(",
")",
"probes_results_ite... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | JunOSDriver.traceroute | Execute traceroute and return results. | napalm_junos/junos.py | def traceroute(self,
destination,
source=C.TRACEROUTE_SOURCE,
ttl=C.TRACEROUTE_TTL,
timeout=C.TRACEROUTE_TIMEOUT,
vrf=C.TRACEROUTE_VRF):
"""Execute traceroute and return results."""
traceroute_result = {}
... | def traceroute(self,
destination,
source=C.TRACEROUTE_SOURCE,
ttl=C.TRACEROUTE_TTL,
timeout=C.TRACEROUTE_TIMEOUT,
vrf=C.TRACEROUTE_VRF):
"""Execute traceroute and return results."""
traceroute_result = {}
... | [
"Execute",
"traceroute",
"and",
"return",
"results",
"."
] | napalm-automation/napalm-junos | python | https://github.com/napalm-automation/napalm-junos/blob/78c0d161daf2abf26af5835b773f6db57c46efff/napalm_junos/junos.py#L1603-L1671 | [
"def",
"traceroute",
"(",
"self",
",",
"destination",
",",
"source",
"=",
"C",
".",
"TRACEROUTE_SOURCE",
",",
"ttl",
"=",
"C",
".",
"TRACEROUTE_TTL",
",",
"timeout",
"=",
"C",
".",
"TRACEROUTE_TIMEOUT",
",",
"vrf",
"=",
"C",
".",
"TRACEROUTE_VRF",
")",
"... | 78c0d161daf2abf26af5835b773f6db57c46efff |
train | parse_intf_section | Parse a single entry from show interfaces output.
Different cases:
mgmt0 is up
admin state is up
Ethernet2/1 is up
admin state is up, Dedicated Interface
Vlan1 is down (Administratively down), line protocol is down, autostate enabled
Ethernet154/1/48 is up (with no 'admin state') | napalm_nxos_ssh/nxos_ssh.py | def parse_intf_section(interface):
"""Parse a single entry from show interfaces output.
Different cases:
mgmt0 is up
admin state is up
Ethernet2/1 is up
admin state is up, Dedicated Interface
Vlan1 is down (Administratively down), line protocol is down, autostate enabled
Ethernet154/... | def parse_intf_section(interface):
"""Parse a single entry from show interfaces output.
Different cases:
mgmt0 is up
admin state is up
Ethernet2/1 is up
admin state is up, Dedicated Interface
Vlan1 is down (Administratively down), line protocol is down, autostate enabled
Ethernet154/... | [
"Parse",
"a",
"single",
"entry",
"from",
"show",
"interfaces",
"output",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos_ssh/nxos_ssh.py#L74-L169 | [
"def",
"parse_intf_section",
"(",
"interface",
")",
":",
"interface",
"=",
"interface",
".",
"strip",
"(",
")",
"re_protocol",
"=",
"r\"^(?P<intf_name>\\S+?)\\s+is\\s+(?P<status>.+?)\"",
"r\",\\s+line\\s+protocol\\s+is\\s+(?P<protocol>\\S+).*$\"",
"re_intf_name_state",
"=",
"r\... | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | NXOSSSHDriver._get_diff | Get a diff between running config and a proposed file. | napalm_nxos_ssh/nxos_ssh.py | def _get_diff(self):
"""Get a diff between running config and a proposed file."""
diff = []
self._create_sot_file()
command = ('show diff rollback-patch file {0} file {1}'.format(
'sot_file', self.replace_file.split('/')[-1]))
diff_out = self.device.send_comman... | def _get_diff(self):
"""Get a diff between running config and a proposed file."""
diff = []
self._create_sot_file()
command = ('show diff rollback-patch file {0} file {1}'.format(
'sot_file', self.replace_file.split('/')[-1]))
diff_out = self.device.send_comman... | [
"Get",
"a",
"diff",
"between",
"running",
"config",
"and",
"a",
"proposed",
"file",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos_ssh/nxos_ssh.py#L595-L613 | [
"def",
"_get_diff",
"(",
"self",
")",
":",
"diff",
"=",
"[",
"]",
"self",
".",
"_create_sot_file",
"(",
")",
"command",
"=",
"(",
"'show diff rollback-patch file {0} file {1}'",
".",
"format",
"(",
"'sot_file'",
",",
"self",
".",
"replace_file",
".",
"split",
... | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | NXOSSSHDriver._save_to_checkpoint | Save the current running config to the given file. | napalm_nxos_ssh/nxos_ssh.py | def _save_to_checkpoint(self, filename):
"""Save the current running config to the given file."""
command = 'checkpoint file {}'.format(filename)
self.device.send_command(command) | def _save_to_checkpoint(self, filename):
"""Save the current running config to the given file."""
command = 'checkpoint file {}'.format(filename)
self.device.send_command(command) | [
"Save",
"the",
"current",
"running",
"config",
"to",
"the",
"given",
"file",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos_ssh/nxos_ssh.py#L657-L660 | [
"def",
"_save_to_checkpoint",
"(",
"self",
",",
"filename",
")",
":",
"command",
"=",
"'checkpoint file {}'",
".",
"format",
"(",
"filename",
")",
"self",
".",
"device",
".",
"send_command",
"(",
"command",
")"
] | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | NXOSSSHDriver.get_facts | Return a set of facts from the devices. | napalm_nxos_ssh/nxos_ssh.py | def get_facts(self):
"""Return a set of facts from the devices."""
# default values.
vendor = u'Cisco'
uptime = -1
serial_number, fqdn, os_version, hostname, domain_name = ('',) * 5
# obtain output from device
show_ver = self.device.send_command('show version')
... | def get_facts(self):
"""Return a set of facts from the devices."""
# default values.
vendor = u'Cisco'
uptime = -1
serial_number, fqdn, os_version, hostname, domain_name = ('',) * 5
# obtain output from device
show_ver = self.device.send_command('show version')
... | [
"Return",
"a",
"set",
"of",
"facts",
"from",
"the",
"devices",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos_ssh/nxos_ssh.py#L736-L799 | [
"def",
"get_facts",
"(",
"self",
")",
":",
"# default values.",
"vendor",
"=",
"u'Cisco'",
"uptime",
"=",
"-",
"1",
"serial_number",
",",
"fqdn",
",",
"os_version",
",",
"hostname",
",",
"domain_name",
"=",
"(",
"''",
",",
")",
"*",
"5",
"# obtain output f... | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | NXOSSSHDriver.get_arp_table | Get arp table information.
Return a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
For example::
[
{
'interface' : 'MgmtEth0/RSP0/CPU0... | napalm_nxos_ssh/nxos_ssh.py | def get_arp_table(self):
"""
Get arp table information.
Return a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
For example::
[
{
... | def get_arp_table(self):
"""
Get arp table information.
Return a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
For example::
[
{
... | [
"Get",
"arp",
"table",
"information",
"."
] | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos_ssh/nxos_ssh.py#L1037-L1105 | [
"def",
"get_arp_table",
"(",
"self",
")",
":",
"arp_table",
"=",
"[",
"]",
"command",
"=",
"'show ip arp vrf default | exc INCOMPLETE'",
"output",
"=",
"self",
".",
"device",
".",
"send_command",
"(",
"command",
")",
"separator",
"=",
"r\"^Address\\s+Age.*Interface.... | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | NXOSSSHDriver.get_mac_address_table | Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (boolean)
* moves (int)
* last... | napalm_nxos_ssh/nxos_ssh.py | def get_mac_address_table(self):
"""
Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (... | def get_mac_address_table(self):
"""
Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (... | [
"Returns",
"a",
"lists",
"of",
"dictionaries",
".",
"Each",
"dictionary",
"represents",
"an",
"entry",
"in",
"the",
"MAC",
"Address",
"Table",
"having",
"the",
"following",
"keys",
"*",
"mac",
"(",
"string",
")",
"*",
"interface",
"(",
"string",
")",
"*",
... | napalm-automation/napalm-nxos | python | https://github.com/napalm-automation/napalm-nxos/blob/936d641c99e068817abf247e0e5571fc31b3a92a/napalm_nxos_ssh/nxos_ssh.py#L1220-L1320 | [
"def",
"get_mac_address_table",
"(",
"self",
")",
":",
"# The '*' is stripped out later",
"RE_MACTABLE_FORMAT1",
"=",
"r\"^\\s+{}\\s+{}\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\"",
".",
"format",
"(",
"VLAN_REGEX",
",",
"MAC_REGEX",
")",
"RE_MACTABLE_FORMAT2",
"=",
"r\"^\\s+{}\... | 936d641c99e068817abf247e0e5571fc31b3a92a |
train | Logout.get | Remove all auth tokens owned by request.user. | authemail/views.py | def get(self, request, format=None):
"""
Remove all auth tokens owned by request.user.
"""
tokens = Token.objects.filter(user=request.user)
for token in tokens:
token.delete()
content = {'success': _('User logged out.')}
return Response(content, status... | def get(self, request, format=None):
"""
Remove all auth tokens owned by request.user.
"""
tokens = Token.objects.filter(user=request.user)
for token in tokens:
token.delete()
content = {'success': _('User logged out.')}
return Response(content, status... | [
"Remove",
"all",
"auth",
"tokens",
"owned",
"by",
"request",
".",
"user",
"."
] | celiao/django-rest-authemail | python | https://github.com/celiao/django-rest-authemail/blob/7295a4061a46b058595dae19b14c612f0eb0393a/authemail/views.py#L130-L138 | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"format",
"=",
"None",
")",
":",
"tokens",
"=",
"Token",
".",
"objects",
".",
"filter",
"(",
"user",
"=",
"request",
".",
"user",
")",
"for",
"token",
"in",
"tokens",
":",
"token",
".",
"delete",
"(",... | 7295a4061a46b058595dae19b14c612f0eb0393a |
train | API._set_attrs_to_values | Set attributes to dictionary values so can access via dot notation. | authemail/wrapper.py | def _set_attrs_to_values(self, response={}):
"""
Set attributes to dictionary values so can access via dot notation.
"""
for key in response.keys():
setattr(self, key, response[key]) | def _set_attrs_to_values(self, response={}):
"""
Set attributes to dictionary values so can access via dot notation.
"""
for key in response.keys():
setattr(self, key, response[key]) | [
"Set",
"attributes",
"to",
"dictionary",
"values",
"so",
"can",
"access",
"via",
"dot",
"notation",
"."
] | celiao/django-rest-authemail | python | https://github.com/celiao/django-rest-authemail/blob/7295a4061a46b058595dae19b14c612f0eb0393a/authemail/wrapper.py#L47-L52 | [
"def",
"_set_attrs_to_values",
"(",
"self",
",",
"response",
"=",
"{",
"}",
")",
":",
"for",
"key",
"in",
"response",
".",
"keys",
"(",
")",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"response",
"[",
"key",
"]",
")"
] | 7295a4061a46b058595dae19b14c612f0eb0393a |
train | Autodoc.add_custom_nl2br_filters | Add a custom filter nl2br to jinja2
Replaces all newline to <BR> | flask_autodoc/autodoc.py | def add_custom_nl2br_filters(self, app):
"""Add a custom filter nl2br to jinja2
Replaces all newline to <BR>
"""
_paragraph_re = re.compile(r'(?:\r\n|\r|\n){3,}')
@app.template_filter()
@evalcontextfilter
def nl2br(eval_ctx, value):
result = '\n\n'.j... | def add_custom_nl2br_filters(self, app):
"""Add a custom filter nl2br to jinja2
Replaces all newline to <BR>
"""
_paragraph_re = re.compile(r'(?:\r\n|\r|\n){3,}')
@app.template_filter()
@evalcontextfilter
def nl2br(eval_ctx, value):
result = '\n\n'.j... | [
"Add",
"a",
"custom",
"filter",
"nl2br",
"to",
"jinja2",
"Replaces",
"all",
"newline",
"to",
"<BR",
">"
] | acoomans/flask-autodoc | python | https://github.com/acoomans/flask-autodoc/blob/6c77c8935b71fbf3243b5e589c5c255d0299d853/flask_autodoc/autodoc.py#L51-L62 | [
"def",
"add_custom_nl2br_filters",
"(",
"self",
",",
"app",
")",
":",
"_paragraph_re",
"=",
"re",
".",
"compile",
"(",
"r'(?:\\r\\n|\\r|\\n){3,}'",
")",
"@",
"app",
".",
"template_filter",
"(",
")",
"@",
"evalcontextfilter",
"def",
"nl2br",
"(",
"eval_ctx",
",... | 6c77c8935b71fbf3243b5e589c5c255d0299d853 |
train | Autodoc.doc | Add flask route to autodoc for automatic documentation
Any route decorated with this method will be added to the list of
routes to be documented by the generate() or html() methods.
By default, the route is added to the 'all' group.
By specifying group or groups argument, the route can... | flask_autodoc/autodoc.py | def doc(self, groups=None, set_location=True, **properties):
"""Add flask route to autodoc for automatic documentation
Any route decorated with this method will be added to the list of
routes to be documented by the generate() or html() methods.
By default, the route is added to the 'a... | def doc(self, groups=None, set_location=True, **properties):
"""Add flask route to autodoc for automatic documentation
Any route decorated with this method will be added to the list of
routes to be documented by the generate() or html() methods.
By default, the route is added to the 'a... | [
"Add",
"flask",
"route",
"to",
"autodoc",
"for",
"automatic",
"documentation"
] | acoomans/flask-autodoc | python | https://github.com/acoomans/flask-autodoc/blob/6c77c8935b71fbf3243b5e589c5c255d0299d853/flask_autodoc/autodoc.py#L64-L111 | [
"def",
"doc",
"(",
"self",
",",
"groups",
"=",
"None",
",",
"set_location",
"=",
"True",
",",
"*",
"*",
"properties",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"# Get previous group list (if any)",
"if",
"f",
"in",
"self",
".",
"func_groups",
":"... | 6c77c8935b71fbf3243b5e589c5c255d0299d853 |
train | Autodoc.generate | Return a list of dict describing the routes specified by the
doc() method
Each dict contains:
- methods: the set of allowed methods (ie ['GET', 'POST'])
- rule: relative url (ie '/user/<int:id>')
- endpoint: function name (ie 'show_user')
- doc: docstring of the func... | flask_autodoc/autodoc.py | def generate(self, groups='all', sort=None):
"""Return a list of dict describing the routes specified by the
doc() method
Each dict contains:
- methods: the set of allowed methods (ie ['GET', 'POST'])
- rule: relative url (ie '/user/<int:id>')
- endpoint: function nam... | def generate(self, groups='all', sort=None):
"""Return a list of dict describing the routes specified by the
doc() method
Each dict contains:
- methods: the set of allowed methods (ie ['GET', 'POST'])
- rule: relative url (ie '/user/<int:id>')
- endpoint: function nam... | [
"Return",
"a",
"list",
"of",
"dict",
"describing",
"the",
"routes",
"specified",
"by",
"the",
"doc",
"()",
"method"
] | acoomans/flask-autodoc | python | https://github.com/acoomans/flask-autodoc/blob/6c77c8935b71fbf3243b5e589c5c255d0299d853/flask_autodoc/autodoc.py#L113-L166 | [
"def",
"generate",
"(",
"self",
",",
"groups",
"=",
"'all'",
",",
"sort",
"=",
"None",
")",
":",
"groups_to_generate",
"=",
"list",
"(",
")",
"if",
"type",
"(",
"groups",
")",
"is",
"list",
":",
"groups_to_generate",
"=",
"groups",
"elif",
"type",
"(",... | 6c77c8935b71fbf3243b5e589c5c255d0299d853 |
train | Autodoc.html | Return an html string of the routes specified by the doc() method
A template can be specified. A list of routes is available under the
'autodoc' value (refer to the documentation for the generate() for a
description of available values). If no template is specified, a
default template i... | flask_autodoc/autodoc.py | def html(self, groups='all', template=None, **context):
"""Return an html string of the routes specified by the doc() method
A template can be specified. A list of routes is available under the
'autodoc' value (refer to the documentation for the generate() for a
description of available... | def html(self, groups='all', template=None, **context):
"""Return an html string of the routes specified by the doc() method
A template can be specified. A list of routes is available under the
'autodoc' value (refer to the documentation for the generate() for a
description of available... | [
"Return",
"an",
"html",
"string",
"of",
"the",
"routes",
"specified",
"by",
"the",
"doc",
"()",
"method"
] | acoomans/flask-autodoc | python | https://github.com/acoomans/flask-autodoc/blob/6c77c8935b71fbf3243b5e589c5c255d0299d853/flask_autodoc/autodoc.py#L168-L194 | [
"def",
"html",
"(",
"self",
",",
"groups",
"=",
"'all'",
",",
"template",
"=",
"None",
",",
"*",
"*",
"context",
")",
":",
"context",
"[",
"'autodoc'",
"]",
"=",
"context",
"[",
"'autodoc'",
"]",
"if",
"'autodoc'",
"in",
"context",
"else",
"self",
".... | 6c77c8935b71fbf3243b5e589c5c255d0299d853 |
train | ImageList.unsaved_files_dialog | Return true if OK to continue with close or quit or whatever | src/photini/imagelist.py | def unsaved_files_dialog(
self, all_files=False, with_cancel=True, with_discard=True):
"""Return true if OK to continue with close or quit or whatever"""
for image in self.images:
if image.metadata.changed() and (all_files or image.selected):
break
else:
... | def unsaved_files_dialog(
self, all_files=False, with_cancel=True, with_discard=True):
"""Return true if OK to continue with close or quit or whatever"""
for image in self.images:
if image.metadata.changed() and (all_files or image.selected):
break
else:
... | [
"Return",
"true",
"if",
"OK",
"to",
"continue",
"with",
"close",
"or",
"quit",
"or",
"whatever"
] | jim-easterbrook/Photini | python | https://github.com/jim-easterbrook/Photini/blob/06f1b1988db23a5cad98bbc6c16406a64a6c556d/src/photini/imagelist.py#L748-L772 | [
"def",
"unsaved_files_dialog",
"(",
"self",
",",
"all_files",
"=",
"False",
",",
"with_cancel",
"=",
"True",
",",
"with_discard",
"=",
"True",
")",
":",
"for",
"image",
"in",
"self",
".",
"images",
":",
"if",
"image",
".",
"metadata",
".",
"changed",
"("... | 06f1b1988db23a5cad98bbc6c16406a64a6c556d |
train | DateTime.from_ISO_8601 | Sufficiently general ISO 8601 parser.
Inputs must be in "basic" format, i.e. no '-' or ':' separators.
See https://en.wikipedia.org/wiki/ISO_8601 | src/photini/metadata.py | def from_ISO_8601(cls, date_string, time_string, tz_string):
"""Sufficiently general ISO 8601 parser.
Inputs must be in "basic" format, i.e. no '-' or ':' separators.
See https://en.wikipedia.org/wiki/ISO_8601
"""
# parse tz_string
if tz_string:
tz_offset = ... | def from_ISO_8601(cls, date_string, time_string, tz_string):
"""Sufficiently general ISO 8601 parser.
Inputs must be in "basic" format, i.e. no '-' or ':' separators.
See https://en.wikipedia.org/wiki/ISO_8601
"""
# parse tz_string
if tz_string:
tz_offset = ... | [
"Sufficiently",
"general",
"ISO",
"8601",
"parser",
"."
] | jim-easterbrook/Photini | python | https://github.com/jim-easterbrook/Photini/blob/06f1b1988db23a5cad98bbc6c16406a64a6c556d/src/photini/metadata.py#L412-L436 | [
"def",
"from_ISO_8601",
"(",
"cls",
",",
"date_string",
",",
"time_string",
",",
"tz_string",
")",
":",
"# parse tz_string",
"if",
"tz_string",
":",
"tz_offset",
"=",
"(",
"int",
"(",
"tz_string",
"[",
"1",
":",
"3",
"]",
")",
"*",
"60",
")",
"+",
"int... | 06f1b1988db23a5cad98bbc6c16406a64a6c556d |
train | post_post | Create a new post.
Form Data: title, content, authorid. | examples/factory/blog/frontend.py | def post_post():
"""Create a new post.
Form Data: title, content, authorid.
"""
authorid = request.form.get('authorid', None)
Post(request.form['title'],
request.form['content'],
users[authorid])
return redirect("/posts") | def post_post():
"""Create a new post.
Form Data: title, content, authorid.
"""
authorid = request.form.get('authorid', None)
Post(request.form['title'],
request.form['content'],
users[authorid])
return redirect("/posts") | [
"Create",
"a",
"new",
"post",
".",
"Form",
"Data",
":",
"title",
"content",
"authorid",
"."
] | acoomans/flask-autodoc | python | https://github.com/acoomans/flask-autodoc/blob/6c77c8935b71fbf3243b5e589c5c255d0299d853/examples/factory/blog/frontend.py#L59-L67 | [
"def",
"post_post",
"(",
")",
":",
"authorid",
"=",
"request",
".",
"form",
".",
"get",
"(",
"'authorid'",
",",
"None",
")",
"Post",
"(",
"request",
".",
"form",
"[",
"'title'",
"]",
",",
"request",
".",
"form",
"[",
"'content'",
"]",
",",
"users",
... | 6c77c8935b71fbf3243b5e589c5c255d0299d853 |
train | SelectionMixin.xpath | Finds another node by XPath originating at the current node. | webkit_server.py | def xpath(self, xpath):
""" Finds another node by XPath originating at the current node. """
return [self.get_node_factory().create(node_id)
for node_id in self._get_xpath_ids(xpath).split(",")
if node_id] | def xpath(self, xpath):
""" Finds another node by XPath originating at the current node. """
return [self.get_node_factory().create(node_id)
for node_id in self._get_xpath_ids(xpath).split(",")
if node_id] | [
"Finds",
"another",
"node",
"by",
"XPath",
"originating",
"at",
"the",
"current",
"node",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L21-L25 | [
"def",
"xpath",
"(",
"self",
",",
"xpath",
")",
":",
"return",
"[",
"self",
".",
"get_node_factory",
"(",
")",
".",
"create",
"(",
"node_id",
")",
"for",
"node_id",
"in",
"self",
".",
"_get_xpath_ids",
"(",
"xpath",
")",
".",
"split",
"(",
"\",\"",
"... | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | SelectionMixin.css | Finds another node by a CSS selector relative to the current node. | webkit_server.py | def css(self, css):
""" Finds another node by a CSS selector relative to the current node. """
return [self.get_node_factory().create(node_id)
for node_id in self._get_css_ids(css).split(",")
if node_id] | def css(self, css):
""" Finds another node by a CSS selector relative to the current node. """
return [self.get_node_factory().create(node_id)
for node_id in self._get_css_ids(css).split(",")
if node_id] | [
"Finds",
"another",
"node",
"by",
"a",
"CSS",
"selector",
"relative",
"to",
"the",
"current",
"node",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L27-L31 | [
"def",
"css",
"(",
"self",
",",
"css",
")",
":",
"return",
"[",
"self",
".",
"get_node_factory",
"(",
")",
".",
"create",
"(",
"node_id",
")",
"for",
"node_id",
"in",
"self",
".",
"_get_css_ids",
"(",
"css",
")",
".",
"split",
"(",
"\",\"",
")",
"i... | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Node.get_bool_attr | Returns the value of a boolean HTML attribute like `checked` or `disabled` | webkit_server.py | def get_bool_attr(self, name):
""" Returns the value of a boolean HTML attribute like `checked` or `disabled`
"""
val = self.get_attr(name)
return val is not None and val.lower() in ("true", name) | def get_bool_attr(self, name):
""" Returns the value of a boolean HTML attribute like `checked` or `disabled`
"""
val = self.get_attr(name)
return val is not None and val.lower() in ("true", name) | [
"Returns",
"the",
"value",
"of",
"a",
"boolean",
"HTML",
"attribute",
"like",
"checked",
"or",
"disabled"
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L68-L72 | [
"def",
"get_bool_attr",
"(",
"self",
",",
"name",
")",
":",
"val",
"=",
"self",
".",
"get_attr",
"(",
"name",
")",
"return",
"val",
"is",
"not",
"None",
"and",
"val",
".",
"lower",
"(",
")",
"in",
"(",
"\"true\"",
",",
"name",
")"
] | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Node.set_attr | Sets the value of an attribute. | webkit_server.py | def set_attr(self, name, value):
""" Sets the value of an attribute. """
self.exec_script("node.setAttribute(%s, %s)" % (repr(name), repr(value))) | def set_attr(self, name, value):
""" Sets the value of an attribute. """
self.exec_script("node.setAttribute(%s, %s)" % (repr(name), repr(value))) | [
"Sets",
"the",
"value",
"of",
"an",
"attribute",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L78-L80 | [
"def",
"set_attr",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"self",
".",
"exec_script",
"(",
"\"node.setAttribute(%s, %s)\"",
"%",
"(",
"repr",
"(",
"name",
")",
",",
"repr",
"(",
"value",
")",
")",
")"
] | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Node.value | Returns the node's value. | webkit_server.py | def value(self):
""" Returns the node's value. """
if self.is_multi_select():
return [opt.value()
for opt in self.xpath(".//option")
if opt["selected"]]
else:
return self._invoke("value") | def value(self):
""" Returns the node's value. """
if self.is_multi_select():
return [opt.value()
for opt in self.xpath(".//option")
if opt["selected"]]
else:
return self._invoke("value") | [
"Returns",
"the",
"node",
"s",
"value",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L82-L89 | [
"def",
"value",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_multi_select",
"(",
")",
":",
"return",
"[",
"opt",
".",
"value",
"(",
")",
"for",
"opt",
"in",
"self",
".",
"xpath",
"(",
"\".//option\"",
")",
"if",
"opt",
"[",
"\"selected\"",
"]",
"]... | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Client.set_header | Sets a HTTP header for future requests. | webkit_server.py | def set_header(self, key, value):
""" Sets a HTTP header for future requests. """
self.conn.issue_command("Header", _normalize_header(key), value) | def set_header(self, key, value):
""" Sets a HTTP header for future requests. """
self.conn.issue_command("Header", _normalize_header(key), value) | [
"Sets",
"a",
"HTTP",
"header",
"for",
"future",
"requests",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L250-L252 | [
"def",
"set_header",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"self",
".",
"conn",
".",
"issue_command",
"(",
"\"Header\"",
",",
"_normalize_header",
"(",
"key",
")",
",",
"value",
")"
] | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Client.headers | Returns a list of the last HTTP response headers.
Header keys are normalized to capitalized form, as in `User-Agent`. | webkit_server.py | def headers(self):
""" Returns a list of the last HTTP response headers.
Header keys are normalized to capitalized form, as in `User-Agent`.
"""
headers = self.conn.issue_command("Headers")
res = []
for header in headers.split("\r"):
key, value = header.split(": ", 1)
for line in val... | def headers(self):
""" Returns a list of the last HTTP response headers.
Header keys are normalized to capitalized form, as in `User-Agent`.
"""
headers = self.conn.issue_command("Headers")
res = []
for header in headers.split("\r"):
key, value = header.split(": ", 1)
for line in val... | [
"Returns",
"a",
"list",
"of",
"the",
"last",
"HTTP",
"response",
"headers",
".",
"Header",
"keys",
"are",
"normalized",
"to",
"capitalized",
"form",
"as",
"in",
"User",
"-",
"Agent",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L262-L272 | [
"def",
"headers",
"(",
"self",
")",
":",
"headers",
"=",
"self",
".",
"conn",
".",
"issue_command",
"(",
"\"Headers\"",
")",
"res",
"=",
"[",
"]",
"for",
"header",
"in",
"headers",
".",
"split",
"(",
"\"\\r\"",
")",
":",
"key",
",",
"value",
"=",
"... | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Client.eval_script | Evaluates a piece of Javascript in the context of the current page and
returns its value. | webkit_server.py | def eval_script(self, expr):
""" Evaluates a piece of Javascript in the context of the current page and
returns its value. """
ret = self.conn.issue_command("Evaluate", expr)
return json.loads("[%s]" % ret)[0] | def eval_script(self, expr):
""" Evaluates a piece of Javascript in the context of the current page and
returns its value. """
ret = self.conn.issue_command("Evaluate", expr)
return json.loads("[%s]" % ret)[0] | [
"Evaluates",
"a",
"piece",
"of",
"Javascript",
"in",
"the",
"context",
"of",
"the",
"current",
"page",
"and",
"returns",
"its",
"value",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L274-L278 | [
"def",
"eval_script",
"(",
"self",
",",
"expr",
")",
":",
"ret",
"=",
"self",
".",
"conn",
".",
"issue_command",
"(",
"\"Evaluate\"",
",",
"expr",
")",
"return",
"json",
".",
"loads",
"(",
"\"[%s]\"",
"%",
"ret",
")",
"[",
"0",
"]"
] | c9e3a8394b8c51000c35f8a56fb770580562b544 |
train | Client.render | Renders the current page to a PNG file (viewport size in pixels). | webkit_server.py | def render(self, path, width = 1024, height = 1024):
""" Renders the current page to a PNG file (viewport size in pixels). """
self.conn.issue_command("Render", path, width, height) | def render(self, path, width = 1024, height = 1024):
""" Renders the current page to a PNG file (viewport size in pixels). """
self.conn.issue_command("Render", path, width, height) | [
"Renders",
"the",
"current",
"page",
"to",
"a",
"PNG",
"file",
"(",
"viewport",
"size",
"in",
"pixels",
")",
"."
] | niklasb/webkit-server | python | https://github.com/niklasb/webkit-server/blob/c9e3a8394b8c51000c35f8a56fb770580562b544/webkit_server.py#L284-L286 | [
"def",
"render",
"(",
"self",
",",
"path",
",",
"width",
"=",
"1024",
",",
"height",
"=",
"1024",
")",
":",
"self",
".",
"conn",
".",
"issue_command",
"(",
"\"Render\"",
",",
"path",
",",
"width",
",",
"height",
")"
] | c9e3a8394b8c51000c35f8a56fb770580562b544 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.