repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
absent1706/sqlalchemy-mixins | sqlalchemy_mixins/serialize.py | SerializeMixin.to_dict | def to_dict(self, nested=False):
"""Return dict object with model's data.
:param nested: flag to return nested relationships' data if true
:type: bool
:return: dict
"""
result = dict()
for key in self.columns:
result[key] = getattr(self, key)
... | python | def to_dict(self, nested=False):
"""Return dict object with model's data.
:param nested: flag to return nested relationships' data if true
:type: bool
:return: dict
"""
result = dict()
for key in self.columns:
result[key] = getattr(self, key)
... | [
"def",
"to_dict",
"(",
"self",
",",
"nested",
"=",
"False",
")",
":",
"result",
"=",
"dict",
"(",
")",
"for",
"key",
"in",
"self",
".",
"columns",
":",
"result",
"[",
"key",
"]",
"=",
"getattr",
"(",
"self",
",",
"key",
")",
"if",
"nested",
":",
... | Return dict object with model's data.
:param nested: flag to return nested relationships' data if true
:type: bool
:return: dict | [
"Return",
"dict",
"object",
"with",
"model",
"s",
"data",
"."
] | a111e69fc5edc5d81a31dca45755f21c8c512ed1 | https://github.com/absent1706/sqlalchemy-mixins/blob/a111e69fc5edc5d81a31dca45755f21c8c512ed1/sqlalchemy_mixins/serialize.py#L11-L31 | train |
absent1706/sqlalchemy-mixins | sqlalchemy_mixins/inspection.py | InspectionMixin.primary_keys_full | def primary_keys_full(cls):
"""Get primary key properties for a SQLAlchemy cls.
Taken from marshmallow_sqlalchemy
"""
mapper = cls.__mapper__
return [
mapper.get_property_by_column(column)
for column in mapper.primary_key
] | python | def primary_keys_full(cls):
"""Get primary key properties for a SQLAlchemy cls.
Taken from marshmallow_sqlalchemy
"""
mapper = cls.__mapper__
return [
mapper.get_property_by_column(column)
for column in mapper.primary_key
] | [
"def",
"primary_keys_full",
"(",
"cls",
")",
":",
"mapper",
"=",
"cls",
".",
"__mapper__",
"return",
"[",
"mapper",
".",
"get_property_by_column",
"(",
"column",
")",
"for",
"column",
"in",
"mapper",
".",
"primary_key",
"]"
] | Get primary key properties for a SQLAlchemy cls.
Taken from marshmallow_sqlalchemy | [
"Get",
"primary",
"key",
"properties",
"for",
"a",
"SQLAlchemy",
"cls",
".",
"Taken",
"from",
"marshmallow_sqlalchemy"
] | a111e69fc5edc5d81a31dca45755f21c8c512ed1 | https://github.com/absent1706/sqlalchemy-mixins/blob/a111e69fc5edc5d81a31dca45755f21c8c512ed1/sqlalchemy_mixins/inspection.py#L20-L28 | train |
absent1706/sqlalchemy-mixins | sqlalchemy_mixins/activerecord.py | ActiveRecordMixin.save | def save(self):
"""Saves the updated model to the current entity db.
"""
self.session.add(self)
self.session.flush()
return self | python | def save(self):
"""Saves the updated model to the current entity db.
"""
self.session.add(self)
self.session.flush()
return self | [
"def",
"save",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"add",
"(",
"self",
")",
"self",
".",
"session",
".",
"flush",
"(",
")",
"return",
"self"
] | Saves the updated model to the current entity db. | [
"Saves",
"the",
"updated",
"model",
"to",
"the",
"current",
"entity",
"db",
"."
] | a111e69fc5edc5d81a31dca45755f21c8c512ed1 | https://github.com/absent1706/sqlalchemy-mixins/blob/a111e69fc5edc5d81a31dca45755f21c8c512ed1/sqlalchemy_mixins/activerecord.py#L26-L31 | train |
diogobaeder/pycket | pycket/session.py | SessionManager.get | def get(self, name, default=None):
'''
Gets the object for "name", or None if there's no such object. If
"default" is provided, return it if no object is found.
'''
session = self.__get_session_from_db()
return session.get(name, default) | python | def get(self, name, default=None):
'''
Gets the object for "name", or None if there's no such object. If
"default" is provided, return it if no object is found.
'''
session = self.__get_session_from_db()
return session.get(name, default) | [
"def",
"get",
"(",
"self",
",",
"name",
",",
"default",
"=",
"None",
")",
":",
"session",
"=",
"self",
".",
"__get_session_from_db",
"(",
")",
"return",
"session",
".",
"get",
"(",
"name",
",",
"default",
")"
] | Gets the object for "name", or None if there's no such object. If
"default" is provided, return it if no object is found. | [
"Gets",
"the",
"object",
"for",
"name",
"or",
"None",
"if",
"there",
"s",
"no",
"such",
"object",
".",
"If",
"default",
"is",
"provided",
"return",
"it",
"if",
"no",
"object",
"is",
"found",
"."
] | b21d1553b4100d820a6922eeb55baa2329bc02c2 | https://github.com/diogobaeder/pycket/blob/b21d1553b4100d820a6922eeb55baa2329bc02c2/pycket/session.py#L89-L97 | train |
diogobaeder/pycket | pycket/session.py | SessionManager.delete | def delete(self, *names):
'''
Deletes the object with "name" from the session, if exists.
'''
def change(session):
keys = session.keys()
names_in_common = [name for name in names if name in keys]
for name in names_in_common:
del sessio... | python | def delete(self, *names):
'''
Deletes the object with "name" from the session, if exists.
'''
def change(session):
keys = session.keys()
names_in_common = [name for name in names if name in keys]
for name in names_in_common:
del sessio... | [
"def",
"delete",
"(",
"self",
",",
"*",
"names",
")",
":",
"def",
"change",
"(",
"session",
")",
":",
"keys",
"=",
"session",
".",
"keys",
"(",
")",
"names_in_common",
"=",
"[",
"name",
"for",
"name",
"in",
"names",
"if",
"name",
"in",
"keys",
"]",... | Deletes the object with "name" from the session, if exists. | [
"Deletes",
"the",
"object",
"with",
"name",
"from",
"the",
"session",
"if",
"exists",
"."
] | b21d1553b4100d820a6922eeb55baa2329bc02c2 | https://github.com/diogobaeder/pycket/blob/b21d1553b4100d820a6922eeb55baa2329bc02c2/pycket/session.py#L99-L109 | train |
occrp-attic/exactitude | exactitude/date.py | DateType.validate | def validate(self, obj, **kwargs):
"""Check if a thing is a valid date."""
obj = stringify(obj)
if obj is None:
return False
return self.DATE_RE.match(obj) is not None | python | def validate(self, obj, **kwargs):
"""Check if a thing is a valid date."""
obj = stringify(obj)
if obj is None:
return False
return self.DATE_RE.match(obj) is not None | [
"def",
"validate",
"(",
"self",
",",
"obj",
",",
"**",
"kwargs",
")",
":",
"obj",
"=",
"stringify",
"(",
"obj",
")",
"if",
"obj",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"DATE_RE",
".",
"match",
"(",
"obj",
")",
"is",
"not",
... | Check if a thing is a valid date. | [
"Check",
"if",
"a",
"thing",
"is",
"a",
"valid",
"date",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/date.py#L18-L23 | train |
occrp-attic/exactitude | exactitude/date.py | DateType._clean_datetime | def _clean_datetime(self, obj):
"""Python objects want to be text."""
if isinstance(obj, datetime):
# if it's not naive, put it on zulu time first:
if obj.tzinfo is not None:
obj = obj.astimezone(pytz.utc)
return obj.isoformat()[:self.MAX_LENGTH]
... | python | def _clean_datetime(self, obj):
"""Python objects want to be text."""
if isinstance(obj, datetime):
# if it's not naive, put it on zulu time first:
if obj.tzinfo is not None:
obj = obj.astimezone(pytz.utc)
return obj.isoformat()[:self.MAX_LENGTH]
... | [
"def",
"_clean_datetime",
"(",
"self",
",",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"datetime",
")",
":",
"if",
"obj",
".",
"tzinfo",
"is",
"not",
"None",
":",
"obj",
"=",
"obj",
".",
"astimezone",
"(",
"pytz",
".",
"utc",
")",
"retur... | Python objects want to be text. | [
"Python",
"objects",
"want",
"to",
"be",
"text",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/date.py#L25-L33 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter.parse | def parse(self):
"""
Parse a result directory to extract the pieces information to be
stored in NIDM-Results.
"""
try:
# Methods: find_software, find_model_fitting, find_contrasts and
# find_inferences should be defined in the children classes and
... | python | def parse(self):
"""
Parse a result directory to extract the pieces information to be
stored in NIDM-Results.
"""
try:
# Methods: find_software, find_model_fitting, find_contrasts and
# find_inferences should be defined in the children classes and
... | [
"def",
"parse",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"software",
"=",
"self",
".",
"_find_software",
"(",
")",
"self",
".",
"model_fittings",
"=",
"self",
".",
"_find_model_fitting",
"(",
")",
"self",
".",
"contrasts",
"=",
"self",
".",
"_fi... | Parse a result directory to extract the pieces information to be
stored in NIDM-Results. | [
"Parse",
"a",
"result",
"directory",
"to",
"extract",
"the",
"pieces",
"information",
"to",
"be",
"stored",
"in",
"NIDM",
"-",
"Results",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L81-L117 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter.add_object | def add_object(self, nidm_object, export_file=True):
"""
Add a NIDMObject to a NIDM-Results export.
"""
if not export_file:
export_dir = None
else:
export_dir = self.export_dir
if not isinstance(nidm_object, NIDMFile):
nidm_object.expo... | python | def add_object(self, nidm_object, export_file=True):
"""
Add a NIDMObject to a NIDM-Results export.
"""
if not export_file:
export_dir = None
else:
export_dir = self.export_dir
if not isinstance(nidm_object, NIDMFile):
nidm_object.expo... | [
"def",
"add_object",
"(",
"self",
",",
"nidm_object",
",",
"export_file",
"=",
"True",
")",
":",
"if",
"not",
"export_file",
":",
"export_dir",
"=",
"None",
"else",
":",
"export_dir",
"=",
"self",
".",
"export_dir",
"if",
"not",
"isinstance",
"(",
"nidm_ob... | Add a NIDMObject to a NIDM-Results export. | [
"Add",
"a",
"NIDMObject",
"to",
"a",
"NIDM",
"-",
"Results",
"export",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L123-L145 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter._get_model_fitting | def _get_model_fitting(self, mf_id):
"""
Retreive model fitting with identifier 'mf_id' from the list of model
fitting objects stored in self.model_fitting
"""
for model_fitting in self.model_fittings:
if model_fitting.activity.id == mf_id:
return mode... | python | def _get_model_fitting(self, mf_id):
"""
Retreive model fitting with identifier 'mf_id' from the list of model
fitting objects stored in self.model_fitting
"""
for model_fitting in self.model_fittings:
if model_fitting.activity.id == mf_id:
return mode... | [
"def",
"_get_model_fitting",
"(",
"self",
",",
"mf_id",
")",
":",
"for",
"model_fitting",
"in",
"self",
".",
"model_fittings",
":",
"if",
"model_fitting",
".",
"activity",
".",
"id",
"==",
"mf_id",
":",
"return",
"model_fitting",
"raise",
"Exception",
"(",
"... | Retreive model fitting with identifier 'mf_id' from the list of model
fitting objects stored in self.model_fitting | [
"Retreive",
"model",
"fitting",
"with",
"identifier",
"mf_id",
"from",
"the",
"list",
"of",
"model",
"fitting",
"objects",
"stored",
"in",
"self",
".",
"model_fitting"
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L534-L544 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter._get_contrast | def _get_contrast(self, con_id):
"""
Retreive contrast with identifier 'con_id' from the list of contrast
objects stored in self.contrasts
"""
for contrasts in list(self.contrasts.values()):
for contrast in contrasts:
if contrast.estimation.id == con_i... | python | def _get_contrast(self, con_id):
"""
Retreive contrast with identifier 'con_id' from the list of contrast
objects stored in self.contrasts
"""
for contrasts in list(self.contrasts.values()):
for contrast in contrasts:
if contrast.estimation.id == con_i... | [
"def",
"_get_contrast",
"(",
"self",
",",
"con_id",
")",
":",
"for",
"contrasts",
"in",
"list",
"(",
"self",
".",
"contrasts",
".",
"values",
"(",
")",
")",
":",
"for",
"contrast",
"in",
"contrasts",
":",
"if",
"contrast",
".",
"estimation",
".",
"id",... | Retreive contrast with identifier 'con_id' from the list of contrast
objects stored in self.contrasts | [
"Retreive",
"contrast",
"with",
"identifier",
"con_id",
"from",
"the",
"list",
"of",
"contrast",
"objects",
"stored",
"in",
"self",
".",
"contrasts"
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L546-L556 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter._add_namespaces | def _add_namespaces(self):
"""
Add namespaces to NIDM document.
"""
self.doc.add_namespace(NIDM)
self.doc.add_namespace(NIIRI)
self.doc.add_namespace(CRYPTO)
self.doc.add_namespace(DCT)
self.doc.add_namespace(DC)
self.doc.add_namespace(NFO)
... | python | def _add_namespaces(self):
"""
Add namespaces to NIDM document.
"""
self.doc.add_namespace(NIDM)
self.doc.add_namespace(NIIRI)
self.doc.add_namespace(CRYPTO)
self.doc.add_namespace(DCT)
self.doc.add_namespace(DC)
self.doc.add_namespace(NFO)
... | [
"def",
"_add_namespaces",
"(",
"self",
")",
":",
"self",
".",
"doc",
".",
"add_namespace",
"(",
"NIDM",
")",
"self",
".",
"doc",
".",
"add_namespace",
"(",
"NIIRI",
")",
"self",
".",
"doc",
".",
"add_namespace",
"(",
"CRYPTO",
")",
"self",
".",
"doc",
... | Add namespaces to NIDM document. | [
"Add",
"namespaces",
"to",
"NIDM",
"document",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L558-L570 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter._create_bundle | def _create_bundle(self, version):
"""
Initialise NIDM-Results bundle.
"""
# *** Bundle entity
if not hasattr(self, 'bundle_ent'):
self.bundle_ent = NIDMResultsBundle(nidm_version=version['num'])
self.bundle = ProvBundle(identifier=self.bundle_ent.id)
... | python | def _create_bundle(self, version):
"""
Initialise NIDM-Results bundle.
"""
# *** Bundle entity
if not hasattr(self, 'bundle_ent'):
self.bundle_ent = NIDMResultsBundle(nidm_version=version['num'])
self.bundle = ProvBundle(identifier=self.bundle_ent.id)
... | [
"def",
"_create_bundle",
"(",
"self",
",",
"version",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'bundle_ent'",
")",
":",
"self",
".",
"bundle_ent",
"=",
"NIDMResultsBundle",
"(",
"nidm_version",
"=",
"version",
"[",
"'num'",
"]",
")",
"self",
... | Initialise NIDM-Results bundle. | [
"Initialise",
"NIDM",
"-",
"Results",
"bundle",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L572-L621 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter._get_model_parameters_estimations | def _get_model_parameters_estimations(self, error_model):
"""
Infer model estimation method from the 'error_model'. Return an object
of type ModelParametersEstimation.
"""
if error_model.dependance == NIDM_INDEPEDENT_ERROR:
if error_model.variance_homo:
... | python | def _get_model_parameters_estimations(self, error_model):
"""
Infer model estimation method from the 'error_model'. Return an object
of type ModelParametersEstimation.
"""
if error_model.dependance == NIDM_INDEPEDENT_ERROR:
if error_model.variance_homo:
... | [
"def",
"_get_model_parameters_estimations",
"(",
"self",
",",
"error_model",
")",
":",
"if",
"error_model",
".",
"dependance",
"==",
"NIDM_INDEPEDENT_ERROR",
":",
"if",
"error_model",
".",
"variance_homo",
":",
"estimation_method",
"=",
"STATO_OLS",
"else",
":",
"es... | Infer model estimation method from the 'error_model'. Return an object
of type ModelParametersEstimation. | [
"Infer",
"model",
"estimation",
"method",
"from",
"the",
"error_model",
".",
"Return",
"an",
"object",
"of",
"type",
"ModelParametersEstimation",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L623-L638 | train |
incf-nidash/nidmresults | nidmresults/exporter.py | NIDMExporter.save_prov_to_files | def save_prov_to_files(self, showattributes=False):
"""
Write-out provn serialisation to nidm.provn.
"""
self.doc.add_bundle(self.bundle)
# provn_file = os.path.join(self.export_dir, 'nidm.provn')
# provn_fid = open(provn_file, 'w')
# # FIXME None
# # prov... | python | def save_prov_to_files(self, showattributes=False):
"""
Write-out provn serialisation to nidm.provn.
"""
self.doc.add_bundle(self.bundle)
# provn_file = os.path.join(self.export_dir, 'nidm.provn')
# provn_fid = open(provn_file, 'w')
# # FIXME None
# # prov... | [
"def",
"save_prov_to_files",
"(",
"self",
",",
"showattributes",
"=",
"False",
")",
":",
"self",
".",
"doc",
".",
"add_bundle",
"(",
"self",
".",
"bundle",
")",
"ttl_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"export_dir",
",",
"'nid... | Write-out provn serialisation to nidm.provn. | [
"Write",
"-",
"out",
"provn",
"serialisation",
"to",
"nidm",
".",
"provn",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/exporter.py#L659-L721 | train |
occrp-attic/exactitude | exactitude/phone.py | PhoneType.clean_text | def clean_text(self, number, countries=None, country=None, **kwargs):
"""Parse a phone number and return in international format.
If no valid phone number can be detected, None is returned. If
a country code is supplied, this will be used to infer the
prefix.
https://github.com... | python | def clean_text(self, number, countries=None, country=None, **kwargs):
"""Parse a phone number and return in international format.
If no valid phone number can be detected, None is returned. If
a country code is supplied, this will be used to infer the
prefix.
https://github.com... | [
"def",
"clean_text",
"(",
"self",
",",
"number",
",",
"countries",
"=",
"None",
",",
"country",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"for",
"code",
"in",
"self",
".",
"_clean_countries",
"(",
"countries",
",",
"country",
")",
":",
"try",
":",
... | Parse a phone number and return in international format.
If no valid phone number can be detected, None is returned. If
a country code is supplied, this will be used to infer the
prefix.
https://github.com/daviddrysdale/python-phonenumbers | [
"Parse",
"a",
"phone",
"number",
"and",
"return",
"in",
"international",
"format",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/phone.py#L23-L39 | train |
occrp-attic/exactitude | exactitude/ip.py | IpType.validate | def validate(self, ip, **kwargs):
"""Check to see if this is a valid ip address."""
if ip is None:
return False
ip = stringify(ip)
if self.IPV4_REGEX.match(ip):
try:
socket.inet_pton(socket.AF_INET, ip)
return True
... | python | def validate(self, ip, **kwargs):
"""Check to see if this is a valid ip address."""
if ip is None:
return False
ip = stringify(ip)
if self.IPV4_REGEX.match(ip):
try:
socket.inet_pton(socket.AF_INET, ip)
return True
... | [
"def",
"validate",
"(",
"self",
",",
"ip",
",",
"**",
"kwargs",
")",
":",
"if",
"ip",
"is",
"None",
":",
"return",
"False",
"ip",
"=",
"stringify",
"(",
"ip",
")",
"if",
"self",
".",
"IPV4_REGEX",
".",
"match",
"(",
"ip",
")",
":",
"try",
":",
... | Check to see if this is a valid ip address. | [
"Check",
"to",
"see",
"if",
"this",
"is",
"a",
"valid",
"ip",
"address",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/ip.py#L15-L42 | train |
incf-nidash/nidmresults | nidmresults/objects/generic.py | NIDMFile.export | def export(self, nidm_version, export_dir, prepend_path):
"""
Copy file over of export_dir and create corresponding triples
"""
if self.path is not None:
if export_dir is not None:
# Copy file only if export_dir is not None
new_file = os.path.j... | python | def export(self, nidm_version, export_dir, prepend_path):
"""
Copy file over of export_dir and create corresponding triples
"""
if self.path is not None:
if export_dir is not None:
# Copy file only if export_dir is not None
new_file = os.path.j... | [
"def",
"export",
"(",
"self",
",",
"nidm_version",
",",
"export_dir",
",",
"prepend_path",
")",
":",
"if",
"self",
".",
"path",
"is",
"not",
"None",
":",
"if",
"export_dir",
"is",
"not",
"None",
":",
"new_file",
"=",
"os",
".",
"path",
".",
"join",
"... | Copy file over of export_dir and create corresponding triples | [
"Copy",
"file",
"over",
"of",
"export_dir",
"and",
"create",
"corresponding",
"triples"
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/objects/generic.py#L289-L339 | train |
incf-nidash/nidmresults | nidmresults/objects/generic.py | Image.export | def export(self, nidm_version, export_dir):
"""
Create prov entity.
"""
if self.file is not None:
self.add_attributes([
(PROV['type'], self.type),
(DCT['format'], "image/png"),
]) | python | def export(self, nidm_version, export_dir):
"""
Create prov entity.
"""
if self.file is not None:
self.add_attributes([
(PROV['type'], self.type),
(DCT['format'], "image/png"),
]) | [
"def",
"export",
"(",
"self",
",",
"nidm_version",
",",
"export_dir",
")",
":",
"if",
"self",
".",
"file",
"is",
"not",
"None",
":",
"self",
".",
"add_attributes",
"(",
"[",
"(",
"PROV",
"[",
"'type'",
"]",
",",
"self",
".",
"type",
")",
",",
"(",
... | Create prov entity. | [
"Create",
"prov",
"entity",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/objects/generic.py#L376-L384 | train |
occrp-attic/exactitude | exactitude/address.py | AddressType.normalize | def normalize(self, address, **kwargs):
"""Make the address more compareable."""
# TODO: normalize well-known parts like "Street", "Road", etc.
# TODO: consider using https://github.com/openvenues/pypostal
addresses = super(AddressType, self).normalize(address, **kwargs)
return a... | python | def normalize(self, address, **kwargs):
"""Make the address more compareable."""
# TODO: normalize well-known parts like "Street", "Road", etc.
# TODO: consider using https://github.com/openvenues/pypostal
addresses = super(AddressType, self).normalize(address, **kwargs)
return a... | [
"def",
"normalize",
"(",
"self",
",",
"address",
",",
"**",
"kwargs",
")",
":",
"addresses",
"=",
"super",
"(",
"AddressType",
",",
"self",
")",
".",
"normalize",
"(",
"address",
",",
"**",
"kwargs",
")",
"return",
"addresses"
] | Make the address more compareable. | [
"Make",
"the",
"address",
"more",
"compareable",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/address.py#L19-L24 | train |
occrp-attic/exactitude | exactitude/url.py | UrlType.clean_text | def clean_text(self, url, **kwargs):
"""Perform intensive care on URLs, see `urlnormalizer`."""
try:
return normalize_url(url)
except UnicodeDecodeError:
log.warning("Invalid URL: %r", url) | python | def clean_text(self, url, **kwargs):
"""Perform intensive care on URLs, see `urlnormalizer`."""
try:
return normalize_url(url)
except UnicodeDecodeError:
log.warning("Invalid URL: %r", url) | [
"def",
"clean_text",
"(",
"self",
",",
"url",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"return",
"normalize_url",
"(",
"url",
")",
"except",
"UnicodeDecodeError",
":",
"log",
".",
"warning",
"(",
"\"Invalid URL: %r\"",
",",
"url",
")"
] | Perform intensive care on URLs, see `urlnormalizer`. | [
"Perform",
"intensive",
"care",
"on",
"URLs",
"see",
"urlnormalizer",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/url.py#L15-L20 | train |
occrp-attic/exactitude | exactitude/country.py | CountryType.clean_text | def clean_text(self, country, guess=False, **kwargs):
"""Determine a two-letter country code based on an input.
The input may be a country code, a country name, etc.
"""
code = country.lower().strip()
if code in self.names:
return code
country = countrynames.... | python | def clean_text(self, country, guess=False, **kwargs):
"""Determine a two-letter country code based on an input.
The input may be a country code, a country name, etc.
"""
code = country.lower().strip()
if code in self.names:
return code
country = countrynames.... | [
"def",
"clean_text",
"(",
"self",
",",
"country",
",",
"guess",
"=",
"False",
",",
"**",
"kwargs",
")",
":",
"code",
"=",
"country",
".",
"lower",
"(",
")",
".",
"strip",
"(",
")",
"if",
"code",
"in",
"self",
".",
"names",
":",
"return",
"code",
... | Determine a two-letter country code based on an input.
The input may be a country code, a country name, etc. | [
"Determine",
"a",
"two",
"-",
"letter",
"country",
"code",
"based",
"on",
"an",
"input",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/country.py#L35-L45 | train |
occrp-attic/exactitude | exactitude/email.py | EmailType.validate | def validate(self, email, **kwargs):
"""Check to see if this is a valid email address."""
email = stringify(email)
if email is None:
return
if not self.EMAIL_REGEX.match(email):
return False
mailbox, domain = email.rsplit('@', 1)
return self.domain... | python | def validate(self, email, **kwargs):
"""Check to see if this is a valid email address."""
email = stringify(email)
if email is None:
return
if not self.EMAIL_REGEX.match(email):
return False
mailbox, domain = email.rsplit('@', 1)
return self.domain... | [
"def",
"validate",
"(",
"self",
",",
"email",
",",
"**",
"kwargs",
")",
":",
"email",
"=",
"stringify",
"(",
"email",
")",
"if",
"email",
"is",
"None",
":",
"return",
"if",
"not",
"self",
".",
"EMAIL_REGEX",
".",
"match",
"(",
"email",
")",
":",
"r... | Check to see if this is a valid email address. | [
"Check",
"to",
"see",
"if",
"this",
"is",
"a",
"valid",
"email",
"address",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/email.py#L15-L23 | train |
occrp-attic/exactitude | exactitude/email.py | EmailType.clean_text | def clean_text(self, email, **kwargs):
"""Parse and normalize an email address.
Returns None if this is not an email address.
"""
if not self.EMAIL_REGEX.match(email):
return None
email = strip_quotes(email)
mailbox, domain = email.rsplit('@', 1)
doma... | python | def clean_text(self, email, **kwargs):
"""Parse and normalize an email address.
Returns None if this is not an email address.
"""
if not self.EMAIL_REGEX.match(email):
return None
email = strip_quotes(email)
mailbox, domain = email.rsplit('@', 1)
doma... | [
"def",
"clean_text",
"(",
"self",
",",
"email",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"EMAIL_REGEX",
".",
"match",
"(",
"email",
")",
":",
"return",
"None",
"email",
"=",
"strip_quotes",
"(",
"email",
")",
"mailbox",
",",
"domain",
... | Parse and normalize an email address.
Returns None if this is not an email address. | [
"Parse",
"and",
"normalize",
"an",
"email",
"address",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/email.py#L25-L37 | train |
incf-nidash/nidmresults | nidmresults/graph.py | NIDMResults.fix_for_specific_versions | def fix_for_specific_versions(self, rdf_data, to_replace):
"""
Fixes of the RDF before loading the graph. All of these are workaround
to circuvent known issues of the SPM and FSL exporters.
"""
# Load the graph as is so that we can query
g = self.parse(rdf_data)
... | python | def fix_for_specific_versions(self, rdf_data, to_replace):
"""
Fixes of the RDF before loading the graph. All of these are workaround
to circuvent known issues of the SPM and FSL exporters.
"""
# Load the graph as is so that we can query
g = self.parse(rdf_data)
... | [
"def",
"fix_for_specific_versions",
"(",
"self",
",",
"rdf_data",
",",
"to_replace",
")",
":",
"g",
"=",
"self",
".",
"parse",
"(",
"rdf_data",
")",
"query",
"=",
"sd",
"=",
"g",
".",
"query",
"(",
"query",
")",
"objects",
"=",
"dict",
"(",
")",
"if"... | Fixes of the RDF before loading the graph. All of these are workaround
to circuvent known issues of the SPM and FSL exporters. | [
"Fixes",
"of",
"the",
"RDF",
"before",
"loading",
"the",
"graph",
".",
"All",
"of",
"these",
"are",
"workaround",
"to",
"circuvent",
"known",
"issues",
"of",
"the",
"SPM",
"and",
"FSL",
"exporters",
"."
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/graph.py#L59-L118 | train |
incf-nidash/nidmresults | nidmresults/graph.py | NIDMResults._get_model_fitting | def _get_model_fitting(self, con_est_id):
"""
Retreive model fitting that corresponds to contrast with identifier
'con_id'
from the list of model fitting objects stored in self.model_fittings
"""
for (mpe_id, pe_ids), contrasts in self.contrasts.items():
for c... | python | def _get_model_fitting(self, con_est_id):
"""
Retreive model fitting that corresponds to contrast with identifier
'con_id'
from the list of model fitting objects stored in self.model_fittings
"""
for (mpe_id, pe_ids), contrasts in self.contrasts.items():
for c... | [
"def",
"_get_model_fitting",
"(",
"self",
",",
"con_est_id",
")",
":",
"for",
"(",
"mpe_id",
",",
"pe_ids",
")",
",",
"contrasts",
"in",
"self",
".",
"contrasts",
".",
"items",
"(",
")",
":",
"for",
"contrast",
"in",
"contrasts",
":",
"if",
"contrast",
... | Retreive model fitting that corresponds to contrast with identifier
'con_id'
from the list of model fitting objects stored in self.model_fittings | [
"Retreive",
"model",
"fitting",
"that",
"corresponds",
"to",
"contrast",
"with",
"identifier",
"con_id",
"from",
"the",
"list",
"of",
"model",
"fitting",
"objects",
"stored",
"in",
"self",
".",
"model_fittings"
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/graph.py#L358-L376 | train |
occrp-attic/exactitude | exactitude/common.py | ExactitudeType.validate | def validate(self, text, **kwargs):
"""Returns a boolean to indicate if this is a valid instance of
the type."""
cleaned = self.clean(text, **kwargs)
return cleaned is not None | python | def validate(self, text, **kwargs):
"""Returns a boolean to indicate if this is a valid instance of
the type."""
cleaned = self.clean(text, **kwargs)
return cleaned is not None | [
"def",
"validate",
"(",
"self",
",",
"text",
",",
"**",
"kwargs",
")",
":",
"cleaned",
"=",
"self",
".",
"clean",
"(",
"text",
",",
"**",
"kwargs",
")",
"return",
"cleaned",
"is",
"not",
"None"
] | Returns a boolean to indicate if this is a valid instance of
the type. | [
"Returns",
"a",
"boolean",
"to",
"indicate",
"if",
"this",
"is",
"a",
"valid",
"instance",
"of",
"the",
"type",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/common.py#L12-L16 | train |
occrp-attic/exactitude | exactitude/common.py | ExactitudeType.normalize | def normalize(self, text, cleaned=False, **kwargs):
"""Create a represenation ideal for comparisons, but not to be
shown to the user."""
if not cleaned:
text = self.clean(text, **kwargs)
return ensure_list(text) | python | def normalize(self, text, cleaned=False, **kwargs):
"""Create a represenation ideal for comparisons, but not to be
shown to the user."""
if not cleaned:
text = self.clean(text, **kwargs)
return ensure_list(text) | [
"def",
"normalize",
"(",
"self",
",",
"text",
",",
"cleaned",
"=",
"False",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"cleaned",
":",
"text",
"=",
"self",
".",
"clean",
"(",
"text",
",",
"**",
"kwargs",
")",
"return",
"ensure_list",
"(",
"text",
... | Create a represenation ideal for comparisons, but not to be
shown to the user. | [
"Create",
"a",
"represenation",
"ideal",
"for",
"comparisons",
"but",
"not",
"to",
"be",
"shown",
"to",
"the",
"user",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/common.py#L28-L33 | train |
occrp-attic/exactitude | exactitude/common.py | ExactitudeType.normalize_set | def normalize_set(self, items, **kwargs):
"""Utility to normalize a whole set of values and get unique
values."""
values = set()
for item in ensure_list(items):
values.update(self.normalize(item, **kwargs))
return list(values) | python | def normalize_set(self, items, **kwargs):
"""Utility to normalize a whole set of values and get unique
values."""
values = set()
for item in ensure_list(items):
values.update(self.normalize(item, **kwargs))
return list(values) | [
"def",
"normalize_set",
"(",
"self",
",",
"items",
",",
"**",
"kwargs",
")",
":",
"values",
"=",
"set",
"(",
")",
"for",
"item",
"in",
"ensure_list",
"(",
"items",
")",
":",
"values",
".",
"update",
"(",
"self",
".",
"normalize",
"(",
"item",
",",
... | Utility to normalize a whole set of values and get unique
values. | [
"Utility",
"to",
"normalize",
"a",
"whole",
"set",
"of",
"values",
"and",
"get",
"unique",
"values",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/common.py#L35-L41 | train |
occrp-attic/exactitude | exactitude/domain.py | DomainType.validate | def validate(self, obj, **kwargs):
"""Check if a thing is a valid domain name."""
text = stringify(obj)
if text is None:
return False
if '.' not in text:
return False
if '@' in text or ':' in text:
return False
if len(text) < 4:
... | python | def validate(self, obj, **kwargs):
"""Check if a thing is a valid domain name."""
text = stringify(obj)
if text is None:
return False
if '.' not in text:
return False
if '@' in text or ':' in text:
return False
if len(text) < 4:
... | [
"def",
"validate",
"(",
"self",
",",
"obj",
",",
"**",
"kwargs",
")",
":",
"text",
"=",
"stringify",
"(",
"obj",
")",
"if",
"text",
"is",
"None",
":",
"return",
"False",
"if",
"'.'",
"not",
"in",
"text",
":",
"return",
"False",
"if",
"'@'",
"in",
... | Check if a thing is a valid domain name. | [
"Check",
"if",
"a",
"thing",
"is",
"a",
"valid",
"domain",
"name",
"."
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/domain.py#L20-L31 | train |
occrp-attic/exactitude | exactitude/domain.py | DomainType.clean_text | def clean_text(self, domain, **kwargs):
"""Try to extract only the domain bit from the """
try:
# handle URLs by extracting the domain name
domain = urlparse(domain).hostname or domain
domain = domain.lower()
# get rid of port specs
domain = do... | python | def clean_text(self, domain, **kwargs):
"""Try to extract only the domain bit from the """
try:
# handle URLs by extracting the domain name
domain = urlparse(domain).hostname or domain
domain = domain.lower()
# get rid of port specs
domain = do... | [
"def",
"clean_text",
"(",
"self",
",",
"domain",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"domain",
"=",
"urlparse",
"(",
"domain",
")",
".",
"hostname",
"or",
"domain",
"domain",
"=",
"domain",
".",
"lower",
"(",
")",
"domain",
"=",
"domain",
".",... | Try to extract only the domain bit from the | [
"Try",
"to",
"extract",
"only",
"the",
"domain",
"bit",
"from",
"the"
] | 9fe13aa70f1aac644dbc999e0b21683db507f02d | https://github.com/occrp-attic/exactitude/blob/9fe13aa70f1aac644dbc999e0b21683db507f02d/exactitude/domain.py#L33-L47 | train |
incf-nidash/nidmresults | nidmresults/load.py | load | def load(filename, to_replace=dict()):
''' Load NIDM-Results file given filename, guessing if it is a
NIDM-Results pack or a JSON file
Parameters
----------
filename : string
specification of file to load
Returns
-------
nidmres : ``NIDMResults``
NIDM-Results object
''... | python | def load(filename, to_replace=dict()):
''' Load NIDM-Results file given filename, guessing if it is a
NIDM-Results pack or a JSON file
Parameters
----------
filename : string
specification of file to load
Returns
-------
nidmres : ``NIDMResults``
NIDM-Results object
''... | [
"def",
"load",
"(",
"filename",
",",
"to_replace",
"=",
"dict",
"(",
")",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"filename",
")",
":",
"raise",
"IOException",
"(",
"'File does not exist: %s'",
"%",
"filename",
")",
"if",
"filename"... | Load NIDM-Results file given filename, guessing if it is a
NIDM-Results pack or a JSON file
Parameters
----------
filename : string
specification of file to load
Returns
-------
nidmres : ``NIDMResults``
NIDM-Results object | [
"Load",
"NIDM",
"-",
"Results",
"file",
"given",
"filename",
"guessing",
"if",
"it",
"is",
"a",
"NIDM",
"-",
"Results",
"pack",
"or",
"a",
"JSON",
"file"
] | 438f7cce6abc4a4379b629bd76f4d427891e033f | https://github.com/incf-nidash/nidmresults/blob/438f7cce6abc4a4379b629bd76f4d427891e033f/nidmresults/load.py#L7-L30 | train |
myint/cppclean | cpp/tokenize.py | _find | def _find(string, sub_string, start_index):
"""Return index of sub_string in string.
Raise TokenError if sub_string is not found.
"""
result = string.find(sub_string, start_index)
if result == -1:
raise TokenError("expected '{0}'".format(sub_string))
return result | python | def _find(string, sub_string, start_index):
"""Return index of sub_string in string.
Raise TokenError if sub_string is not found.
"""
result = string.find(sub_string, start_index)
if result == -1:
raise TokenError("expected '{0}'".format(sub_string))
return result | [
"def",
"_find",
"(",
"string",
",",
"sub_string",
",",
"start_index",
")",
":",
"result",
"=",
"string",
".",
"find",
"(",
"sub_string",
",",
"start_index",
")",
"if",
"result",
"==",
"-",
"1",
":",
"raise",
"TokenError",
"(",
"\"expected '{0}'\"",
".",
... | Return index of sub_string in string.
Raise TokenError if sub_string is not found. | [
"Return",
"index",
"of",
"sub_string",
"in",
"string",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/tokenize.py#L289-L297 | train |
myint/cppclean | cpp/ast.py | builder_from_source | def builder_from_source(source, filename, system_includes,
nonsystem_includes, quiet=False):
"""Utility method that returns an ASTBuilder from source code.
Args:
source: 'C++ source code'
filename: 'file1'
Returns:
ASTBuilder
"""
return ASTBuilder(tokenize... | python | def builder_from_source(source, filename, system_includes,
nonsystem_includes, quiet=False):
"""Utility method that returns an ASTBuilder from source code.
Args:
source: 'C++ source code'
filename: 'file1'
Returns:
ASTBuilder
"""
return ASTBuilder(tokenize... | [
"def",
"builder_from_source",
"(",
"source",
",",
"filename",
",",
"system_includes",
",",
"nonsystem_includes",
",",
"quiet",
"=",
"False",
")",
":",
"return",
"ASTBuilder",
"(",
"tokenize",
".",
"get_tokens",
"(",
"source",
")",
",",
"filename",
",",
"system... | Utility method that returns an ASTBuilder from source code.
Args:
source: 'C++ source code'
filename: 'file1'
Returns:
ASTBuilder | [
"Utility",
"method",
"that",
"returns",
"an",
"ASTBuilder",
"from",
"source",
"code",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/ast.py#L1654-L1669 | train |
myint/cppclean | cpp/ast.py | VariableDeclaration.to_string | def to_string(self):
"""Return a string that tries to reconstitute the variable decl."""
suffix = '%s %s' % (self.type, self.name)
if self.initial_value:
suffix += ' = ' + self.initial_value
return suffix | python | def to_string(self):
"""Return a string that tries to reconstitute the variable decl."""
suffix = '%s %s' % (self.type, self.name)
if self.initial_value:
suffix += ' = ' + self.initial_value
return suffix | [
"def",
"to_string",
"(",
"self",
")",
":",
"suffix",
"=",
"'%s %s'",
"%",
"(",
"self",
".",
"type",
",",
"self",
".",
"name",
")",
"if",
"self",
".",
"initial_value",
":",
"suffix",
"+=",
"' = '",
"+",
"self",
".",
"initial_value",
"return",
"suffix"
] | Return a string that tries to reconstitute the variable decl. | [
"Return",
"a",
"string",
"that",
"tries",
"to",
"reconstitute",
"the",
"variable",
"decl",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/ast.py#L201-L206 | train |
myint/cppclean | cpp/symbols.py | SymbolTable._lookup_namespace | def _lookup_namespace(self, symbol, namespace):
"""Helper for lookup_symbol that only looks up variables in a
namespace.
Args:
symbol: Symbol
namespace: pointer into self.namespaces
"""
for namespace_part in symbol.parts:
namespace = namespace.get... | python | def _lookup_namespace(self, symbol, namespace):
"""Helper for lookup_symbol that only looks up variables in a
namespace.
Args:
symbol: Symbol
namespace: pointer into self.namespaces
"""
for namespace_part in symbol.parts:
namespace = namespace.get... | [
"def",
"_lookup_namespace",
"(",
"self",
",",
"symbol",
",",
"namespace",
")",
":",
"for",
"namespace_part",
"in",
"symbol",
".",
"parts",
":",
"namespace",
"=",
"namespace",
".",
"get",
"(",
"namespace_part",
")",
"if",
"namespace",
"is",
"None",
":",
"br... | Helper for lookup_symbol that only looks up variables in a
namespace.
Args:
symbol: Symbol
namespace: pointer into self.namespaces | [
"Helper",
"for",
"lookup_symbol",
"that",
"only",
"looks",
"up",
"variables",
"in",
"a",
"namespace",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L48-L62 | train |
myint/cppclean | cpp/symbols.py | SymbolTable._lookup_global | def _lookup_global(self, symbol):
"""Helper for lookup_symbol that only looks up global variables.
Args:
symbol: Symbol
"""
assert symbol.parts
namespace = self.namespaces
if len(symbol.parts) == 1:
# If there is only one part, look in globals.
... | python | def _lookup_global(self, symbol):
"""Helper for lookup_symbol that only looks up global variables.
Args:
symbol: Symbol
"""
assert symbol.parts
namespace = self.namespaces
if len(symbol.parts) == 1:
# If there is only one part, look in globals.
... | [
"def",
"_lookup_global",
"(",
"self",
",",
"symbol",
")",
":",
"assert",
"symbol",
".",
"parts",
"namespace",
"=",
"self",
".",
"namespaces",
"if",
"len",
"(",
"symbol",
".",
"parts",
")",
"==",
"1",
":",
"namespace",
"=",
"self",
".",
"namespaces",
"[... | Helper for lookup_symbol that only looks up global variables.
Args:
symbol: Symbol | [
"Helper",
"for",
"lookup_symbol",
"that",
"only",
"looks",
"up",
"global",
"variables",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L64-L85 | train |
myint/cppclean | cpp/symbols.py | SymbolTable._lookup_in_all_namespaces | def _lookup_in_all_namespaces(self, symbol):
"""Helper for lookup_symbol that looks for symbols in all namespaces.
Args:
symbol: Symbol
"""
namespace = self.namespaces
# Create a stack of namespaces.
namespace_stack = []
for current in symbol.namespace_... | python | def _lookup_in_all_namespaces(self, symbol):
"""Helper for lookup_symbol that looks for symbols in all namespaces.
Args:
symbol: Symbol
"""
namespace = self.namespaces
# Create a stack of namespaces.
namespace_stack = []
for current in symbol.namespace_... | [
"def",
"_lookup_in_all_namespaces",
"(",
"self",
",",
"symbol",
")",
":",
"namespace",
"=",
"self",
".",
"namespaces",
"namespace_stack",
"=",
"[",
"]",
"for",
"current",
"in",
"symbol",
".",
"namespace_stack",
":",
"namespace",
"=",
"namespace",
".",
"get",
... | Helper for lookup_symbol that looks for symbols in all namespaces.
Args:
symbol: Symbol | [
"Helper",
"for",
"lookup_symbol",
"that",
"looks",
"for",
"symbols",
"in",
"all",
"namespaces",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L87-L109 | train |
myint/cppclean | cpp/symbols.py | SymbolTable.lookup_symbol | def lookup_symbol(self, name, namespace_stack):
"""Returns AST node and module for symbol if found.
Args:
name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'in', 'current', 'scope']
Returns:
(ast.Node, module (ie, any object stored with ... | python | def lookup_symbol(self, name, namespace_stack):
"""Returns AST node and module for symbol if found.
Args:
name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'in', 'current', 'scope']
Returns:
(ast.Node, module (ie, any object stored with ... | [
"def",
"lookup_symbol",
"(",
"self",
",",
"name",
",",
"namespace_stack",
")",
":",
"symbol",
"=",
"Symbol",
"(",
"name",
",",
"name",
".",
"split",
"(",
"'::'",
")",
",",
"namespace_stack",
")",
"assert",
"symbol",
".",
"parts",
"if",
"symbol",
".",
"... | Returns AST node and module for symbol if found.
Args:
name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'in', 'current', 'scope']
Returns:
(ast.Node, module (ie, any object stored with symbol)) if found
Raises:
Error if the s... | [
"Returns",
"AST",
"node",
"and",
"module",
"for",
"symbol",
"if",
"found",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L111-L141 | train |
myint/cppclean | cpp/symbols.py | SymbolTable._add | def _add(self, symbol_name, namespace, node, module):
"""Helper function for adding symbols.
See add_symbol().
"""
result = symbol_name in namespace
namespace[symbol_name] = node, module
return not result | python | def _add(self, symbol_name, namespace, node, module):
"""Helper function for adding symbols.
See add_symbol().
"""
result = symbol_name in namespace
namespace[symbol_name] = node, module
return not result | [
"def",
"_add",
"(",
"self",
",",
"symbol_name",
",",
"namespace",
",",
"node",
",",
"module",
")",
":",
"result",
"=",
"symbol_name",
"in",
"namespace",
"namespace",
"[",
"symbol_name",
"]",
"=",
"node",
",",
"module",
"return",
"not",
"result"
] | Helper function for adding symbols.
See add_symbol(). | [
"Helper",
"function",
"for",
"adding",
"symbols",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L143-L150 | train |
myint/cppclean | cpp/symbols.py | SymbolTable.add_symbol | def add_symbol(self, symbol_name, namespace_stack, node, module):
"""Adds symbol_name defined in namespace_stack to the symbol table.
Args:
symbol_name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'symbol', 'defined', 'in']
node: ast.Node that de... | python | def add_symbol(self, symbol_name, namespace_stack, node, module):
"""Adds symbol_name defined in namespace_stack to the symbol table.
Args:
symbol_name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'symbol', 'defined', 'in']
node: ast.Node that de... | [
"def",
"add_symbol",
"(",
"self",
",",
"symbol_name",
",",
"namespace_stack",
",",
"node",
",",
"module",
")",
":",
"if",
"namespace_stack",
":",
"last_namespace",
"=",
"self",
".",
"namespaces",
"for",
"namespace",
"in",
"namespace_stack",
":",
"last_namespace"... | Adds symbol_name defined in namespace_stack to the symbol table.
Args:
symbol_name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'symbol', 'defined', 'in']
node: ast.Node that defines this symbol
module: module (any object) this symbol is define... | [
"Adds",
"symbol_name",
"defined",
"in",
"namespace_stack",
"to",
"the",
"symbol",
"table",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L152-L172 | train |
myint/cppclean | cpp/symbols.py | SymbolTable.get_namespace | def get_namespace(self, name_seq):
"""Returns the prefix of names from name_seq that are known namespaces.
Args:
name_seq: ['names', 'of', 'possible', 'namespace', 'to', 'find']
Returns:
['names', 'that', 'are', 'namespaces', 'possibly', 'empty', 'list']
"""
... | python | def get_namespace(self, name_seq):
"""Returns the prefix of names from name_seq that are known namespaces.
Args:
name_seq: ['names', 'of', 'possible', 'namespace', 'to', 'find']
Returns:
['names', 'that', 'are', 'namespaces', 'possibly', 'empty', 'list']
"""
... | [
"def",
"get_namespace",
"(",
"self",
",",
"name_seq",
")",
":",
"namespaces",
"=",
"self",
".",
"namespaces",
"result",
"=",
"[",
"]",
"for",
"name",
"in",
"name_seq",
":",
"namespaces",
"=",
"namespaces",
".",
"get",
"(",
"name",
")",
"if",
"not",
"na... | Returns the prefix of names from name_seq that are known namespaces.
Args:
name_seq: ['names', 'of', 'possible', 'namespace', 'to', 'find']
Returns:
['names', 'that', 'are', 'namespaces', 'possibly', 'empty', 'list'] | [
"Returns",
"the",
"prefix",
"of",
"names",
"from",
"name_seq",
"that",
"are",
"known",
"namespaces",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/symbols.py#L174-L190 | train |
myint/cppclean | cpp/find_warnings.py | WarningHunter._verify_forward_declarations_used | def _verify_forward_declarations_used(self, forward_declarations,
decl_uses, file_uses):
"""Find all the forward declarations that are not used."""
for cls in forward_declarations:
if cls in file_uses:
if not decl_uses[cls] & USES_DEC... | python | def _verify_forward_declarations_used(self, forward_declarations,
decl_uses, file_uses):
"""Find all the forward declarations that are not used."""
for cls in forward_declarations:
if cls in file_uses:
if not decl_uses[cls] & USES_DEC... | [
"def",
"_verify_forward_declarations_used",
"(",
"self",
",",
"forward_declarations",
",",
"decl_uses",
",",
"file_uses",
")",
":",
"for",
"cls",
"in",
"forward_declarations",
":",
"if",
"cls",
"in",
"file_uses",
":",
"if",
"not",
"decl_uses",
"[",
"cls",
"]",
... | Find all the forward declarations that are not used. | [
"Find",
"all",
"the",
"forward",
"declarations",
"that",
"are",
"not",
"used",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/find_warnings.py#L223-L237 | train |
myint/cppclean | cpp/find_warnings.py | WarningHunter._check_public_functions | def _check_public_functions(self, primary_header, all_headers):
"""Verify all the public functions are also declared in a header
file."""
public_symbols = {}
declared_only_symbols = {}
if primary_header:
for name, symbol in primary_header.public_symbols.items():
... | python | def _check_public_functions(self, primary_header, all_headers):
"""Verify all the public functions are also declared in a header
file."""
public_symbols = {}
declared_only_symbols = {}
if primary_header:
for name, symbol in primary_header.public_symbols.items():
... | [
"def",
"_check_public_functions",
"(",
"self",
",",
"primary_header",
",",
"all_headers",
")",
":",
"public_symbols",
"=",
"{",
"}",
"declared_only_symbols",
"=",
"{",
"}",
"if",
"primary_header",
":",
"for",
"name",
",",
"symbol",
"in",
"primary_header",
".",
... | Verify all the public functions are also declared in a header
file. | [
"Verify",
"all",
"the",
"public",
"functions",
"are",
"also",
"declared",
"in",
"a",
"header",
"file",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/find_warnings.py#L521-L560 | train |
myint/cppclean | cpp/static_data.py | _find_unused_static_warnings | def _find_unused_static_warnings(filename, lines, ast_list):
"""Warn about unused static variables."""
static_declarations = dict(_get_static_declarations(ast_list))
def find_variables_use(body):
for child in body:
if child.name in static_declarations:
static_use_counts[... | python | def _find_unused_static_warnings(filename, lines, ast_list):
"""Warn about unused static variables."""
static_declarations = dict(_get_static_declarations(ast_list))
def find_variables_use(body):
for child in body:
if child.name in static_declarations:
static_use_counts[... | [
"def",
"_find_unused_static_warnings",
"(",
"filename",
",",
"lines",
",",
"ast_list",
")",
":",
"static_declarations",
"=",
"dict",
"(",
"_get_static_declarations",
"(",
"ast_list",
")",
")",
"def",
"find_variables_use",
"(",
"body",
")",
":",
"for",
"child",
"... | Warn about unused static variables. | [
"Warn",
"about",
"unused",
"static",
"variables",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/static_data.py#L84-L112 | train |
myint/cppclean | cpp/utils.py | read_file | def read_file(filename, print_error=True):
"""Returns the contents of a file."""
try:
for encoding in ['utf-8', 'latin1']:
try:
with io.open(filename, encoding=encoding) as fp:
return fp.read()
except UnicodeDecodeError:
pass
... | python | def read_file(filename, print_error=True):
"""Returns the contents of a file."""
try:
for encoding in ['utf-8', 'latin1']:
try:
with io.open(filename, encoding=encoding) as fp:
return fp.read()
except UnicodeDecodeError:
pass
... | [
"def",
"read_file",
"(",
"filename",
",",
"print_error",
"=",
"True",
")",
":",
"try",
":",
"for",
"encoding",
"in",
"[",
"'utf-8'",
",",
"'latin1'",
"]",
":",
"try",
":",
"with",
"io",
".",
"open",
"(",
"filename",
",",
"encoding",
"=",
"encoding",
... | Returns the contents of a file. | [
"Returns",
"the",
"contents",
"of",
"a",
"file",
"."
] | 8a20c943dca1049e87d57137938f92d7735828dc | https://github.com/myint/cppclean/blob/8a20c943dca1049e87d57137938f92d7735828dc/cpp/utils.py#L29-L41 | train |
dbrattli/OSlash | oslash/reader.py | Reader.map | def map(self, fn: Callable[[Any], Any]) -> 'Reader':
r"""Map a function over the Reader.
Haskell:
fmap f m = Reader $ \r -> f (runReader m r).
fmap f g = (\x -> f (g x))
"""
def _compose(x: Any) -> Any:
try:
ret = fn(self.run(x))
e... | python | def map(self, fn: Callable[[Any], Any]) -> 'Reader':
r"""Map a function over the Reader.
Haskell:
fmap f m = Reader $ \r -> f (runReader m r).
fmap f g = (\x -> f (g x))
"""
def _compose(x: Any) -> Any:
try:
ret = fn(self.run(x))
e... | [
"def",
"map",
"(",
"self",
",",
"fn",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Any",
"]",
")",
"->",
"'Reader'",
":",
"r",
"def",
"_compose",
"(",
"x",
":",
"Any",
")",
"->",
"Any",
":",
"try",
":",
"ret",
"=",
"fn",
"(",
"self",
".",
"... | r"""Map a function over the Reader.
Haskell:
fmap f m = Reader $ \r -> f (runReader m r).
fmap f g = (\x -> f (g x)) | [
"r",
"Map",
"a",
"function",
"over",
"the",
"Reader",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/reader.py#L40-L53 | train |
dbrattli/OSlash | oslash/reader.py | Reader.bind | def bind(self, fn: "Callable[[Any], Reader]") -> 'Reader':
r"""Bind a monadic function to the Reader.
Haskell:
Reader: m >>= k = Reader $ \r -> runReader (k (runReader m r)) r
Function: h >>= f = \w -> f (h w) w
"""
return Reader(lambda x: fn(self.run(x)).run(x)) | python | def bind(self, fn: "Callable[[Any], Reader]") -> 'Reader':
r"""Bind a monadic function to the Reader.
Haskell:
Reader: m >>= k = Reader $ \r -> runReader (k (runReader m r)) r
Function: h >>= f = \w -> f (h w) w
"""
return Reader(lambda x: fn(self.run(x)).run(x)) | [
"def",
"bind",
"(",
"self",
",",
"fn",
":",
"\"Callable[[Any], Reader]\"",
")",
"->",
"'Reader'",
":",
"r",
"return",
"Reader",
"(",
"lambda",
"x",
":",
"fn",
"(",
"self",
".",
"run",
"(",
"x",
")",
")",
".",
"run",
"(",
"x",
")",
")"
] | r"""Bind a monadic function to the Reader.
Haskell:
Reader: m >>= k = Reader $ \r -> runReader (k (runReader m r)) r
Function: h >>= f = \w -> f (h w) w | [
"r",
"Bind",
"a",
"monadic",
"function",
"to",
"the",
"Reader",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/reader.py#L55-L62 | train |
dbrattli/OSlash | oslash/reader.py | Reader.run | def run(self, *args, **kwargs) -> Callable:
"""Return wrapped function.
Haskell: runReader :: Reader r a -> r -> a
This is the inverse of unit and returns the wrapped function.
"""
return self.fn(*args, **kwargs) if args or kwargs else self.fn | python | def run(self, *args, **kwargs) -> Callable:
"""Return wrapped function.
Haskell: runReader :: Reader r a -> r -> a
This is the inverse of unit and returns the wrapped function.
"""
return self.fn(*args, **kwargs) if args or kwargs else self.fn | [
"def",
"run",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
"->",
"Callable",
":",
"return",
"self",
".",
"fn",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"if",
"args",
"or",
"kwargs",
"else",
"self",
".",
"fn"
] | Return wrapped function.
Haskell: runReader :: Reader r a -> r -> a
This is the inverse of unit and returns the wrapped function. | [
"Return",
"wrapped",
"function",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/reader.py#L85-L92 | train |
dbrattli/OSlash | oslash/reader.py | MonadReader.asks | def asks(cls, fn: Callable) -> Reader:
"""
Given a function it returns a Reader which evaluates that
function and returns the result.
asks :: (e -> a) -> R e a
asks f = do
e <- ask
return $ f e
asks sel = ask >>= return . sel
"""
... | python | def asks(cls, fn: Callable) -> Reader:
"""
Given a function it returns a Reader which evaluates that
function and returns the result.
asks :: (e -> a) -> R e a
asks f = do
e <- ask
return $ f e
asks sel = ask >>= return . sel
"""
... | [
"def",
"asks",
"(",
"cls",
",",
"fn",
":",
"Callable",
")",
"->",
"Reader",
":",
"return",
"cls",
".",
"ask",
"(",
")",
".",
"bind",
"(",
"Reader",
"(",
"lambda",
"x",
":",
"cls",
".",
"unit",
"(",
"fn",
"(",
"x",
")",
")",
")",
")"
] | Given a function it returns a Reader which evaluates that
function and returns the result.
asks :: (e -> a) -> R e a
asks f = do
e <- ask
return $ f e
asks sel = ask >>= return . sel | [
"Given",
"a",
"function",
"it",
"returns",
"a",
"Reader",
"which",
"evaluates",
"that",
"function",
"and",
"returns",
"the",
"result",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/reader.py#L132-L144 | train |
dbrattli/OSlash | oslash/monadic.py | compose | def compose(f: Callable[[Any], Monad], g: Callable[[Any], Monad]) -> Callable[[Any], Monad]:
r"""Monadic compose function.
Right-to-left Kleisli composition of two monadic functions.
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
f <=< g = \x -> g x >>= f
"""
return lambda x: g(x).bi... | python | def compose(f: Callable[[Any], Monad], g: Callable[[Any], Monad]) -> Callable[[Any], Monad]:
r"""Monadic compose function.
Right-to-left Kleisli composition of two monadic functions.
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
f <=< g = \x -> g x >>= f
"""
return lambda x: g(x).bi... | [
"def",
"compose",
"(",
"f",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Monad",
"]",
",",
"g",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Monad",
"]",
")",
"->",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Monad",
"]",
":",
"r",
"return",
"lam... | r"""Monadic compose function.
Right-to-left Kleisli composition of two monadic functions.
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
f <=< g = \x -> g x >>= f | [
"r",
"Monadic",
"compose",
"function",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/monadic.py#L12-L20 | train |
dbrattli/OSlash | oslash/util/fn.py | compose | def compose(*funcs: Callable) -> Callable:
"""Compose multiple functions right to left.
Composes zero or more functions into a functional composition. The
functions are composed right to left. A composition of zero
functions gives back the identity function.
compose()(x) == x
compose(f)(x) == ... | python | def compose(*funcs: Callable) -> Callable:
"""Compose multiple functions right to left.
Composes zero or more functions into a functional composition. The
functions are composed right to left. A composition of zero
functions gives back the identity function.
compose()(x) == x
compose(f)(x) == ... | [
"def",
"compose",
"(",
"*",
"funcs",
":",
"Callable",
")",
"->",
"Callable",
":",
"def",
"_compose",
"(",
"*",
"args",
",",
"**",
"kw",
")",
":",
"ret",
"=",
"reduce",
"(",
"lambda",
"acc",
",",
"x",
":",
"lambda",
"f",
":",
"f",
"(",
"acc",
"(... | Compose multiple functions right to left.
Composes zero or more functions into a functional composition. The
functions are composed right to left. A composition of zero
functions gives back the identity function.
compose()(x) == x
compose(f)(x) == f(x)
compose(g, f)(x) == g(f(x))
compose(h... | [
"Compose",
"multiple",
"functions",
"right",
"to",
"left",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/util/fn.py#L6-L27 | train |
dbrattli/OSlash | oslash/state.py | State.run | def run(self, state: Any) -> Tuple[Any, Any]:
"""Return wrapped state computation.
This is the inverse of unit and returns the wrapped function.
"""
return self._value(state) | python | def run(self, state: Any) -> Tuple[Any, Any]:
"""Return wrapped state computation.
This is the inverse of unit and returns the wrapped function.
"""
return self._value(state) | [
"def",
"run",
"(",
"self",
",",
"state",
":",
"Any",
")",
"->",
"Tuple",
"[",
"Any",
",",
"Any",
"]",
":",
"return",
"self",
".",
"_value",
"(",
"state",
")"
] | Return wrapped state computation.
This is the inverse of unit and returns the wrapped function. | [
"Return",
"wrapped",
"state",
"computation",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/state.py#L63-L68 | train |
dbrattli/OSlash | oslash/writer.py | Writer.map | def map(self, func: Callable[[Tuple[Any, Log]], Tuple[Any, Log]]) -> 'Writer':
"""Map a function func over the Writer value.
Haskell:
fmap f m = Writer $ let (a, w) = runWriter m in (f a, w)
Keyword arguments:
func -- Mapper function:
"""
a, w = self.run()
... | python | def map(self, func: Callable[[Tuple[Any, Log]], Tuple[Any, Log]]) -> 'Writer':
"""Map a function func over the Writer value.
Haskell:
fmap f m = Writer $ let (a, w) = runWriter m in (f a, w)
Keyword arguments:
func -- Mapper function:
"""
a, w = self.run()
... | [
"def",
"map",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"Tuple",
"[",
"Any",
",",
"Log",
"]",
"]",
",",
"Tuple",
"[",
"Any",
",",
"Log",
"]",
"]",
")",
"->",
"'Writer'",
":",
"a",
",",
"w",
"=",
"self",
".",
"run",
"(",
")",
"b",... | Map a function func over the Writer value.
Haskell:
fmap f m = Writer $ let (a, w) = runWriter m in (f a, w)
Keyword arguments:
func -- Mapper function: | [
"Map",
"a",
"function",
"func",
"over",
"the",
"Writer",
"value",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/writer.py#L23-L34 | train |
dbrattli/OSlash | oslash/writer.py | Writer.bind | def bind(self, func: Callable[[Any], 'Writer']) -> 'Writer':
"""Flat is better than nested.
Haskell:
(Writer (x, v)) >>= f = let
(Writer (y, v')) = f x in Writer (y, v `append` v')
"""
a, w = self.run()
b, w_ = func(a).run()
if isinstance(w_, Monoid)... | python | def bind(self, func: Callable[[Any], 'Writer']) -> 'Writer':
"""Flat is better than nested.
Haskell:
(Writer (x, v)) >>= f = let
(Writer (y, v')) = f x in Writer (y, v `append` v')
"""
a, w = self.run()
b, w_ = func(a).run()
if isinstance(w_, Monoid)... | [
"def",
"bind",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"'Writer'",
"]",
")",
"->",
"'Writer'",
":",
"a",
",",
"w",
"=",
"self",
".",
"run",
"(",
")",
"b",
",",
"w_",
"=",
"func",
"(",
"a",
")",
".",
"run",
"(",... | Flat is better than nested.
Haskell:
(Writer (x, v)) >>= f = let
(Writer (y, v')) = f x in Writer (y, v `append` v') | [
"Flat",
"is",
"better",
"than",
"nested",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/writer.py#L36-L51 | train |
dbrattli/OSlash | oslash/writer.py | Writer.apply_log | def apply_log(a: tuple, func: Callable[[Any], Tuple[Any, Log]]) -> Tuple[Any, Log]:
"""Apply a function to a value with a log.
Helper function to apply a function to a value with a log tuple.
"""
value, log = a
new, entry = func(value)
return new, log + entry | python | def apply_log(a: tuple, func: Callable[[Any], Tuple[Any, Log]]) -> Tuple[Any, Log]:
"""Apply a function to a value with a log.
Helper function to apply a function to a value with a log tuple.
"""
value, log = a
new, entry = func(value)
return new, log + entry | [
"def",
"apply_log",
"(",
"a",
":",
"tuple",
",",
"func",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Tuple",
"[",
"Any",
",",
"Log",
"]",
"]",
")",
"->",
"Tuple",
"[",
"Any",
",",
"Log",
"]",
":",
"value",
",",
"log",
"=",
"a",
"new",
",",
... | Apply a function to a value with a log.
Helper function to apply a function to a value with a log tuple. | [
"Apply",
"a",
"function",
"to",
"a",
"value",
"with",
"a",
"log",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/writer.py#L79-L86 | train |
dbrattli/OSlash | oslash/writer.py | Writer.create | def create(cls, class_name: str, monoid_type=Union[Monoid, str]):
"""Create Writer subclass using specified monoid type.
lets us create a Writer that uses a different monoid than str for
the log.
"""
def unit(cls, value):
if hasattr(monoid_type, "empty"):
... | python | def create(cls, class_name: str, monoid_type=Union[Monoid, str]):
"""Create Writer subclass using specified monoid type.
lets us create a Writer that uses a different monoid than str for
the log.
"""
def unit(cls, value):
if hasattr(monoid_type, "empty"):
... | [
"def",
"create",
"(",
"cls",
",",
"class_name",
":",
"str",
",",
"monoid_type",
"=",
"Union",
"[",
"Monoid",
",",
"str",
"]",
")",
":",
"def",
"unit",
"(",
"cls",
",",
"value",
")",
":",
"if",
"hasattr",
"(",
"monoid_type",
",",
"\"empty\"",
")",
"... | Create Writer subclass using specified monoid type.
lets us create a Writer that uses a different monoid than str for
the log. | [
"Create",
"Writer",
"subclass",
"using",
"specified",
"monoid",
"type",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/writer.py#L98-L113 | train |
dbrattli/OSlash | oslash/identity.py | Identity.map | def map(self, mapper: Callable[[Any], Any]) -> 'Identity':
"""Map a function over wrapped values."""
value = self._value
try:
result = mapper(value)
except TypeError:
result = partial(mapper, value)
return Identity(result) | python | def map(self, mapper: Callable[[Any], Any]) -> 'Identity':
"""Map a function over wrapped values."""
value = self._value
try:
result = mapper(value)
except TypeError:
result = partial(mapper, value)
return Identity(result) | [
"def",
"map",
"(",
"self",
",",
"mapper",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Any",
"]",
")",
"->",
"'Identity'",
":",
"value",
"=",
"self",
".",
"_value",
"try",
":",
"result",
"=",
"mapper",
"(",
"value",
")",
"except",
"TypeError",
":",... | Map a function over wrapped values. | [
"Map",
"a",
"function",
"over",
"wrapped",
"values",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/identity.py#L24-L32 | train |
dbrattli/OSlash | oslash/ioaction.py | Put.run | def run(self, world: int) -> IO:
"""Run IO action"""
text, action = self._value
new_world = pure_print(world, text)
return action(world=new_world) | python | def run(self, world: int) -> IO:
"""Run IO action"""
text, action = self._value
new_world = pure_print(world, text)
return action(world=new_world) | [
"def",
"run",
"(",
"self",
",",
"world",
":",
"int",
")",
"->",
"IO",
":",
"text",
",",
"action",
"=",
"self",
".",
"_value",
"new_world",
"=",
"pure_print",
"(",
"world",
",",
"text",
")",
"return",
"action",
"(",
"world",
"=",
"new_world",
")"
] | Run IO action | [
"Run",
"IO",
"action"
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/ioaction.py#L79-L84 | train |
dbrattli/OSlash | oslash/abc/monad.py | Monad.lift | def lift(self, func):
"""Map function over monadic value.
Takes a function and a monadic value and maps the function over the
monadic value
Haskell: liftM :: (Monad m) => (a -> b) -> m a -> m b
This is really the same function as Functor.fmap, but is instead
implemente... | python | def lift(self, func):
"""Map function over monadic value.
Takes a function and a monadic value and maps the function over the
monadic value
Haskell: liftM :: (Monad m) => (a -> b) -> m a -> m b
This is really the same function as Functor.fmap, but is instead
implemente... | [
"def",
"lift",
"(",
"self",
",",
"func",
")",
":",
"return",
"self",
".",
"bind",
"(",
"lambda",
"x",
":",
"self",
".",
"unit",
"(",
"func",
"(",
"x",
")",
")",
")"
] | Map function over monadic value.
Takes a function and a monadic value and maps the function over the
monadic value
Haskell: liftM :: (Monad m) => (a -> b) -> m a -> m b
This is really the same function as Functor.fmap, but is instead
implemented using bind, and does not rely o... | [
"Map",
"function",
"over",
"monadic",
"value",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/abc/monad.py#L58-L71 | train |
dbrattli/OSlash | oslash/observable.py | Observable.map | def map(self, mapper: Callable[[Any], Any]) -> 'Observable':
r"""Map a function over an observable.
Haskell: fmap f m = Cont $ \c -> runCont m (c . f)
"""
source = self
return Observable(lambda on_next: source.subscribe(compose(on_next, mapper))) | python | def map(self, mapper: Callable[[Any], Any]) -> 'Observable':
r"""Map a function over an observable.
Haskell: fmap f m = Cont $ \c -> runCont m (c . f)
"""
source = self
return Observable(lambda on_next: source.subscribe(compose(on_next, mapper))) | [
"def",
"map",
"(",
"self",
",",
"mapper",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Any",
"]",
")",
"->",
"'Observable'",
":",
"r",
"source",
"=",
"self",
"return",
"Observable",
"(",
"lambda",
"on_next",
":",
"source",
".",
"subscribe",
"(",
"com... | r"""Map a function over an observable.
Haskell: fmap f m = Cont $ \c -> runCont m (c . f) | [
"r",
"Map",
"a",
"function",
"over",
"an",
"observable",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/observable.py#L39-L45 | train |
dbrattli/OSlash | oslash/observable.py | Observable.filter | def filter(self, predicate) -> 'Observable':
"""Filter the on_next continuation functions"""
source = self
def subscribe(on_next):
def _next(x):
if predicate(x):
on_next(x)
return source.subscribe(_next)
return Observable(subs... | python | def filter(self, predicate) -> 'Observable':
"""Filter the on_next continuation functions"""
source = self
def subscribe(on_next):
def _next(x):
if predicate(x):
on_next(x)
return source.subscribe(_next)
return Observable(subs... | [
"def",
"filter",
"(",
"self",
",",
"predicate",
")",
"->",
"'Observable'",
":",
"source",
"=",
"self",
"def",
"subscribe",
"(",
"on_next",
")",
":",
"def",
"_next",
"(",
"x",
")",
":",
"if",
"predicate",
"(",
"x",
")",
":",
"on_next",
"(",
"x",
")"... | Filter the on_next continuation functions | [
"Filter",
"the",
"on_next",
"continuation",
"functions"
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/observable.py#L56-L66 | train |
dbrattli/OSlash | oslash/maybe.py | Just.bind | def bind(self, func: Callable[[Any], Maybe]) -> Maybe:
"""Just x >>= f = f x."""
value = self._value
return func(value) | python | def bind(self, func: Callable[[Any], Maybe]) -> Maybe:
"""Just x >>= f = f x."""
value = self._value
return func(value) | [
"def",
"bind",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Maybe",
"]",
")",
"->",
"Maybe",
":",
"value",
"=",
"self",
".",
"_value",
"return",
"func",
"(",
"value",
")"
] | Just x >>= f = f x. | [
"Just",
"x",
">>",
"=",
"f",
"=",
"f",
"x",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/maybe.py#L113-L117 | train |
dbrattli/OSlash | oslash/list.py | List.cons | def cons(self, element: Any) -> 'List':
"""Add element to front of List."""
tail = self._get_value()
return List(lambda sel: sel(element, tail)) | python | def cons(self, element: Any) -> 'List':
"""Add element to front of List."""
tail = self._get_value()
return List(lambda sel: sel(element, tail)) | [
"def",
"cons",
"(",
"self",
",",
"element",
":",
"Any",
")",
"->",
"'List'",
":",
"tail",
"=",
"self",
".",
"_get_value",
"(",
")",
"return",
"List",
"(",
"lambda",
"sel",
":",
"sel",
"(",
"element",
",",
"tail",
")",
")"
] | Add element to front of List. | [
"Add",
"element",
"to",
"front",
"of",
"List",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L22-L26 | train |
dbrattli/OSlash | oslash/list.py | List.head | def head(self) -> Any:
"""Retrive first element in List."""
lambda_list = self._get_value()
return lambda_list(lambda head, _: head) | python | def head(self) -> Any:
"""Retrive first element in List."""
lambda_list = self._get_value()
return lambda_list(lambda head, _: head) | [
"def",
"head",
"(",
"self",
")",
"->",
"Any",
":",
"lambda_list",
"=",
"self",
".",
"_get_value",
"(",
")",
"return",
"lambda_list",
"(",
"lambda",
"head",
",",
"_",
":",
"head",
")"
] | Retrive first element in List. | [
"Retrive",
"first",
"element",
"in",
"List",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L28-L32 | train |
dbrattli/OSlash | oslash/list.py | List.tail | def tail(self) -> 'List':
"""Return tail of List."""
lambda_list = self._get_value()
return List(lambda_list(lambda _, tail: tail)) | python | def tail(self) -> 'List':
"""Return tail of List."""
lambda_list = self._get_value()
return List(lambda_list(lambda _, tail: tail)) | [
"def",
"tail",
"(",
"self",
")",
"->",
"'List'",
":",
"lambda_list",
"=",
"self",
".",
"_get_value",
"(",
")",
"return",
"List",
"(",
"lambda_list",
"(",
"lambda",
"_",
",",
"tail",
":",
"tail",
")",
")"
] | Return tail of List. | [
"Return",
"tail",
"of",
"List",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L34-L38 | train |
dbrattli/OSlash | oslash/list.py | List.map | def map(self, mapper: Callable[[Any], Any]) -> 'List':
"""Map a function over a List."""
try:
ret = List.from_iterable([mapper(x) for x in self])
except TypeError:
ret = List.from_iterable([partial(mapper, x) for x in self])
return ret | python | def map(self, mapper: Callable[[Any], Any]) -> 'List':
"""Map a function over a List."""
try:
ret = List.from_iterable([mapper(x) for x in self])
except TypeError:
ret = List.from_iterable([partial(mapper, x) for x in self])
return ret | [
"def",
"map",
"(",
"self",
",",
"mapper",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Any",
"]",
")",
"->",
"'List'",
":",
"try",
":",
"ret",
"=",
"List",
".",
"from_iterable",
"(",
"[",
"mapper",
"(",
"x",
")",
"for",
"x",
"in",
"self",
"]",
... | Map a function over a List. | [
"Map",
"a",
"function",
"over",
"a",
"List",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L51-L57 | train |
dbrattli/OSlash | oslash/list.py | List.append | def append(self, other: 'List') -> 'List':
"""Append other list to this list."""
if self.null():
return other
return (self.tail().append(other)).cons(self.head()) | python | def append(self, other: 'List') -> 'List':
"""Append other list to this list."""
if self.null():
return other
return (self.tail().append(other)).cons(self.head()) | [
"def",
"append",
"(",
"self",
",",
"other",
":",
"'List'",
")",
"->",
"'List'",
":",
"if",
"self",
".",
"null",
"(",
")",
":",
"return",
"other",
"return",
"(",
"self",
".",
"tail",
"(",
")",
".",
"append",
"(",
"other",
")",
")",
".",
"cons",
... | Append other list to this list. | [
"Append",
"other",
"list",
"to",
"this",
"list",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L73-L78 | train |
dbrattli/OSlash | oslash/list.py | List.bind | def bind(self, fn: Callable[[Any], 'List']) -> 'List':
"""Flatten and map the List.
Haskell: xs >>= f = concat (map f xs)
"""
return List.concat(self.map(fn)) | python | def bind(self, fn: Callable[[Any], 'List']) -> 'List':
"""Flatten and map the List.
Haskell: xs >>= f = concat (map f xs)
"""
return List.concat(self.map(fn)) | [
"def",
"bind",
"(",
"self",
",",
"fn",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"'List'",
"]",
")",
"->",
"'List'",
":",
"return",
"List",
".",
"concat",
"(",
"self",
".",
"map",
"(",
"fn",
")",
")"
] | Flatten and map the List.
Haskell: xs >>= f = concat (map f xs) | [
"Flatten",
"and",
"map",
"the",
"List",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L80-L85 | train |
dbrattli/OSlash | oslash/list.py | List.from_iterable | def from_iterable(cls, iterable: Iterable) -> 'List':
"""Create list from iterable."""
iterator = iter(iterable)
def recurse() -> List:
try:
value = next(iterator)
except StopIteration:
return List.empty()
return List.unit(va... | python | def from_iterable(cls, iterable: Iterable) -> 'List':
"""Create list from iterable."""
iterator = iter(iterable)
def recurse() -> List:
try:
value = next(iterator)
except StopIteration:
return List.empty()
return List.unit(va... | [
"def",
"from_iterable",
"(",
"cls",
",",
"iterable",
":",
"Iterable",
")",
"->",
"'List'",
":",
"iterator",
"=",
"iter",
"(",
"iterable",
")",
"def",
"recurse",
"(",
")",
"->",
"List",
":",
"try",
":",
"value",
"=",
"next",
"(",
"iterator",
")",
"exc... | Create list from iterable. | [
"Create",
"list",
"from",
"iterable",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/list.py#L88-L100 | train |
dbrattli/OSlash | oslash/cont.py | Cont.map | def map(self, fn: Callable[[Any], Any]) -> 'Cont':
r"""Map a function over a continuation.
Haskell: fmap f m = Cont $ \c -> runCont m (c . f)
"""
return Cont(lambda c: self.run(compose(c, fn))) | python | def map(self, fn: Callable[[Any], Any]) -> 'Cont':
r"""Map a function over a continuation.
Haskell: fmap f m = Cont $ \c -> runCont m (c . f)
"""
return Cont(lambda c: self.run(compose(c, fn))) | [
"def",
"map",
"(",
"self",
",",
"fn",
":",
"Callable",
"[",
"[",
"Any",
"]",
",",
"Any",
"]",
")",
"->",
"'Cont'",
":",
"r",
"return",
"Cont",
"(",
"lambda",
"c",
":",
"self",
".",
"run",
"(",
"compose",
"(",
"c",
",",
"fn",
")",
")",
")"
] | r"""Map a function over a continuation.
Haskell: fmap f m = Cont $ \c -> runCont m (c . f) | [
"r",
"Map",
"a",
"function",
"over",
"a",
"continuation",
"."
] | ffdc714c5d454f7519f740254de89f70850929eb | https://github.com/dbrattli/OSlash/blob/ffdc714c5d454f7519f740254de89f70850929eb/oslash/cont.py#L38-L43 | train |
romanvm/python-web-pdb | web_pdb/wsgi_app.py | compress | def compress(func):
"""
Compress route return data with gzip compression
"""
@wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
if ('gzip' in bottle.request.headers.get('Accept-Encoding', '') and
isinstance(result, string_type) and
... | python | def compress(func):
"""
Compress route return data with gzip compression
"""
@wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
if ('gzip' in bottle.request.headers.get('Accept-Encoding', '') and
isinstance(result, string_type) and
... | [
"def",
"compress",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"result",
"=",
"func",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"if",
"(",
"'gzip'",
"in",
"bottle",
... | Compress route return data with gzip compression | [
"Compress",
"route",
"return",
"data",
"with",
"gzip",
"compression"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/wsgi_app.py#L49-L67 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | set_trace | def set_trace(host='', port=5555, patch_stdstreams=False):
"""
Start the debugger
This method suspends execution of the current script
and starts a PDB debugging session. The web-interface is opened
on the specified port (default: ``5555``).
Example::
import web_pdb;web_pdb.set_trace(... | python | def set_trace(host='', port=5555, patch_stdstreams=False):
"""
Start the debugger
This method suspends execution of the current script
and starts a PDB debugging session. The web-interface is opened
on the specified port (default: ``5555``).
Example::
import web_pdb;web_pdb.set_trace(... | [
"def",
"set_trace",
"(",
"host",
"=",
"''",
",",
"port",
"=",
"5555",
",",
"patch_stdstreams",
"=",
"False",
")",
":",
"pdb",
"=",
"WebPdb",
".",
"active_instance",
"if",
"pdb",
"is",
"None",
":",
"pdb",
"=",
"WebPdb",
"(",
"host",
",",
"port",
",",
... | Start the debugger
This method suspends execution of the current script
and starts a PDB debugging session. The web-interface is opened
on the specified port (default: ``5555``).
Example::
import web_pdb;web_pdb.set_trace()
Subsequent :func:`set_trace` calls can be used as hardcoded brea... | [
"Start",
"the",
"debugger"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L249-L278 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | post_mortem | def post_mortem(tb=None, host='', port=5555, patch_stdstreams=False):
"""
Start post-mortem debugging for the provided traceback object
If no traceback is provided the debugger tries to obtain a traceback
for the last unhandled exception.
Example::
try:
# Some error-prone code... | python | def post_mortem(tb=None, host='', port=5555, patch_stdstreams=False):
"""
Start post-mortem debugging for the provided traceback object
If no traceback is provided the debugger tries to obtain a traceback
for the last unhandled exception.
Example::
try:
# Some error-prone code... | [
"def",
"post_mortem",
"(",
"tb",
"=",
"None",
",",
"host",
"=",
"''",
",",
"port",
"=",
"5555",
",",
"patch_stdstreams",
"=",
"False",
")",
":",
"if",
"tb",
"is",
"None",
":",
"t",
",",
"v",
",",
"tb",
"=",
"sys",
".",
"exc_info",
"(",
")",
"ex... | Start post-mortem debugging for the provided traceback object
If no traceback is provided the debugger tries to obtain a traceback
for the last unhandled exception.
Example::
try:
# Some error-prone code
assert ham == spam
except:
web_pdb.post_mortem()
... | [
"Start",
"post",
"-",
"mortem",
"debugging",
"for",
"the",
"provided",
"traceback",
"object"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L281-L328 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | catch_post_mortem | def catch_post_mortem(host='', port=5555, patch_stdstreams=False):
"""
A context manager for tracking potentially error-prone code
If an unhandled exception is raised inside context manager's code block,
the post-mortem debugger is started automatically.
Example::
with web_pdb.catch_post_... | python | def catch_post_mortem(host='', port=5555, patch_stdstreams=False):
"""
A context manager for tracking potentially error-prone code
If an unhandled exception is raised inside context manager's code block,
the post-mortem debugger is started automatically.
Example::
with web_pdb.catch_post_... | [
"def",
"catch_post_mortem",
"(",
"host",
"=",
"''",
",",
"port",
"=",
"5555",
",",
"patch_stdstreams",
"=",
"False",
")",
":",
"try",
":",
"yield",
"except",
"Exception",
":",
"post_mortem",
"(",
"None",
",",
"host",
",",
"port",
",",
"patch_stdstreams",
... | A context manager for tracking potentially error-prone code
If an unhandled exception is raised inside context manager's code block,
the post-mortem debugger is started automatically.
Example::
with web_pdb.catch_post_mortem()
# Some error-prone code
assert ham == spam
... | [
"A",
"context",
"manager",
"for",
"tracking",
"potentially",
"error",
"-",
"prone",
"code"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L332-L357 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | WebPdb.do_quit | def do_quit(self, arg):
"""
quit || exit || q
Stop and quit the current debugging session
"""
for name, fh in self._backup:
setattr(sys, name, fh)
self.console.writeline('*** Aborting program ***\n')
self.console.flush()
self.console.close()
... | python | def do_quit(self, arg):
"""
quit || exit || q
Stop and quit the current debugging session
"""
for name, fh in self._backup:
setattr(sys, name, fh)
self.console.writeline('*** Aborting program ***\n')
self.console.flush()
self.console.close()
... | [
"def",
"do_quit",
"(",
"self",
",",
"arg",
")",
":",
"for",
"name",
",",
"fh",
"in",
"self",
".",
"_backup",
":",
"setattr",
"(",
"sys",
",",
"name",
",",
"fh",
")",
"self",
".",
"console",
".",
"writeline",
"(",
"'*** Aborting program ***\\n'",
")",
... | quit || exit || q
Stop and quit the current debugging session | [
"quit",
"||",
"exit",
"||",
"q",
"Stop",
"and",
"quit",
"the",
"current",
"debugging",
"session"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L88-L99 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | WebPdb._get_repr | def _get_repr(obj, pretty=False, indent=1):
"""
Get string representation of an object
:param obj: object
:type obj: object
:param pretty: use pretty formatting
:type pretty: bool
:param indent: indentation for pretty formatting
:type indent: int
... | python | def _get_repr(obj, pretty=False, indent=1):
"""
Get string representation of an object
:param obj: object
:type obj: object
:param pretty: use pretty formatting
:type pretty: bool
:param indent: indentation for pretty formatting
:type indent: int
... | [
"def",
"_get_repr",
"(",
"obj",
",",
"pretty",
"=",
"False",
",",
"indent",
"=",
"1",
")",
":",
"if",
"pretty",
":",
"repr_value",
"=",
"pformat",
"(",
"obj",
",",
"indent",
")",
"else",
":",
"repr_value",
"=",
"repr",
"(",
"obj",
")",
"if",
"sys",... | Get string representation of an object
:param obj: object
:type obj: object
:param pretty: use pretty formatting
:type pretty: bool
:param indent: indentation for pretty formatting
:type indent: int
:return: string representation
:rtype: str | [
"Get",
"string",
"representation",
"of",
"an",
"object"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L132-L155 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | WebPdb.get_current_frame_data | def get_current_frame_data(self):
"""
Get all date about the current execution frame
:return: current frame data
:rtype: dict
:raises AttributeError: if the debugger does hold any execution frame.
:raises IOError: if source code for the current execution frame is not acc... | python | def get_current_frame_data(self):
"""
Get all date about the current execution frame
:return: current frame data
:rtype: dict
:raises AttributeError: if the debugger does hold any execution frame.
:raises IOError: if source code for the current execution frame is not acc... | [
"def",
"get_current_frame_data",
"(",
"self",
")",
":",
"filename",
"=",
"self",
".",
"curframe",
".",
"f_code",
".",
"co_filename",
"lines",
",",
"start_line",
"=",
"inspect",
".",
"findsource",
"(",
"self",
".",
"curframe",
")",
"if",
"sys",
".",
"versio... | Get all date about the current execution frame
:return: current frame data
:rtype: dict
:raises AttributeError: if the debugger does hold any execution frame.
:raises IOError: if source code for the current execution frame is not accessible. | [
"Get",
"all",
"date",
"about",
"the",
"current",
"execution",
"frame"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L172-L193 | train |
romanvm/python-web-pdb | web_pdb/__init__.py | WebPdb.remove_trace | def remove_trace(self, frame=None):
"""
Detach the debugger from the execution stack
:param frame: the lowest frame to detach the debugger from.
:type frame: types.FrameType
"""
sys.settrace(None)
if frame is None:
frame = self.curframe
while ... | python | def remove_trace(self, frame=None):
"""
Detach the debugger from the execution stack
:param frame: the lowest frame to detach the debugger from.
:type frame: types.FrameType
"""
sys.settrace(None)
if frame is None:
frame = self.curframe
while ... | [
"def",
"remove_trace",
"(",
"self",
",",
"frame",
"=",
"None",
")",
":",
"sys",
".",
"settrace",
"(",
"None",
")",
"if",
"frame",
"is",
"None",
":",
"frame",
"=",
"self",
".",
"curframe",
"while",
"frame",
"and",
"frame",
"is",
"not",
"self",
".",
... | Detach the debugger from the execution stack
:param frame: the lowest frame to detach the debugger from.
:type frame: types.FrameType | [
"Detach",
"the",
"debugger",
"from",
"the",
"execution",
"stack"
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/__init__.py#L234-L246 | train |
romanvm/python-web-pdb | web_pdb/web_console.py | WebConsole.flush | def flush(self):
"""
Wait until history is read but no more than 10 cycles
in case a browser session is closed.
"""
i = 0
while self._frame_data.is_dirty and i < 10:
i += 1
time.sleep(0.1) | python | def flush(self):
"""
Wait until history is read but no more than 10 cycles
in case a browser session is closed.
"""
i = 0
while self._frame_data.is_dirty and i < 10:
i += 1
time.sleep(0.1) | [
"def",
"flush",
"(",
"self",
")",
":",
"i",
"=",
"0",
"while",
"self",
".",
"_frame_data",
".",
"is_dirty",
"and",
"i",
"<",
"10",
":",
"i",
"+=",
"1",
"time",
".",
"sleep",
"(",
"0.1",
")"
] | Wait until history is read but no more than 10 cycles
in case a browser session is closed. | [
"Wait",
"until",
"history",
"is",
"read",
"but",
"no",
"more",
"than",
"10",
"cycles",
"in",
"case",
"a",
"browser",
"session",
"is",
"closed",
"."
] | f2df2207e870dbf50a4bb30ca12a59cab39a809f | https://github.com/romanvm/python-web-pdb/blob/f2df2207e870dbf50a4bb30ca12a59cab39a809f/web_pdb/web_console.py#L176-L184 | train |
cvxgrp/qcqp | qcqp/qcqp.py | solve_spectral | def solve_spectral(prob, *args, **kwargs):
"""Solve the spectral relaxation with lambda = 1.
"""
# TODO: do this efficiently without SDP lifting
# lifted variables and semidefinite constraint
X = cvx.Semidef(prob.n + 1)
W = prob.f0.homogeneous_form()
rel_obj = cvx.Minimize(cvx.sum_entries... | python | def solve_spectral(prob, *args, **kwargs):
"""Solve the spectral relaxation with lambda = 1.
"""
# TODO: do this efficiently without SDP lifting
# lifted variables and semidefinite constraint
X = cvx.Semidef(prob.n + 1)
W = prob.f0.homogeneous_form()
rel_obj = cvx.Minimize(cvx.sum_entries... | [
"def",
"solve_spectral",
"(",
"prob",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"X",
"=",
"cvx",
".",
"Semidef",
"(",
"prob",
".",
"n",
"+",
"1",
")",
"W",
"=",
"prob",
".",
"f0",
".",
"homogeneous_form",
"(",
")",
"rel_obj",
"=",
"cvx",
... | Solve the spectral relaxation with lambda = 1. | [
"Solve",
"the",
"spectral",
"relaxation",
"with",
"lambda",
"=",
"1",
"."
] | 6b7a9804ad7429b72094c9a8da3b29d807037fe9 | https://github.com/cvxgrp/qcqp/blob/6b7a9804ad7429b72094c9a8da3b29d807037fe9/qcqp/qcqp.py#L41-L70 | train |
cvxgrp/qcqp | qcqp/qcqp.py | solve_sdr | def solve_sdr(prob, *args, **kwargs):
"""Solve the SDP relaxation.
"""
# lifted variables and semidefinite constraint
X = cvx.Semidef(prob.n + 1)
W = prob.f0.homogeneous_form()
rel_obj = cvx.Minimize(cvx.sum_entries(cvx.mul_elemwise(W, X)))
rel_constr = [X[-1, -1] == 1]
for f in prob.... | python | def solve_sdr(prob, *args, **kwargs):
"""Solve the SDP relaxation.
"""
# lifted variables and semidefinite constraint
X = cvx.Semidef(prob.n + 1)
W = prob.f0.homogeneous_form()
rel_obj = cvx.Minimize(cvx.sum_entries(cvx.mul_elemwise(W, X)))
rel_constr = [X[-1, -1] == 1]
for f in prob.... | [
"def",
"solve_sdr",
"(",
"prob",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"X",
"=",
"cvx",
".",
"Semidef",
"(",
"prob",
".",
"n",
"+",
"1",
")",
"W",
"=",
"prob",
".",
"f0",
".",
"homogeneous_form",
"(",
")",
"rel_obj",
"=",
"cvx",
".",... | Solve the SDP relaxation. | [
"Solve",
"the",
"SDP",
"relaxation",
"."
] | 6b7a9804ad7429b72094c9a8da3b29d807037fe9 | https://github.com/cvxgrp/qcqp/blob/6b7a9804ad7429b72094c9a8da3b29d807037fe9/qcqp/qcqp.py#L72-L97 | train |
cvxgrp/qcqp | qcqp/utilities.py | get_qcqp_form | def get_qcqp_form(prob):
"""Returns the problem metadata in QCQP class
"""
# Check quadraticity
if not prob.objective.args[0].is_quadratic():
raise Exception("Objective is not quadratic.")
if not all([constr._expr.is_quadratic() for constr in prob.constraints]):
raise Exception("Not ... | python | def get_qcqp_form(prob):
"""Returns the problem metadata in QCQP class
"""
# Check quadraticity
if not prob.objective.args[0].is_quadratic():
raise Exception("Objective is not quadratic.")
if not all([constr._expr.is_quadratic() for constr in prob.constraints]):
raise Exception("Not ... | [
"def",
"get_qcqp_form",
"(",
"prob",
")",
":",
"if",
"not",
"prob",
".",
"objective",
".",
"args",
"[",
"0",
"]",
".",
"is_quadratic",
"(",
")",
":",
"raise",
"Exception",
"(",
"\"Objective is not quadratic.\"",
")",
"if",
"not",
"all",
"(",
"[",
"constr... | Returns the problem metadata in QCQP class | [
"Returns",
"the",
"problem",
"metadata",
"in",
"QCQP",
"class"
] | 6b7a9804ad7429b72094c9a8da3b29d807037fe9 | https://github.com/cvxgrp/qcqp/blob/6b7a9804ad7429b72094c9a8da3b29d807037fe9/qcqp/utilities.py#L318-L347 | train |
rytilahti/python-eq3bt | eq3bt/connection.py | BTLEConnection.make_request | def make_request(self, handle, value, timeout=DEFAULT_TIMEOUT, with_response=True):
"""Write a GATT Command without callback - not utf-8."""
try:
with self:
_LOGGER.debug("Writing %s to %s with with_response=%s", codecs.encode(value, 'hex'), handle, with_response)
... | python | def make_request(self, handle, value, timeout=DEFAULT_TIMEOUT, with_response=True):
"""Write a GATT Command without callback - not utf-8."""
try:
with self:
_LOGGER.debug("Writing %s to %s with with_response=%s", codecs.encode(value, 'hex'), handle, with_response)
... | [
"def",
"make_request",
"(",
"self",
",",
"handle",
",",
"value",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
",",
"with_response",
"=",
"True",
")",
":",
"try",
":",
"with",
"self",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Writing %s to %s with with_response=%s\"",
"... | Write a GATT Command without callback - not utf-8. | [
"Write",
"a",
"GATT",
"Command",
"without",
"callback",
"-",
"not",
"utf",
"-",
"8",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/connection.py#L68-L79 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | cli | def cli(ctx, mac, debug):
""" Tool to query and modify the state of EQ3 BT smart thermostat. """
if debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
thermostat = Thermostat(mac)
thermostat.update()
ctx.obj = thermostat
if ctx.inv... | python | def cli(ctx, mac, debug):
""" Tool to query and modify the state of EQ3 BT smart thermostat. """
if debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
thermostat = Thermostat(mac)
thermostat.update()
ctx.obj = thermostat
if ctx.inv... | [
"def",
"cli",
"(",
"ctx",
",",
"mac",
",",
"debug",
")",
":",
"if",
"debug",
":",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"DEBUG",
")",
"else",
":",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"INFO",
... | Tool to query and modify the state of EQ3 BT smart thermostat. | [
"Tool",
"to",
"query",
"and",
"modify",
"the",
"state",
"of",
"EQ3",
"BT",
"smart",
"thermostat",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L26-L38 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | temp | def temp(dev, target):
""" Gets or sets the target temperature."""
click.echo("Current target temp: %s" % dev.target_temperature)
if target:
click.echo("Setting target temp: %s" % target)
dev.target_temperature = target | python | def temp(dev, target):
""" Gets or sets the target temperature."""
click.echo("Current target temp: %s" % dev.target_temperature)
if target:
click.echo("Setting target temp: %s" % target)
dev.target_temperature = target | [
"def",
"temp",
"(",
"dev",
",",
"target",
")",
":",
"click",
".",
"echo",
"(",
"\"Current target temp: %s\"",
"%",
"dev",
".",
"target_temperature",
")",
"if",
"target",
":",
"click",
".",
"echo",
"(",
"\"Setting target temp: %s\"",
"%",
"target",
")",
"dev"... | Gets or sets the target temperature. | [
"Gets",
"or",
"sets",
"the",
"target",
"temperature",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L44-L49 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | mode | def mode(dev, target):
""" Gets or sets the active mode. """
click.echo("Current mode: %s" % dev.mode_readable)
if target:
click.echo("Setting mode: %s" % target)
dev.mode = target | python | def mode(dev, target):
""" Gets or sets the active mode. """
click.echo("Current mode: %s" % dev.mode_readable)
if target:
click.echo("Setting mode: %s" % target)
dev.mode = target | [
"def",
"mode",
"(",
"dev",
",",
"target",
")",
":",
"click",
".",
"echo",
"(",
"\"Current mode: %s\"",
"%",
"dev",
".",
"mode_readable",
")",
"if",
"target",
":",
"click",
".",
"echo",
"(",
"\"Setting mode: %s\"",
"%",
"target",
")",
"dev",
".",
"mode",
... | Gets or sets the active mode. | [
"Gets",
"or",
"sets",
"the",
"active",
"mode",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L55-L60 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | boost | def boost(dev, target):
""" Gets or sets the boost mode. """
click.echo("Boost: %s" % dev.boost)
if target is not None:
click.echo("Setting boost: %s" % target)
dev.boost = target | python | def boost(dev, target):
""" Gets or sets the boost mode. """
click.echo("Boost: %s" % dev.boost)
if target is not None:
click.echo("Setting boost: %s" % target)
dev.boost = target | [
"def",
"boost",
"(",
"dev",
",",
"target",
")",
":",
"click",
".",
"echo",
"(",
"\"Boost: %s\"",
"%",
"dev",
".",
"boost",
")",
"if",
"target",
"is",
"not",
"None",
":",
"click",
".",
"echo",
"(",
"\"Setting boost: %s\"",
"%",
"target",
")",
"dev",
"... | Gets or sets the boost mode. | [
"Gets",
"or",
"sets",
"the",
"boost",
"mode",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L66-L71 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | locked | def locked(dev, target):
""" Gets or sets the lock. """
click.echo("Locked: %s" % dev.locked)
if target is not None:
click.echo("Setting lock: %s" % target)
dev.locked = target | python | def locked(dev, target):
""" Gets or sets the lock. """
click.echo("Locked: %s" % dev.locked)
if target is not None:
click.echo("Setting lock: %s" % target)
dev.locked = target | [
"def",
"locked",
"(",
"dev",
",",
"target",
")",
":",
"click",
".",
"echo",
"(",
"\"Locked: %s\"",
"%",
"dev",
".",
"locked",
")",
"if",
"target",
"is",
"not",
"None",
":",
"click",
".",
"echo",
"(",
"\"Setting lock: %s\"",
"%",
"target",
")",
"dev",
... | Gets or sets the lock. | [
"Gets",
"or",
"sets",
"the",
"lock",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L84-L89 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | window_open | def window_open(dev, temp, duration):
""" Gets and sets the window open settings. """
click.echo("Window open: %s" % dev.window_open)
if temp and duration:
click.echo("Setting window open conf, temp: %s duration: %s" % (temp, duration))
dev.window_open_config(temp, duration) | python | def window_open(dev, temp, duration):
""" Gets and sets the window open settings. """
click.echo("Window open: %s" % dev.window_open)
if temp and duration:
click.echo("Setting window open conf, temp: %s duration: %s" % (temp, duration))
dev.window_open_config(temp, duration) | [
"def",
"window_open",
"(",
"dev",
",",
"temp",
",",
"duration",
")",
":",
"click",
".",
"echo",
"(",
"\"Window open: %s\"",
"%",
"dev",
".",
"window_open",
")",
"if",
"temp",
"and",
"duration",
":",
"click",
".",
"echo",
"(",
"\"Setting window open conf, tem... | Gets and sets the window open settings. | [
"Gets",
"and",
"sets",
"the",
"window",
"open",
"settings",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L103-L108 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | presets | def presets(dev, comfort, eco):
""" Sets the preset temperatures for auto mode. """
click.echo("Setting presets: comfort %s, eco %s" % (comfort, eco))
dev.temperature_presets(comfort, eco) | python | def presets(dev, comfort, eco):
""" Sets the preset temperatures for auto mode. """
click.echo("Setting presets: comfort %s, eco %s" % (comfort, eco))
dev.temperature_presets(comfort, eco) | [
"def",
"presets",
"(",
"dev",
",",
"comfort",
",",
"eco",
")",
":",
"click",
".",
"echo",
"(",
"\"Setting presets: comfort %s, eco %s\"",
"%",
"(",
"comfort",
",",
"eco",
")",
")",
"dev",
".",
"temperature_presets",
"(",
"comfort",
",",
"eco",
")"
] | Sets the preset temperatures for auto mode. | [
"Sets",
"the",
"preset",
"temperatures",
"for",
"auto",
"mode",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L115-L118 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | schedule | def schedule(dev):
""" Gets the schedule from the thermostat. """
# TODO: expose setting the schedule somehow?
for d in range(7):
dev.query_schedule(d)
for day in dev.schedule.values():
click.echo("Day %s, base temp: %s" % (day.day, day.base_temp))
current_hour = day.next_change_... | python | def schedule(dev):
""" Gets the schedule from the thermostat. """
# TODO: expose setting the schedule somehow?
for d in range(7):
dev.query_schedule(d)
for day in dev.schedule.values():
click.echo("Day %s, base temp: %s" % (day.day, day.base_temp))
current_hour = day.next_change_... | [
"def",
"schedule",
"(",
"dev",
")",
":",
"for",
"d",
"in",
"range",
"(",
"7",
")",
":",
"dev",
".",
"query_schedule",
"(",
"d",
")",
"for",
"day",
"in",
"dev",
".",
"schedule",
".",
"values",
"(",
")",
":",
"click",
".",
"echo",
"(",
"\"Day %s, b... | Gets the schedule from the thermostat. | [
"Gets",
"the",
"schedule",
"from",
"the",
"thermostat",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L122-L133 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | away | def away(dev, away_end, temperature):
""" Enables or disables the away mode. """
if away_end:
click.echo("Setting away until %s, temperature: %s" % (away_end, temperature))
else:
click.echo("Disabling away mode")
dev.set_away(away_end, temperature) | python | def away(dev, away_end, temperature):
""" Enables or disables the away mode. """
if away_end:
click.echo("Setting away until %s, temperature: %s" % (away_end, temperature))
else:
click.echo("Disabling away mode")
dev.set_away(away_end, temperature) | [
"def",
"away",
"(",
"dev",
",",
"away_end",
",",
"temperature",
")",
":",
"if",
"away_end",
":",
"click",
".",
"echo",
"(",
"\"Setting away until %s, temperature: %s\"",
"%",
"(",
"away_end",
",",
"temperature",
")",
")",
"else",
":",
"click",
".",
"echo",
... | Enables or disables the away mode. | [
"Enables",
"or",
"disables",
"the",
"away",
"mode",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L147-L153 | train |
rytilahti/python-eq3bt | eq3bt/eq3cli.py | state | def state(ctx):
""" Prints out all available information. """
dev = ctx.obj
click.echo(dev)
ctx.forward(locked)
ctx.forward(low_battery)
ctx.forward(window_open)
ctx.forward(boost)
ctx.forward(temp)
# ctx.forward(presets)
ctx.forward(mode)
ctx.forward(valve_state) | python | def state(ctx):
""" Prints out all available information. """
dev = ctx.obj
click.echo(dev)
ctx.forward(locked)
ctx.forward(low_battery)
ctx.forward(window_open)
ctx.forward(boost)
ctx.forward(temp)
# ctx.forward(presets)
ctx.forward(mode)
ctx.forward(valve_state) | [
"def",
"state",
"(",
"ctx",
")",
":",
"dev",
"=",
"ctx",
".",
"obj",
"click",
".",
"echo",
"(",
"dev",
")",
"ctx",
".",
"forward",
"(",
"locked",
")",
"ctx",
".",
"forward",
"(",
"low_battery",
")",
"ctx",
".",
"forward",
"(",
"window_open",
")",
... | Prints out all available information. | [
"Prints",
"out",
"all",
"available",
"information",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3cli.py#L157-L168 | train |
rytilahti/python-eq3bt | eq3bt/eq3btsmart.py | Thermostat.parse_schedule | def parse_schedule(self, data):
"""Parses the device sent schedule."""
sched = Schedule.parse(data)
_LOGGER.debug("Got schedule data for day '%s'", sched.day)
return sched | python | def parse_schedule(self, data):
"""Parses the device sent schedule."""
sched = Schedule.parse(data)
_LOGGER.debug("Got schedule data for day '%s'", sched.day)
return sched | [
"def",
"parse_schedule",
"(",
"self",
",",
"data",
")",
":",
"sched",
"=",
"Schedule",
".",
"parse",
"(",
"data",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Got schedule data for day '%s'\"",
",",
"sched",
".",
"day",
")",
"return",
"sched"
] | Parses the device sent schedule. | [
"Parses",
"the",
"device",
"sent",
"schedule",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3btsmart.py#L108-L113 | train |
rytilahti/python-eq3bt | eq3bt/eq3btsmart.py | Thermostat.update | def update(self):
"""Update the data from the thermostat. Always sets the current time."""
_LOGGER.debug("Querying the device..")
time = datetime.now()
value = struct.pack('BBBBBBB', PROP_INFO_QUERY,
time.year % 100, time.month, time.day,
... | python | def update(self):
"""Update the data from the thermostat. Always sets the current time."""
_LOGGER.debug("Querying the device..")
time = datetime.now()
value = struct.pack('BBBBBBB', PROP_INFO_QUERY,
time.year % 100, time.month, time.day,
... | [
"def",
"update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Querying the device..\"",
")",
"time",
"=",
"datetime",
".",
"now",
"(",
")",
"value",
"=",
"struct",
".",
"pack",
"(",
"'BBBBBBB'",
",",
"PROP_INFO_QUERY",
",",
"time",
".",
"year"... | Update the data from the thermostat. Always sets the current time. | [
"Update",
"the",
"data",
"from",
"the",
"thermostat",
".",
"Always",
"sets",
"the",
"current",
"time",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3btsmart.py#L155-L163 | train |
rytilahti/python-eq3bt | eq3bt/eq3btsmart.py | Thermostat.set_schedule | def set_schedule(self, data):
"""Sets the schedule for the given day. """
value = Schedule.build(data)
self._conn.make_request(PROP_WRITE_HANDLE, value) | python | def set_schedule(self, data):
"""Sets the schedule for the given day. """
value = Schedule.build(data)
self._conn.make_request(PROP_WRITE_HANDLE, value) | [
"def",
"set_schedule",
"(",
"self",
",",
"data",
")",
":",
"value",
"=",
"Schedule",
".",
"build",
"(",
"data",
")",
"self",
".",
"_conn",
".",
"make_request",
"(",
"PROP_WRITE_HANDLE",
",",
"value",
")"
] | Sets the schedule for the given day. | [
"Sets",
"the",
"schedule",
"for",
"the",
"given",
"day",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3btsmart.py#L182-L185 | train |
rytilahti/python-eq3bt | eq3bt/eq3btsmart.py | Thermostat.target_temperature | def target_temperature(self, temperature):
"""Set new target temperature."""
dev_temp = int(temperature * 2)
if temperature == EQ3BT_OFF_TEMP or temperature == EQ3BT_ON_TEMP:
dev_temp |= 0x40
value = struct.pack('BB', PROP_MODE_WRITE, dev_temp)
else:
s... | python | def target_temperature(self, temperature):
"""Set new target temperature."""
dev_temp = int(temperature * 2)
if temperature == EQ3BT_OFF_TEMP or temperature == EQ3BT_ON_TEMP:
dev_temp |= 0x40
value = struct.pack('BB', PROP_MODE_WRITE, dev_temp)
else:
s... | [
"def",
"target_temperature",
"(",
"self",
",",
"temperature",
")",
":",
"dev_temp",
"=",
"int",
"(",
"temperature",
"*",
"2",
")",
"if",
"temperature",
"==",
"EQ3BT_OFF_TEMP",
"or",
"temperature",
"==",
"EQ3BT_ON_TEMP",
":",
"dev_temp",
"|=",
"0x40",
"value",
... | Set new target temperature. | [
"Set",
"new",
"target",
"temperature",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3btsmart.py#L193-L203 | train |
rytilahti/python-eq3bt | eq3bt/eq3btsmart.py | Thermostat.mode | def mode(self, mode):
"""Set the operation mode."""
_LOGGER.debug("Setting new mode: %s", mode)
if self.mode == Mode.Boost and mode != Mode.Boost:
self.boost = False
if mode == Mode.Boost:
self.boost = True
return
elif mode == Mode.Away:
... | python | def mode(self, mode):
"""Set the operation mode."""
_LOGGER.debug("Setting new mode: %s", mode)
if self.mode == Mode.Boost and mode != Mode.Boost:
self.boost = False
if mode == Mode.Boost:
self.boost = True
return
elif mode == Mode.Away:
... | [
"def",
"mode",
"(",
"self",
",",
"mode",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting new mode: %s\"",
",",
"mode",
")",
"if",
"self",
".",
"mode",
"==",
"Mode",
".",
"Boost",
"and",
"mode",
"!=",
"Mode",
".",
"Boost",
":",
"self",
".",
"boost"... | Set the operation mode. | [
"Set",
"the",
"operation",
"mode",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3btsmart.py#L211-L234 | train |
rytilahti/python-eq3bt | eq3bt/eq3btsmart.py | Thermostat.set_away | def set_away(self, away_end=None, temperature=EQ3BT_AWAY_TEMP):
""" Sets away mode with target temperature.
When called without parameters disables away mode."""
if not away_end:
_LOGGER.debug("Disabling away, going to auto mode.")
return self.set_mode(0x00)
... | python | def set_away(self, away_end=None, temperature=EQ3BT_AWAY_TEMP):
""" Sets away mode with target temperature.
When called without parameters disables away mode."""
if not away_end:
_LOGGER.debug("Disabling away, going to auto mode.")
return self.set_mode(0x00)
... | [
"def",
"set_away",
"(",
"self",
",",
"away_end",
"=",
"None",
",",
"temperature",
"=",
"EQ3BT_AWAY_TEMP",
")",
":",
"if",
"not",
"away_end",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Disabling away, going to auto mode.\"",
")",
"return",
"self",
".",
"set_mode",
"... | Sets away mode with target temperature.
When called without parameters disables away mode. | [
"Sets",
"away",
"mode",
"with",
"target",
"temperature",
".",
"When",
"called",
"without",
"parameters",
"disables",
"away",
"mode",
"."
] | 595459d9885920cf13b7059a1edd2cf38cede1f0 | https://github.com/rytilahti/python-eq3bt/blob/595459d9885920cf13b7059a1edd2cf38cede1f0/eq3bt/eq3btsmart.py#L240-L251 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.