code
stringlengths 51
2.38k
| docstring
stringlengths 4
15.2k
|
---|---|
def relation_completions(
completion_text: str, bel_spec: BELSpec, bel_fmt: str, size: int
) -> list:
if bel_fmt == "short":
relation_list = bel_spec["relations"]["list_short"]
else:
relation_list = bel_spec["relations"]["list_long"]
matches = []
for r in relation_list:
if re.match(completion_text, r):
matches.append(r)
replace_list = []
for match in matches:
highlight = match.replace(completion_text, f"<em>{completion_text}</em>")
replace_list.append(
{
"replacement": match,
"label": match,
"highlight": highlight,
"type": "Relation",
}
)
return replace_list[:size]
|
Filter BEL relations by prefix
Args:
prefix: completion string
bel_fmt: short, medium, long BEL formats
spec: BEL specification
Returns:
list: list of BEL relations that match prefix
|
def msg_debug(message):
if _log_lvl == logging.DEBUG:
to_stdout(" (*) {message}".format(message=message), colorf=cyan)
if _logger:
_logger.debug(message)
|
Log a debug message
:param message: the message to be logged
|
def load_session(fname=None):
if fname is None:
fname = conf.session
try:
s = six.moves.cPickle.load(gzip.open(fname, "rb"))
except IOError:
try:
s = six.moves.cPickle.load(open(fname, "rb"))
except IOError:
raise
scapy_session = six.moves.builtins.__dict__["scapy_session"]
scapy_session.clear()
scapy_session.update(s)
update_ipython_session(scapy_session)
log_loading.info("Loaded session [%s]" % fname)
|
Load current Scapy session from the file specified in the fname arg.
This will erase any existing session.
params:
- fname: file to load the scapy session from
|
def _convert_data(self, data, data_type, num_recs, num_values, num_elems):
if (data_type == 51 or data_type == 52):
return [data[i:i+num_elems].decode('utf-8') for i in
range(0, num_recs*num_values*num_elems, num_elems)]
else:
tofrom = self._convert_option()
dt_string = self._convert_type(data_type)
form = tofrom + str(num_recs*num_values*num_elems) + dt_string
value_len = CDF._type_size(data_type, num_elems)
return list(struct.unpack_from(form,
data[0:num_recs*num_values*value_len]))
|
Converts data to the appropriate type using the struct.unpack method,
rather than using numpy.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.