repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
arteria/django-background-image
background_image/models.py
SingletonModel.save
def save(self, *args, **kwargs): """ Save object to the database. Removes all other entries if there are any. """ self.__class__.objects.exclude(id=self.id).delete() super(SingletonModel, self).save(*args, **kwargs)
python
def save(self, *args, **kwargs): """ Save object to the database. Removes all other entries if there are any. """ self.__class__.objects.exclude(id=self.id).delete() super(SingletonModel, self).save(*args, **kwargs)
[ "def", "save", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "__class__", ".", "objects", ".", "exclude", "(", "id", "=", "self", ".", "id", ")", ".", "delete", "(", ")", "super", "(", "SingletonModel", ",", "self...
Save object to the database. Removes all other entries if there are any.
[ "Save", "object", "to", "the", "database", ".", "Removes", "all", "other", "entries", "if", "there", "are", "any", "." ]
30d2c80512bfde0aaf927bde84a50a20e089cd9c
https://github.com/arteria/django-background-image/blob/30d2c80512bfde0aaf927bde84a50a20e089cd9c/background_image/models.py#L22-L28
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_magicc_region_to_openscm_region_mapping
def get_magicc_region_to_openscm_region_mapping(inverse=False): """Get the mappings from MAGICC to OpenSCM regions. This is not a pure inverse of the other way around. For example, we never provide "GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also have "World". Fortunat...
python
def get_magicc_region_to_openscm_region_mapping(inverse=False): """Get the mappings from MAGICC to OpenSCM regions. This is not a pure inverse of the other way around. For example, we never provide "GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also have "World". Fortunat...
[ "def", "get_magicc_region_to_openscm_region_mapping", "(", "inverse", "=", "False", ")", ":", "def", "get_openscm_replacement", "(", "in_region", ")", ":", "world", "=", "\"World\"", "if", "in_region", "in", "(", "\"WORLD\"", ",", "\"GLOBAL\"", ")", ":", "return",...
Get the mappings from MAGICC to OpenSCM regions. This is not a pure inverse of the other way around. For example, we never provide "GLOBAL" as a MAGICC return value because it's unnecesarily confusing when we also have "World". Fortunately MAGICC doesn't ever read the name "GLOBAL" so this shouldn't ma...
[ "Get", "the", "mappings", "from", "MAGICC", "to", "OpenSCM", "regions", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L80-L158
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_magicc_to_openscm_regions
def convert_magicc_to_openscm_regions(regions, inverse=False): """ Convert MAGICC regions to OpenSCM regions Parameters ---------- regions : list_like, str Regions to convert inverse : bool If True, convert the other way i.e. convert OpenSCM regions to MAGICC7 regions ...
python
def convert_magicc_to_openscm_regions(regions, inverse=False): """ Convert MAGICC regions to OpenSCM regions Parameters ---------- regions : list_like, str Regions to convert inverse : bool If True, convert the other way i.e. convert OpenSCM regions to MAGICC7 regions ...
[ "def", "convert_magicc_to_openscm_regions", "(", "regions", ",", "inverse", "=", "False", ")", ":", "if", "isinstance", "(", "regions", ",", "(", "list", ",", "pd", ".", "Index", ")", ")", ":", "return", "[", "_apply_convert_magicc_to_openscm_regions", "(", "r...
Convert MAGICC regions to OpenSCM regions Parameters ---------- regions : list_like, str Regions to convert inverse : bool If True, convert the other way i.e. convert OpenSCM regions to MAGICC7 regions Returns ------- ``type(regions)`` Set of converted regi...
[ "Convert", "MAGICC", "regions", "to", "OpenSCM", "regions" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L188-L209
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_magicc7_to_openscm_variable_mapping
def get_magicc7_to_openscm_variable_mapping(inverse=False): """Get the mappings from MAGICC7 to OpenSCM variables. Parameters ---------- inverse : bool If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings Returns ------- dict Dictionary of mappings """ ...
python
def get_magicc7_to_openscm_variable_mapping(inverse=False): """Get the mappings from MAGICC7 to OpenSCM variables. Parameters ---------- inverse : bool If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings Returns ------- dict Dictionary of mappings """ ...
[ "def", "get_magicc7_to_openscm_variable_mapping", "(", "inverse", "=", "False", ")", ":", "def", "get_openscm_replacement", "(", "in_var", ")", ":", "if", "in_var", ".", "endswith", "(", "\"_INVERSE_EMIS\"", ")", ":", "prefix", "=", "\"Inverse Emissions\"", "elif", ...
Get the mappings from MAGICC7 to OpenSCM variables. Parameters ---------- inverse : bool If True, return the inverse mappings i.e. OpenSCM to MAGICC7 mappings Returns ------- dict Dictionary of mappings
[ "Get", "the", "mappings", "from", "MAGICC7", "to", "OpenSCM", "variables", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L212-L369
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_magicc7_to_openscm_variables
def convert_magicc7_to_openscm_variables(variables, inverse=False): """ Convert MAGICC7 variables to OpenSCM variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert OpenSCM variables to MAGICC7 ...
python
def convert_magicc7_to_openscm_variables(variables, inverse=False): """ Convert MAGICC7 variables to OpenSCM variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert OpenSCM variables to MAGICC7 ...
[ "def", "convert_magicc7_to_openscm_variables", "(", "variables", ",", "inverse", "=", "False", ")", ":", "if", "isinstance", "(", "variables", ",", "(", "list", ",", "pd", ".", "Index", ")", ")", ":", "return", "[", "_apply_convert_magicc7_to_openscm_variables", ...
Convert MAGICC7 variables to OpenSCM variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert OpenSCM variables to MAGICC7 variables Returns ------- ``type(variables)`` Set of...
[ "Convert", "MAGICC7", "variables", "to", "OpenSCM", "variables" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L400-L423
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_magicc6_to_magicc7_variable_mapping
def get_magicc6_to_magicc7_variable_mapping(inverse=False): """Get the mappings from MAGICC6 to MAGICC7 variables. Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and "HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in MAGICC7 maps back to "HFC4310". ...
python
def get_magicc6_to_magicc7_variable_mapping(inverse=False): """Get the mappings from MAGICC6 to MAGICC7 variables. Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and "HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in MAGICC7 maps back to "HFC4310". ...
[ "def", "get_magicc6_to_magicc7_variable_mapping", "(", "inverse", "=", "False", ")", ":", "# we generate the mapping dynamically, the first name in the list", "# is the one which will be used for inverse mappings", "magicc6_simple_mapping_vars", "=", "[", "\"KYOTO-CO2EQ\"", ",", "\"CO2...
Get the mappings from MAGICC6 to MAGICC7 variables. Note that this mapping is not one to one. For example, "HFC4310", "HFC43-10" and "HFC-43-10" in MAGICC6 both map to "HFC4310" in MAGICC7 but "HFC4310" in MAGICC7 maps back to "HFC4310". Note that HFC-245fa was mistakenly labelled as HFC-245ca in MAGI...
[ "Get", "the", "mappings", "from", "MAGICC6", "to", "MAGICC7", "variables", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L426-L562
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_magicc6_to_magicc7_variables
def convert_magicc6_to_magicc7_variables(variables, inverse=False): """ Convert MAGICC6 variables to MAGICC7 variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6 ...
python
def convert_magicc6_to_magicc7_variables(variables, inverse=False): """ Convert MAGICC6 variables to MAGICC7 variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6 ...
[ "def", "convert_magicc6_to_magicc7_variables", "(", "variables", ",", "inverse", "=", "False", ")", ":", "if", "isinstance", "(", "variables", ",", "(", "list", ",", "pd", ".", "Index", ")", ")", ":", "return", "[", "_apply_convert_magicc6_to_magicc7_variables", ...
Convert MAGICC6 variables to MAGICC7 variables Parameters ---------- variables : list_like, str Variables to convert inverse : bool If True, convert the other way i.e. convert MAGICC7 variables to MAGICC6 variables Raises ------ ValueError If you try to con...
[ "Convert", "MAGICC6", "variables", "to", "MAGICC7", "variables" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L604-L636
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
get_pint_to_fortran_safe_units_mapping
def get_pint_to_fortran_safe_units_mapping(inverse=False): """Get the mappings from Pint to Fortran safe units. Fortran can't handle special characters like "^" or "/" in names, but we need these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt CO2 / yr" but we don't want thes...
python
def get_pint_to_fortran_safe_units_mapping(inverse=False): """Get the mappings from Pint to Fortran safe units. Fortran can't handle special characters like "^" or "/" in names, but we need these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt CO2 / yr" but we don't want thes...
[ "def", "get_pint_to_fortran_safe_units_mapping", "(", "inverse", "=", "False", ")", ":", "replacements", "=", "{", "\"^\"", ":", "\"super\"", ",", "\"/\"", ":", "\"per\"", ",", "\" \"", ":", "\"\"", "}", "if", "inverse", ":", "replacements", "=", "{", "v", ...
Get the mappings from Pint to Fortran safe units. Fortran can't handle special characters like "^" or "/" in names, but we need these in Pint. Conversely, Pint stores variables with spaces by default e.g. "Mt CO2 / yr" but we don't want these in the input files as Fortran is likely to think the whitesp...
[ "Get", "the", "mappings", "from", "Pint", "to", "Fortran", "safe", "units", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L639-L664
train
openclimatedata/pymagicc
pymagicc/definitions/__init__.py
convert_pint_to_fortran_safe_units
def convert_pint_to_fortran_safe_units(units, inverse=False): """ Convert Pint units to Fortran safe units Parameters ---------- units : list_like, str Units to convert inverse : bool If True, convert the other way i.e. convert Fortran safe units to Pint units Returns ...
python
def convert_pint_to_fortran_safe_units(units, inverse=False): """ Convert Pint units to Fortran safe units Parameters ---------- units : list_like, str Units to convert inverse : bool If True, convert the other way i.e. convert Fortran safe units to Pint units Returns ...
[ "def", "convert_pint_to_fortran_safe_units", "(", "units", ",", "inverse", "=", "False", ")", ":", "if", "inverse", ":", "return", "apply_string_substitutions", "(", "units", ",", "FORTRAN_SAFE_TO_PINT_UNITS_MAPPING", ")", "else", ":", "return", "apply_string_substituti...
Convert Pint units to Fortran safe units Parameters ---------- units : list_like, str Units to convert inverse : bool If True, convert the other way i.e. convert Fortran safe units to Pint units Returns ------- ``type(units)`` Set of converted units
[ "Convert", "Pint", "units", "to", "Fortran", "safe", "units" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/definitions/__init__.py#L678-L698
train
productml/blurr
blurr/core/field.py
Field.run_evaluate
def run_evaluate(self) -> None: """ Overrides the base evaluation to set the value to the evaluation result of the value expression in the schema """ result = None self.eval_error = False if self._needs_evaluation: result = self._schema.value.evaluate(...
python
def run_evaluate(self) -> None: """ Overrides the base evaluation to set the value to the evaluation result of the value expression in the schema """ result = None self.eval_error = False if self._needs_evaluation: result = self._schema.value.evaluate(...
[ "def", "run_evaluate", "(", "self", ")", "->", "None", ":", "result", "=", "None", "self", ".", "eval_error", "=", "False", "if", "self", ".", "_needs_evaluation", ":", "result", "=", "self", ".", "_schema", ".", "value", ".", "evaluate", "(", "self", ...
Overrides the base evaluation to set the value to the evaluation result of the value expression in the schema
[ "Overrides", "the", "base", "evaluation", "to", "set", "the", "value", "to", "the", "evaluation", "result", "of", "the", "value", "expression", "in", "the", "schema" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field.py#L90-L124
train
productml/blurr
blurr/core/field_complex.py
Map.set
def set(self, key: Any, value: Any) -> None: """ Sets the value of a key to a supplied value """ if key is not None: self[key] = value
python
def set(self, key: Any, value: Any) -> None: """ Sets the value of a key to a supplied value """ if key is not None: self[key] = value
[ "def", "set", "(", "self", ",", "key", ":", "Any", ",", "value", ":", "Any", ")", "->", "None", ":", "if", "key", "is", "not", "None", ":", "self", "[", "key", "]", "=", "value" ]
Sets the value of a key to a supplied value
[ "Sets", "the", "value", "of", "a", "key", "to", "a", "supplied", "value" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L11-L14
train
productml/blurr
blurr/core/field_complex.py
Map.increment
def increment(self, key: Any, by: int = 1) -> None: """ Increments the value set against a key. If the key is not present, 0 is assumed as the initial state """ if key is not None: self[key] = self.get(key, 0) + by
python
def increment(self, key: Any, by: int = 1) -> None: """ Increments the value set against a key. If the key is not present, 0 is assumed as the initial state """ if key is not None: self[key] = self.get(key, 0) + by
[ "def", "increment", "(", "self", ",", "key", ":", "Any", ",", "by", ":", "int", "=", "1", ")", "->", "None", ":", "if", "key", "is", "not", "None", ":", "self", "[", "key", "]", "=", "self", ".", "get", "(", "key", ",", "0", ")", "+", "by" ...
Increments the value set against a key. If the key is not present, 0 is assumed as the initial state
[ "Increments", "the", "value", "set", "against", "a", "key", ".", "If", "the", "key", "is", "not", "present", "0", "is", "assumed", "as", "the", "initial", "state" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L16-L19
train
productml/blurr
blurr/core/field_complex.py
List.insert
def insert(self, index: int, obj: Any) -> None: """ Inserts an item to the list as long as it is not None """ if obj is not None: super().insert(index, obj)
python
def insert(self, index: int, obj: Any) -> None: """ Inserts an item to the list as long as it is not None """ if obj is not None: super().insert(index, obj)
[ "def", "insert", "(", "self", ",", "index", ":", "int", ",", "obj", ":", "Any", ")", "->", "None", ":", "if", "obj", "is", "not", "None", ":", "super", "(", ")", ".", "insert", "(", "index", ",", "obj", ")" ]
Inserts an item to the list as long as it is not None
[ "Inserts", "an", "item", "to", "the", "list", "as", "long", "as", "it", "is", "not", "None" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/field_complex.py#L42-L45
train
openclimatedata/pymagicc
pymagicc/io.py
get_dattype_regionmode
def get_dattype_regionmode(regions, scen7=False): """ Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set. In all MAGICC input files, there are two flags: THISFILE_DATTYPE and THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This function maps the ...
python
def get_dattype_regionmode(regions, scen7=False): """ Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set. In all MAGICC input files, there are two flags: THISFILE_DATTYPE and THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This function maps the ...
[ "def", "get_dattype_regionmode", "(", "regions", ",", "scen7", "=", "False", ")", ":", "dattype_flag", "=", "\"THISFILE_DATTYPE\"", "regionmode_flag", "=", "\"THISFILE_REGIONMODE\"", "region_dattype_row", "=", "_get_dattype_regionmode_regions_row", "(", "regions", ",", "s...
Get the THISFILE_DATTYPE and THISFILE_REGIONMODE flags for a given region set. In all MAGICC input files, there are two flags: THISFILE_DATTYPE and THISFILE_REGIONMODE. These tell MAGICC how to read in a given input file. This function maps the regions which are in a given file to the value of these flags ...
[ "Get", "the", "THISFILE_DATTYPE", "and", "THISFILE_REGIONMODE", "flags", "for", "a", "given", "region", "set", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1131-L1165
train
openclimatedata/pymagicc
pymagicc/io.py
get_region_order
def get_region_order(regions, scen7=False): """ Get the region order expected by MAGICC. Parameters ---------- regions : list_like The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for. scen7 : bool, optional Whether the file we are getting the flags for is a SC...
python
def get_region_order(regions, scen7=False): """ Get the region order expected by MAGICC. Parameters ---------- regions : list_like The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for. scen7 : bool, optional Whether the file we are getting the flags for is a SC...
[ "def", "get_region_order", "(", "regions", ",", "scen7", "=", "False", ")", ":", "region_dattype_row", "=", "_get_dattype_regionmode_regions_row", "(", "regions", ",", "scen7", "=", "scen7", ")", "region_order", "=", "DATTYPE_REGIONMODE_REGIONS", "[", "\"regions\"", ...
Get the region order expected by MAGICC. Parameters ---------- regions : list_like The regions to get THISFILE_DATTYPE and THISFILE_REGIONMODE flags for. scen7 : bool, optional Whether the file we are getting the flags for is a SCEN7 file or not. Returns ------- list ...
[ "Get", "the", "region", "order", "expected", "by", "MAGICC", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1168-L1188
train
openclimatedata/pymagicc
pymagicc/io.py
get_special_scen_code
def get_special_scen_code(regions, emissions): """ Get special code for MAGICC6 SCEN files. At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions data is being provided for. The second digit, the 'sce...
python
def get_special_scen_code(regions, emissions): """ Get special code for MAGICC6 SCEN files. At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions data is being provided for. The second digit, the 'sce...
[ "def", "get_special_scen_code", "(", "regions", ",", "emissions", ")", ":", "if", "sorted", "(", "set", "(", "PART_OF_SCENFILE_WITH_EMISSIONS_CODE_0", ")", ")", "==", "sorted", "(", "set", "(", "emissions", ")", ")", ":", "scenfile_emissions_code", "=", "0", "...
Get special code for MAGICC6 SCEN files. At the top of every MAGICC6 and MAGICC5 SCEN file there is a two digit number. The first digit, the 'scenfile_region_code' tells MAGICC how many regions data is being provided for. The second digit, the 'scenfile_emissions_code', tells MAGICC which gases are in ...
[ "Get", "special", "code", "for", "MAGICC6", "SCEN", "files", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1796-L1852
train
openclimatedata/pymagicc
pymagicc/io.py
determine_tool
def determine_tool(filepath, tool_to_get): """ Determine the tool to use for reading/writing. The function uses an internally defined set of mappings between filepaths, regular expresions and readers/writers to work out which tool to use for a given task, given the filepath. It is intended for...
python
def determine_tool(filepath, tool_to_get): """ Determine the tool to use for reading/writing. The function uses an internally defined set of mappings between filepaths, regular expresions and readers/writers to work out which tool to use for a given task, given the filepath. It is intended for...
[ "def", "determine_tool", "(", "filepath", ",", "tool_to_get", ")", ":", "file_regexp_reader_writer", "=", "{", "\"SCEN\"", ":", "{", "\"regexp\"", ":", "r\"^.*\\.SCEN$\"", ",", "\"reader\"", ":", "_ScenReader", ",", "\"writer\"", ":", "_ScenWriter", "}", ",", "\...
Determine the tool to use for reading/writing. The function uses an internally defined set of mappings between filepaths, regular expresions and readers/writers to work out which tool to use for a given task, given the filepath. It is intended for internal use only, but is public because of its im...
[ "Determine", "the", "tool", "to", "use", "for", "reading", "/", "writing", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2021-L2163
train
openclimatedata/pymagicc
pymagicc/io.py
pull_cfg_from_parameters_out
def pull_cfg_from_parameters_out(parameters_out, namelist_to_read="nml_allcfgs"): """Pull out a single config set from a parameters_out namelist. This function returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``parame...
python
def pull_cfg_from_parameters_out(parameters_out, namelist_to_read="nml_allcfgs"): """Pull out a single config set from a parameters_out namelist. This function returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``parame...
[ "def", "pull_cfg_from_parameters_out", "(", "parameters_out", ",", "namelist_to_read", "=", "\"nml_allcfgs\"", ")", ":", "single_cfg", "=", "Namelist", "(", "{", "namelist_to_read", ":", "{", "}", "}", ")", "for", "key", ",", "value", "in", "parameters_out", "["...
Pull out a single config set from a parameters_out namelist. This function returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``parameters_out``. Parameters ---------- parameters_out : dict, f90nml.Namelist ...
[ "Pull", "out", "a", "single", "config", "set", "from", "a", "parameters_out", "namelist", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2196-L2246
train
openclimatedata/pymagicc
pymagicc/io.py
pull_cfg_from_parameters_out_file
def pull_cfg_from_parameters_out_file( parameters_out_file, namelist_to_read="nml_allcfgs" ): """Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file. This function reads in the ``PARAMETERS.OUT`` file and returns a single file with the config that needs to be passed to MAGICC in order to...
python
def pull_cfg_from_parameters_out_file( parameters_out_file, namelist_to_read="nml_allcfgs" ): """Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file. This function reads in the ``PARAMETERS.OUT`` file and returns a single file with the config that needs to be passed to MAGICC in order to...
[ "def", "pull_cfg_from_parameters_out_file", "(", "parameters_out_file", ",", "namelist_to_read", "=", "\"nml_allcfgs\"", ")", ":", "parameters_out", "=", "read_cfg_file", "(", "parameters_out_file", ")", "return", "pull_cfg_from_parameters_out", "(", "parameters_out", ",", ...
Pull out a single config set from a MAGICC ``PARAMETERS.OUT`` file. This function reads in the ``PARAMETERS.OUT`` file and returns a single file with the config that needs to be passed to MAGICC in order to do the same run as is represented by the values in ``PARAMETERS.OUT``. Parameters ---------...
[ "Pull", "out", "a", "single", "config", "set", "from", "a", "MAGICC", "PARAMETERS", ".", "OUT", "file", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2249-L2279
train
openclimatedata/pymagicc
pymagicc/io.py
get_generic_rcp_name
def get_generic_rcp_name(inname): """Convert an RCP name into the generic Pymagicc RCP name The conversion is case insensitive. Parameters ---------- inname : str The name for which to get the generic Pymagicc RCP name Returns ------- str The generic Pymagicc RCP name ...
python
def get_generic_rcp_name(inname): """Convert an RCP name into the generic Pymagicc RCP name The conversion is case insensitive. Parameters ---------- inname : str The name for which to get the generic Pymagicc RCP name Returns ------- str The generic Pymagicc RCP name ...
[ "def", "get_generic_rcp_name", "(", "inname", ")", ":", "# TODO: move into OpenSCM", "mapping", "=", "{", "\"rcp26\"", ":", "\"rcp26\"", ",", "\"rcp3pd\"", ":", "\"rcp26\"", ",", "\"rcp45\"", ":", "\"rcp45\"", ",", "\"rcp6\"", ":", "\"rcp60\"", ",", "\"rcp60\"", ...
Convert an RCP name into the generic Pymagicc RCP name The conversion is case insensitive. Parameters ---------- inname : str The name for which to get the generic Pymagicc RCP name Returns ------- str The generic Pymagicc RCP name Examples -------- >>> get_ge...
[ "Convert", "an", "RCP", "name", "into", "the", "generic", "Pymagicc", "RCP", "name" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2282-L2315
train
openclimatedata/pymagicc
pymagicc/io.py
join_timeseries
def join_timeseries(base, overwrite, join_linear=None): """Join two sets of timeseries Parameters ---------- base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Base timeseries to use. If a filepath, the data will first be loaded from disk. overwrite : :obj:`MAGICCData`, :obj:`pd.DataF...
python
def join_timeseries(base, overwrite, join_linear=None): """Join two sets of timeseries Parameters ---------- base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Base timeseries to use. If a filepath, the data will first be loaded from disk. overwrite : :obj:`MAGICCData`, :obj:`pd.DataF...
[ "def", "join_timeseries", "(", "base", ",", "overwrite", ",", "join_linear", "=", "None", ")", ":", "if", "join_linear", "is", "not", "None", ":", "if", "len", "(", "join_linear", ")", "!=", "2", ":", "raise", "ValueError", "(", "\"join_linear must have a le...
Join two sets of timeseries Parameters ---------- base : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Base timeseries to use. If a filepath, the data will first be loaded from disk. overwrite : :obj:`MAGICCData`, :obj:`pd.DataFrame`, filepath Timeseries to join onto base. Any point...
[ "Join", "two", "sets", "of", "timeseries" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2320-L2363
train
openclimatedata/pymagicc
pymagicc/io.py
read_scen_file
def read_scen_file( filepath, columns={ "model": ["unspecified"], "scenario": ["unspecified"], "climate_model": ["unspecified"], }, **kwargs ): """ Read a MAGICC .SCEN file. Parameters ---------- filepath : str Filepath of the .SCEN file to read ...
python
def read_scen_file( filepath, columns={ "model": ["unspecified"], "scenario": ["unspecified"], "climate_model": ["unspecified"], }, **kwargs ): """ Read a MAGICC .SCEN file. Parameters ---------- filepath : str Filepath of the .SCEN file to read ...
[ "def", "read_scen_file", "(", "filepath", ",", "columns", "=", "{", "\"model\"", ":", "[", "\"unspecified\"", "]", ",", "\"scenario\"", ":", "[", "\"unspecified\"", "]", ",", "\"climate_model\"", ":", "[", "\"unspecified\"", "]", ",", "}", ",", "*", "*", "...
Read a MAGICC .SCEN file. Parameters ---------- filepath : str Filepath of the .SCEN file to read columns : dict Passed to ``__init__`` method of MAGICCData. See ``MAGICCData.__init__`` for details. kwargs Passed to ``__init__`` method of MAGICCData. See ``...
[ "Read", "a", "MAGICC", ".", "SCEN", "file", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2431-L2463
train
openclimatedata/pymagicc
pymagicc/io.py
_get_openscm_var_from_filepath
def _get_openscm_var_from_filepath(filepath): """ Determine the OpenSCM variable from a filepath. Uses MAGICC's internal, implicit, filenaming conventions. Parameters ---------- filepath : str Filepath from which to determine the OpenSCM variable. Returns ------- str ...
python
def _get_openscm_var_from_filepath(filepath): """ Determine the OpenSCM variable from a filepath. Uses MAGICC's internal, implicit, filenaming conventions. Parameters ---------- filepath : str Filepath from which to determine the OpenSCM variable. Returns ------- str ...
[ "def", "_get_openscm_var_from_filepath", "(", "filepath", ")", ":", "reader", "=", "determine_tool", "(", "filepath", ",", "\"reader\"", ")", "(", "filepath", ")", "openscm_var", "=", "convert_magicc7_to_openscm_variables", "(", "convert_magicc6_to_magicc7_variables", "("...
Determine the OpenSCM variable from a filepath. Uses MAGICC's internal, implicit, filenaming conventions. Parameters ---------- filepath : str Filepath from which to determine the OpenSCM variable. Returns ------- str The OpenSCM variable implied by the filepath.
[ "Determine", "the", "OpenSCM", "variable", "from", "a", "filepath", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2466-L2487
train
openclimatedata/pymagicc
pymagicc/io.py
_Reader._find_nml
def _find_nml(self): """ Find the start and end of the embedded namelist. Returns ------- (int, int) start and end index for the namelist """ nml_start = None nml_end = None for i in range(len(self.lines)): if self.lines[i]...
python
def _find_nml(self): """ Find the start and end of the embedded namelist. Returns ------- (int, int) start and end index for the namelist """ nml_start = None nml_end = None for i in range(len(self.lines)): if self.lines[i]...
[ "def", "_find_nml", "(", "self", ")", ":", "nml_start", "=", "None", "nml_end", "=", "None", "for", "i", "in", "range", "(", "len", "(", "self", ".", "lines", ")", ")", ":", "if", "self", ".", "lines", "[", "i", "]", ".", "strip", "(", ")", "."...
Find the start and end of the embedded namelist. Returns ------- (int, int) start and end index for the namelist
[ "Find", "the", "start", "and", "end", "of", "the", "embedded", "namelist", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L143-L163
train
openclimatedata/pymagicc
pymagicc/io.py
_Reader.process_data
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file. Parameters ---------- stream : Streamlike object A Streamlike object (nominally StringIO) containing the table to be extracted metadata : dict ...
python
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file. Parameters ---------- stream : Streamlike object A Streamlike object (nominally StringIO) containing the table to be extracted metadata : dict ...
[ "def", "process_data", "(", "self", ",", "stream", ",", "metadata", ")", ":", "ch", ",", "metadata", "=", "self", ".", "_get_column_headers_and_update_metadata", "(", "stream", ",", "metadata", ")", "df", "=", "self", ".", "_convert_data_block_and_headers_to_df", ...
Extract the tabulated data from the input file. Parameters ---------- stream : Streamlike object A Streamlike object (nominally StringIO) containing the table to be extracted metadata : dict Metadata read in from the header and the namelist R...
[ "Extract", "the", "tabulated", "data", "from", "the", "input", "file", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L200-L222
train
openclimatedata/pymagicc
pymagicc/io.py
_Reader._convert_data_block_and_headers_to_df
def _convert_data_block_and_headers_to_df(self, stream): """ stream : Streamlike object A Streamlike object (nominally StringIO) containing the data to be extracted ch : dict Column headers to use for the output pd.DataFrame Returns ------- ...
python
def _convert_data_block_and_headers_to_df(self, stream): """ stream : Streamlike object A Streamlike object (nominally StringIO) containing the data to be extracted ch : dict Column headers to use for the output pd.DataFrame Returns ------- ...
[ "def", "_convert_data_block_and_headers_to_df", "(", "self", ",", "stream", ")", ":", "df", "=", "pd", ".", "read_csv", "(", "stream", ",", "skip_blank_lines", "=", "True", ",", "delim_whitespace", "=", "True", ",", "header", "=", "None", ",", "index_col", "...
stream : Streamlike object A Streamlike object (nominally StringIO) containing the data to be extracted ch : dict Column headers to use for the output pd.DataFrame Returns ------- :obj:`pd.DataFrame` Dataframe with processed datablock
[ "stream", ":", "Streamlike", "object", "A", "Streamlike", "object", "(", "nominally", "StringIO", ")", "containing", "the", "data", "to", "be", "extracted" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L224-L252
train
openclimatedata/pymagicc
pymagicc/io.py
_Reader._get_variable_from_filepath
def _get_variable_from_filepath(self): """ Determine the file variable from the filepath. Returns ------- str Best guess of variable name from the filepath """ try: return self.regexp_capture_variable.search(self.filepath).group(1) ...
python
def _get_variable_from_filepath(self): """ Determine the file variable from the filepath. Returns ------- str Best guess of variable name from the filepath """ try: return self.regexp_capture_variable.search(self.filepath).group(1) ...
[ "def", "_get_variable_from_filepath", "(", "self", ")", ":", "try", ":", "return", "self", ".", "regexp_capture_variable", ".", "search", "(", "self", ".", "filepath", ")", ".", "group", "(", "1", ")", "except", "AttributeError", ":", "self", ".", "_raise_ca...
Determine the file variable from the filepath. Returns ------- str Best guess of variable name from the filepath
[ "Determine", "the", "file", "variable", "from", "the", "filepath", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L359-L371
train
openclimatedata/pymagicc
pymagicc/io.py
_Reader.process_header
def process_header(self, header): """ Parse the header for additional metadata. Parameters ---------- header : str All the lines in the header. Returns ------- dict The metadata in the header. """ metadata = {} ...
python
def process_header(self, header): """ Parse the header for additional metadata. Parameters ---------- header : str All the lines in the header. Returns ------- dict The metadata in the header. """ metadata = {} ...
[ "def", "process_header", "(", "self", ",", "header", ")", ":", "metadata", "=", "{", "}", "for", "line", "in", "header", ".", "split", "(", "\"\\n\"", ")", ":", "line", "=", "line", ".", "strip", "(", ")", "for", "tag", "in", "self", ".", "header_t...
Parse the header for additional metadata. Parameters ---------- header : str All the lines in the header. Returns ------- dict The metadata in the header.
[ "Parse", "the", "header", "for", "additional", "metadata", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L383-L405
train
openclimatedata/pymagicc
pymagicc/io.py
_Reader._read_data_header_line
def _read_data_header_line(self, stream, expected_header): """Read a data header line, ensuring that it starts with the expected header Parameters ---------- stream : :obj:`StreamIO` Stream object containing the text to read expected_header : str, list of strs ...
python
def _read_data_header_line(self, stream, expected_header): """Read a data header line, ensuring that it starts with the expected header Parameters ---------- stream : :obj:`StreamIO` Stream object containing the text to read expected_header : str, list of strs ...
[ "def", "_read_data_header_line", "(", "self", ",", "stream", ",", "expected_header", ")", ":", "pos", "=", "stream", ".", "tell", "(", ")", "expected_header", "=", "(", "[", "expected_header", "]", "if", "isinstance", "(", "expected_header", ",", "str", ")",...
Read a data header line, ensuring that it starts with the expected header Parameters ---------- stream : :obj:`StreamIO` Stream object containing the text to read expected_header : str, list of strs Expected header of the data header line
[ "Read", "a", "data", "header", "line", "ensuring", "that", "it", "starts", "with", "the", "expected", "header" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L407-L434
train
openclimatedata/pymagicc
pymagicc/io.py
_BinData.read_chunk
def read_chunk(self, t): """ Read out the next chunk of memory Values in fortran binary streams begin and end with the number of bytes :param t: Data type (same format as used by struct). :return: Numpy array if the variable is an array, otherwise a scalar. """ s...
python
def read_chunk(self, t): """ Read out the next chunk of memory Values in fortran binary streams begin and end with the number of bytes :param t: Data type (same format as used by struct). :return: Numpy array if the variable is an array, otherwise a scalar. """ s...
[ "def", "read_chunk", "(", "self", ",", "t", ")", ":", "size", "=", "self", ".", "data", "[", "self", ".", "pos", ":", "self", ".", "pos", "+", "4", "]", ".", "cast", "(", "\"i\"", ")", "[", "0", "]", "d", "=", "self", ".", "data", "[", "sel...
Read out the next chunk of memory Values in fortran binary streams begin and end with the number of bytes :param t: Data type (same format as used by struct). :return: Numpy array if the variable is an array, otherwise a scalar.
[ "Read", "out", "the", "next", "chunk", "of", "memory" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1017-L1039
train
openclimatedata/pymagicc
pymagicc/io.py
_BinaryOutReader.process_data
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file # Arguments stream (Streamlike object): A Streamlike object (nominally StringIO) containing the table to be extracted metadata (dict): metadata read in from the header and th...
python
def process_data(self, stream, metadata): """ Extract the tabulated data from the input file # Arguments stream (Streamlike object): A Streamlike object (nominally StringIO) containing the table to be extracted metadata (dict): metadata read in from the header and th...
[ "def", "process_data", "(", "self", ",", "stream", ",", "metadata", ")", ":", "index", "=", "np", ".", "arange", "(", "metadata", "[", "\"firstyear\"", "]", ",", "metadata", "[", "\"lastyear\"", "]", "+", "1", ")", "# The first variable is the global values", ...
Extract the tabulated data from the input file # Arguments stream (Streamlike object): A Streamlike object (nominally StringIO) containing the table to be extracted metadata (dict): metadata read in from the header and the namelist # Returns df (pandas.DataFrame): c...
[ "Extract", "the", "tabulated", "data", "from", "the", "input", "file" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1055-L1108
train
openclimatedata/pymagicc
pymagicc/io.py
_BinaryOutReader.process_header
def process_header(self, data): """ Reads the first part of the file to get some essential metadata # Returns return (dict): the metadata in the header """ metadata = { "datacolumns": data.read_chunk("I"), "firstyear": data.read_chunk("I"), ...
python
def process_header(self, data): """ Reads the first part of the file to get some essential metadata # Returns return (dict): the metadata in the header """ metadata = { "datacolumns": data.read_chunk("I"), "firstyear": data.read_chunk("I"), ...
[ "def", "process_header", "(", "self", ",", "data", ")", ":", "metadata", "=", "{", "\"datacolumns\"", ":", "data", ".", "read_chunk", "(", "\"I\"", ")", ",", "\"firstyear\"", ":", "data", ".", "read_chunk", "(", "\"I\"", ")", ",", "\"lastyear\"", ":", "d...
Reads the first part of the file to get some essential metadata # Returns return (dict): the metadata in the header
[ "Reads", "the", "first", "part", "of", "the", "file", "to", "get", "some", "essential", "metadata" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1110-L1128
train
openclimatedata/pymagicc
pymagicc/io.py
_Writer.write
def write(self, magicc_input, filepath): """ Write a MAGICC input file from df and metadata Parameters ---------- magicc_input : :obj:`pymagicc.io.MAGICCData` MAGICCData object which holds the data to write filepath : str Filepath of the file to ...
python
def write(self, magicc_input, filepath): """ Write a MAGICC input file from df and metadata Parameters ---------- magicc_input : :obj:`pymagicc.io.MAGICCData` MAGICCData object which holds the data to write filepath : str Filepath of the file to ...
[ "def", "write", "(", "self", ",", "magicc_input", ",", "filepath", ")", ":", "self", ".", "_filepath", "=", "filepath", "# TODO: make copy attribute for MAGICCData", "self", ".", "minput", "=", "deepcopy", "(", "magicc_input", ")", "self", ".", "data_block", "="...
Write a MAGICC input file from df and metadata Parameters ---------- magicc_input : :obj:`pymagicc.io.MAGICCData` MAGICCData object which holds the data to write filepath : str Filepath of the file to write to.
[ "Write", "a", "MAGICC", "input", "file", "from", "df", "and", "metadata" ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1240-L1267
train
openclimatedata/pymagicc
pymagicc/io.py
MAGICCData.append
def append(self, other, inplace=False, **kwargs): """ Append any input which can be converted to MAGICCData to self. Parameters ---------- other : MAGICCData, pd.DataFrame, pd.Series, str Source of data to append. inplace : bool If True, append `...
python
def append(self, other, inplace=False, **kwargs): """ Append any input which can be converted to MAGICCData to self. Parameters ---------- other : MAGICCData, pd.DataFrame, pd.Series, str Source of data to append. inplace : bool If True, append `...
[ "def", "append", "(", "self", ",", "other", ",", "inplace", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "other", ",", "MAGICCData", ")", ":", "other", "=", "MAGICCData", "(", "other", ",", "*", "*", "kwargs", ")...
Append any input which can be converted to MAGICCData to self. Parameters ---------- other : MAGICCData, pd.DataFrame, pd.Series, str Source of data to append. inplace : bool If True, append ``other`` inplace, otherwise return a new ``MAGICCData`` in...
[ "Append", "any", "input", "which", "can", "be", "converted", "to", "MAGICCData", "to", "self", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L1973-L2001
train
openclimatedata/pymagicc
pymagicc/io.py
MAGICCData.write
def write(self, filepath, magicc_version): """ Write an input file to disk. Parameters ---------- filepath : str Filepath of the file to write. magicc_version : int The MAGICC version for which we want to write files. MAGICC7 and MAGICC6 ...
python
def write(self, filepath, magicc_version): """ Write an input file to disk. Parameters ---------- filepath : str Filepath of the file to write. magicc_version : int The MAGICC version for which we want to write files. MAGICC7 and MAGICC6 ...
[ "def", "write", "(", "self", ",", "filepath", ",", "magicc_version", ")", ":", "writer", "=", "determine_tool", "(", "filepath", ",", "\"writer\"", ")", "(", "magicc_version", "=", "magicc_version", ")", "writer", ".", "write", "(", "self", ",", "filepath", ...
Write an input file to disk. Parameters ---------- filepath : str Filepath of the file to write. magicc_version : int The MAGICC version for which we want to write files. MAGICC7 and MAGICC6 namelists are incompatible hence we need to know which one ...
[ "Write", "an", "input", "file", "to", "disk", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/io.py#L2003-L2018
train
productml/blurr
blurr/core/validator.py
validate_python_identifier_attributes
def validate_python_identifier_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[InvalidIdentifierError]: """ Validates a set of attributes as identifiers in a spec """ errors: List[InvalidIdentifierError] = [] checks: List[Tuple...
python
def validate_python_identifier_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[InvalidIdentifierError]: """ Validates a set of attributes as identifiers in a spec """ errors: List[InvalidIdentifierError] = [] checks: List[Tuple...
[ "def", "validate_python_identifier_attributes", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "*", "attributes", ":", "str", ")", "->", "List", "[", "InvalidIdentifierError", "]", ":", "errors", ":", "Li...
Validates a set of attributes as identifiers in a spec
[ "Validates", "a", "set", "of", "attributes", "as", "identifiers", "in", "a", "spec" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L11-L32
train
productml/blurr
blurr/core/validator.py
validate_required_attributes
def validate_required_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[RequiredAttributeError]: """ Validates to ensure that a set of attributes are present in spec """ return [ RequiredAttributeError(fully_qualified_name, spec, attri...
python
def validate_required_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[RequiredAttributeError]: """ Validates to ensure that a set of attributes are present in spec """ return [ RequiredAttributeError(fully_qualified_name, spec, attri...
[ "def", "validate_required_attributes", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "*", "attributes", ":", "str", ")", "->", "List", "[", "RequiredAttributeError", "]", ":", "return", "[", "RequiredAtt...
Validates to ensure that a set of attributes are present in spec
[ "Validates", "to", "ensure", "that", "a", "set", "of", "attributes", "are", "present", "in", "spec" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L35-L42
train
productml/blurr
blurr/core/validator.py
validate_empty_attributes
def validate_empty_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[EmptyAttributeError]: """ Validates to ensure that a set of attributes do not contain empty values """ return [ EmptyAttributeError(fully_qualified_name, spec, attribute...
python
def validate_empty_attributes(fully_qualified_name: str, spec: Dict[str, Any], *attributes: str) -> List[EmptyAttributeError]: """ Validates to ensure that a set of attributes do not contain empty values """ return [ EmptyAttributeError(fully_qualified_name, spec, attribute...
[ "def", "validate_empty_attributes", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "*", "attributes", ":", "str", ")", "->", "List", "[", "EmptyAttributeError", "]", ":", "return", "[", "EmptyAttributeErr...
Validates to ensure that a set of attributes do not contain empty values
[ "Validates", "to", "ensure", "that", "a", "set", "of", "attributes", "do", "not", "contain", "empty", "values" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L45-L52
train
productml/blurr
blurr/core/validator.py
validate_number_attribute
def validate_number_attribute( fully_qualified_name: str, spec: Dict[str, Any], attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] = None) -> Optional[InvalidNumberError]: ...
python
def validate_number_attribute( fully_qualified_name: str, spec: Dict[str, Any], attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] = None) -> Optional[InvalidNumberError]: ...
[ "def", "validate_number_attribute", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "attribute", ":", "str", ",", "value_type", ":", "Union", "[", "Type", "[", "int", "]", ",", "Type", "[", "float", ...
Validates to ensure that the value is a number of the specified type, and lies with the specified range
[ "Validates", "to", "ensure", "that", "the", "value", "is", "a", "number", "of", "the", "specified", "type", "and", "lies", "with", "the", "specified", "range" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L55-L73
train
productml/blurr
blurr/core/validator.py
validate_enum_attribute
def validate_enum_attribute(fully_qualified_name: str, spec: Dict[str, Any], attribute: str, candidates: Set[Union[str, int, float]]) -> Optional[InvalidValueError]: """ Validates to ensure that the value of an attribute lies within an allowed set of candidates """ if attribute not ...
python
def validate_enum_attribute(fully_qualified_name: str, spec: Dict[str, Any], attribute: str, candidates: Set[Union[str, int, float]]) -> Optional[InvalidValueError]: """ Validates to ensure that the value of an attribute lies within an allowed set of candidates """ if attribute not ...
[ "def", "validate_enum_attribute", "(", "fully_qualified_name", ":", "str", ",", "spec", ":", "Dict", "[", "str", ",", "Any", "]", ",", "attribute", ":", "str", ",", "candidates", ":", "Set", "[", "Union", "[", "str", ",", "int", ",", "float", "]", "]",...
Validates to ensure that the value of an attribute lies within an allowed set of candidates
[ "Validates", "to", "ensure", "that", "the", "value", "of", "an", "attribute", "lies", "within", "an", "allowed", "set", "of", "candidates" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/validator.py#L76-L84
train
productml/blurr
blurr/core/store_key.py
Key.parse
def parse(key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[3]: key_type = KeyType.TIMESTAMP return Key(key_type, parts[0], parts[1], parts[2].split(Key.DIMENSION...
python
def parse(key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[3]: key_type = KeyType.TIMESTAMP return Key(key_type, parts[0], parts[1], parts[2].split(Key.DIMENSION...
[ "def", "parse", "(", "key_string", ":", "str", ")", "->", "'Key'", ":", "parts", "=", "key_string", ".", "split", "(", "Key", ".", "PARTITION", ")", "key_type", "=", "KeyType", ".", "DIMENSION", "if", "parts", "[", "3", "]", ":", "key_type", "=", "Ke...
Parses a flat key string and returns a key
[ "Parses", "a", "flat", "key", "string", "and", "returns", "a", "key" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store_key.py#L62-L70
train
productml/blurr
blurr/core/store_key.py
Key.parse_sort_key
def parse_sort_key(identity: str, sort_key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = sort_key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[2]: key_type = KeyType.TIMESTAMP return Key(key_type, identity, part...
python
def parse_sort_key(identity: str, sort_key_string: str) -> 'Key': """ Parses a flat key string and returns a key """ parts = sort_key_string.split(Key.PARTITION) key_type = KeyType.DIMENSION if parts[2]: key_type = KeyType.TIMESTAMP return Key(key_type, identity, part...
[ "def", "parse_sort_key", "(", "identity", ":", "str", ",", "sort_key_string", ":", "str", ")", "->", "'Key'", ":", "parts", "=", "sort_key_string", ".", "split", "(", "Key", ".", "PARTITION", ")", "key_type", "=", "KeyType", ".", "DIMENSION", "if", "parts"...
Parses a flat key string and returns a key
[ "Parses", "a", "flat", "key", "string", "and", "returns", "a", "key" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store_key.py#L73-L81
train
productml/blurr
blurr/core/store_key.py
Key.starts_with
def starts_with(self, other: 'Key') -> bool: """ Checks if this key starts with the other key provided. Returns False if key_type, identity or group are different. For `KeyType.TIMESTAMP` returns True. For `KeyType.DIMENSION` does prefix match between the two dimensions property....
python
def starts_with(self, other: 'Key') -> bool: """ Checks if this key starts with the other key provided. Returns False if key_type, identity or group are different. For `KeyType.TIMESTAMP` returns True. For `KeyType.DIMENSION` does prefix match between the two dimensions property....
[ "def", "starts_with", "(", "self", ",", "other", ":", "'Key'", ")", "->", "bool", ":", "if", "(", "self", ".", "key_type", ",", "self", ".", "identity", ",", "self", ".", "group", ")", "!=", "(", "other", ".", "key_type", ",", "other", ".", "identi...
Checks if this key starts with the other key provided. Returns False if key_type, identity or group are different. For `KeyType.TIMESTAMP` returns True. For `KeyType.DIMENSION` does prefix match between the two dimensions property.
[ "Checks", "if", "this", "key", "starts", "with", "the", "other", "key", "provided", ".", "Returns", "False", "if", "key_type", "identity", "or", "group", "are", "different", ".", "For", "KeyType", ".", "TIMESTAMP", "returns", "True", ".", "For", "KeyType", ...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store_key.py#L141-L156
train
productml/blurr
blurr/core/aggregate_identity.py
IdentityAggregate._evaluate_dimension_fields
def _evaluate_dimension_fields(self) -> bool: """ Evaluates the dimension fields. Returns False if any of the fields could not be evaluated. """ for _, item in self._dimension_fields.items(): item.run_evaluate() if item.eval_error: return False ...
python
def _evaluate_dimension_fields(self) -> bool: """ Evaluates the dimension fields. Returns False if any of the fields could not be evaluated. """ for _, item in self._dimension_fields.items(): item.run_evaluate() if item.eval_error: return False ...
[ "def", "_evaluate_dimension_fields", "(", "self", ")", "->", "bool", ":", "for", "_", ",", "item", "in", "self", ".", "_dimension_fields", ".", "items", "(", ")", ":", "item", ".", "run_evaluate", "(", ")", "if", "item", ".", "eval_error", ":", "return",...
Evaluates the dimension fields. Returns False if any of the fields could not be evaluated.
[ "Evaluates", "the", "dimension", "fields", ".", "Returns", "False", "if", "any", "of", "the", "fields", "could", "not", "be", "evaluated", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_identity.py#L85-L93
train
productml/blurr
blurr/core/aggregate_identity.py
IdentityAggregate._compare_dimensions_to_fields
def _compare_dimensions_to_fields(self) -> bool: """ Compares the dimension field values to the value in regular fields.""" for name, item in self._dimension_fields.items(): if item.value != self._nested_items[name].value: return False return True
python
def _compare_dimensions_to_fields(self) -> bool: """ Compares the dimension field values to the value in regular fields.""" for name, item in self._dimension_fields.items(): if item.value != self._nested_items[name].value: return False return True
[ "def", "_compare_dimensions_to_fields", "(", "self", ")", "->", "bool", ":", "for", "name", ",", "item", "in", "self", ".", "_dimension_fields", ".", "items", "(", ")", ":", "if", "item", ".", "value", "!=", "self", ".", "_nested_items", "[", "name", "]"...
Compares the dimension field values to the value in regular fields.
[ "Compares", "the", "dimension", "field", "values", "to", "the", "value", "in", "regular", "fields", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_identity.py#L95-L100
train
productml/blurr
blurr/core/aggregate_identity.py
IdentityAggregate._key
def _key(self): """ Generates the Key object based on dimension fields. """ return Key(self._schema.key_type, self._identity, self._name, [str(item.value) for item in self._dimension_fields.values()])
python
def _key(self): """ Generates the Key object based on dimension fields. """ return Key(self._schema.key_type, self._identity, self._name, [str(item.value) for item in self._dimension_fields.values()])
[ "def", "_key", "(", "self", ")", ":", "return", "Key", "(", "self", ".", "_schema", ".", "key_type", ",", "self", ".", "_identity", ",", "self", ".", "_name", ",", "[", "str", "(", "item", ".", "value", ")", "for", "item", "in", "self", ".", "_di...
Generates the Key object based on dimension fields.
[ "Generates", "the", "Key", "object", "based", "on", "dimension", "fields", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_identity.py#L103-L106
train
openclimatedata/pymagicc
pymagicc/__init__.py
run
def run(scenario, magicc_version=6, **kwargs): """ Run a MAGICC scenario and return output data and (optionally) config parameters. As a reminder, putting ``out_parameters=1`` will cause MAGICC to write out its parameters into ``out/PARAMETERS.OUT`` and they will then be read into ``output.metadata...
python
def run(scenario, magicc_version=6, **kwargs): """ Run a MAGICC scenario and return output data and (optionally) config parameters. As a reminder, putting ``out_parameters=1`` will cause MAGICC to write out its parameters into ``out/PARAMETERS.OUT`` and they will then be read into ``output.metadata...
[ "def", "run", "(", "scenario", ",", "magicc_version", "=", "6", ",", "*", "*", "kwargs", ")", ":", "if", "magicc_version", "==", "6", ":", "magicc_cls", "=", "MAGICC6", "elif", "magicc_version", "==", "7", ":", "magicc_cls", "=", "MAGICC7", "else", ":", ...
Run a MAGICC scenario and return output data and (optionally) config parameters. As a reminder, putting ``out_parameters=1`` will cause MAGICC to write out its parameters into ``out/PARAMETERS.OUT`` and they will then be read into ``output.metadata["parameters"]`` where ``output`` is the returned object. ...
[ "Run", "a", "MAGICC", "scenario", "and", "return", "output", "data", "and", "(", "optionally", ")", "config", "parameters", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/__init__.py#L37-L77
train
productml/blurr
blurr/core/transformer_window.py
WindowTransformer.run_evaluate
def run_evaluate(self, block: TimeAggregate) -> bool: """ Evaluates the anchor condition against the specified block. :param block: Block to run the anchor condition against. :return: True, if the anchor condition is met, otherwise, False. """ if self._anchor.evaluate_anc...
python
def run_evaluate(self, block: TimeAggregate) -> bool: """ Evaluates the anchor condition against the specified block. :param block: Block to run the anchor condition against. :return: True, if the anchor condition is met, otherwise, False. """ if self._anchor.evaluate_anc...
[ "def", "run_evaluate", "(", "self", ",", "block", ":", "TimeAggregate", ")", "->", "bool", ":", "if", "self", ".", "_anchor", ".", "evaluate_anchor", "(", "block", ",", "self", ".", "_evaluation_context", ")", ":", "try", ":", "self", ".", "run_reset", "...
Evaluates the anchor condition against the specified block. :param block: Block to run the anchor condition against. :return: True, if the anchor condition is met, otherwise, False.
[ "Evaluates", "the", "anchor", "condition", "against", "the", "specified", "block", ".", ":", "param", "block", ":", "Block", "to", "run", "the", "anchor", "condition", "against", ".", ":", "return", ":", "True", "if", "the", "anchor", "condition", "is", "m...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/transformer_window.py#L51-L68
train
productml/blurr
blurr/core/aggregate_time.py
TimeAggregateSchema.extend_schema_spec
def extend_schema_spec(self) -> None: """ Injects the block start and end times """ super().extend_schema_spec() if self.ATTRIBUTE_FIELDS in self._spec: # Add new fields to the schema spec. Since `_identity` is added by the super, new elements are added after predefined_...
python
def extend_schema_spec(self) -> None: """ Injects the block start and end times """ super().extend_schema_spec() if self.ATTRIBUTE_FIELDS in self._spec: # Add new fields to the schema spec. Since `_identity` is added by the super, new elements are added after predefined_...
[ "def", "extend_schema_spec", "(", "self", ")", "->", "None", ":", "super", "(", ")", ".", "extend_schema_spec", "(", ")", "if", "self", ".", "ATTRIBUTE_FIELDS", "in", "self", ".", "_spec", ":", "# Add new fields to the schema spec. Since `_identity` is added by the su...
Injects the block start and end times
[ "Injects", "the", "block", "start", "and", "end", "times" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_time.py#L12-L23
train
productml/blurr
blurr/core/aggregate_time.py
TimeAggregateSchema._build_time_fields_spec
def _build_time_fields_spec(name_in_context: str) -> List[Dict[str, Any]]: """ Constructs the spec for predefined fields that are to be included in the master spec prior to schema load :param name_in_context: Name of the current object in the context :return: """ return [...
python
def _build_time_fields_spec(name_in_context: str) -> List[Dict[str, Any]]: """ Constructs the spec for predefined fields that are to be included in the master spec prior to schema load :param name_in_context: Name of the current object in the context :return: """ return [...
[ "def", "_build_time_fields_spec", "(", "name_in_context", ":", "str", ")", "->", "List", "[", "Dict", "[", "str", ",", "Any", "]", "]", ":", "return", "[", "{", "'Name'", ":", "'_start_time'", ",", "'Type'", ":", "Type", ".", "DATETIME", ",", "'Value'", ...
Constructs the spec for predefined fields that are to be included in the master spec prior to schema load :param name_in_context: Name of the current object in the context :return:
[ "Constructs", "the", "spec", "for", "predefined", "fields", "that", "are", "to", "be", "included", "in", "the", "master", "spec", "prior", "to", "schema", "load", ":", "param", "name_in_context", ":", "Name", "of", "the", "current", "object", "in", "the", ...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_time.py#L26-L49
train
openclimatedata/pymagicc
pymagicc/utils.py
apply_string_substitutions
def apply_string_substitutions( inputs, substitutions, inverse=False, case_insensitive=False, unused_substitutions="ignore", ): """Apply a number of substitutions to a string(s). The substitutions are applied effectively all at once. This means that conflicting substitutions don't inter...
python
def apply_string_substitutions( inputs, substitutions, inverse=False, case_insensitive=False, unused_substitutions="ignore", ): """Apply a number of substitutions to a string(s). The substitutions are applied effectively all at once. This means that conflicting substitutions don't inter...
[ "def", "apply_string_substitutions", "(", "inputs", ",", "substitutions", ",", "inverse", "=", "False", ",", "case_insensitive", "=", "False", ",", "unused_substitutions", "=", "\"ignore\"", ",", ")", ":", "if", "inverse", ":", "substitutions", "=", "{", "v", ...
Apply a number of substitutions to a string(s). The substitutions are applied effectively all at once. This means that conflicting substitutions don't interact. Where substitutions are conflicting, the one which is longer takes precedance. This is confusing so we recommend that you look at the examples...
[ "Apply", "a", "number", "of", "substitutions", "to", "a", "string", "(", "s", ")", "." ]
d896014832cf458d1e95e5878fd6d5961f3e2e05
https://github.com/openclimatedata/pymagicc/blob/d896014832cf458d1e95e5878fd6d5961f3e2e05/pymagicc/utils.py#L82-L188
train
productml/blurr
blurr/core/store.py
Store.get_range
def get_range(self, base_key: Key, start_time: datetime, end_time: datetime = None, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. :param base_k...
python
def get_range(self, base_key: Key, start_time: datetime, end_time: datetime = None, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. :param base_k...
[ "def", "get_range", "(", "self", ",", "base_key", ":", "Key", ",", "start_time", ":", "datetime", ",", "end_time", ":", "datetime", "=", "None", ",", "count", ":", "int", "=", "0", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ...
Returns the list of items from the store based on the given time range or count. :param base_key: Items which don't start with the base_key are filtered out. :param start_time: Start time to for the range query :param end_time: End time of the range query. If None count is used. :param c...
[ "Returns", "the", "list", "of", "items", "from", "the", "store", "based", "on", "the", "given", "time", "range", "or", "count", ".", ":", "param", "base_key", ":", "Items", "which", "don", "t", "start", "with", "the", "base_key", "are", "filtered", "out"...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L30-L60
train
productml/blurr
blurr/core/store.py
Store._get_range_timestamp_key
def _get_range_timestamp_key(self, start: Key, end: Key, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. This is used when the key being used is a TIMESTAMP key. """ r...
python
def _get_range_timestamp_key(self, start: Key, end: Key, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the store based on the given time range or count. This is used when the key being used is a TIMESTAMP key. """ r...
[ "def", "_get_range_timestamp_key", "(", "self", ",", "start", ":", "Key", ",", "end", ":", "Key", ",", "count", ":", "int", "=", "0", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ":", "raise", "NotImplementedError", "(", ")" ]
Returns the list of items from the store based on the given time range or count. This is used when the key being used is a TIMESTAMP key.
[ "Returns", "the", "list", "of", "items", "from", "the", "store", "based", "on", "the", "given", "time", "range", "or", "count", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L63-L70
train
productml/blurr
blurr/core/store.py
Store._get_range_dimension_key
def _get_range_dimension_key(self, base_key: Key, start_time: datetime, end_time: datetime, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the...
python
def _get_range_dimension_key(self, base_key: Key, start_time: datetime, end_time: datetime, count: int = 0) -> List[Tuple[Key, Any]]: """ Returns the list of items from the...
[ "def", "_get_range_dimension_key", "(", "self", ",", "base_key", ":", "Key", ",", "start_time", ":", "datetime", ",", "end_time", ":", "datetime", ",", "count", ":", "int", "=", "0", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ...
Returns the list of items from the store based on the given time range or count. This is used when the key being used is a DIMENSION key.
[ "Returns", "the", "list", "of", "items", "from", "the", "store", "based", "on", "the", "given", "time", "range", "or", "count", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L79-L89
train
productml/blurr
blurr/core/store.py
Store._restrict_items_to_count
def _restrict_items_to_count(items: List[Tuple[Key, Any]], count: int) -> List[Tuple[Key, Any]]: """ Restricts items to count number if len(items) is larger than abs(count). This function assumes that items is sorted by time. :param items: The items to restrict. :param count: Th...
python
def _restrict_items_to_count(items: List[Tuple[Key, Any]], count: int) -> List[Tuple[Key, Any]]: """ Restricts items to count number if len(items) is larger than abs(count). This function assumes that items is sorted by time. :param items: The items to restrict. :param count: Th...
[ "def", "_restrict_items_to_count", "(", "items", ":", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ",", "count", ":", "int", ")", "->", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ":", "if", "abs", "(", "count", ")", ">", ...
Restricts items to count number if len(items) is larger than abs(count). This function assumes that items is sorted by time. :param items: The items to restrict. :param count: The number of items returned.
[ "Restricts", "items", "to", "count", "number", "if", "len", "(", "items", ")", "is", "larger", "than", "abs", "(", "count", ")", ".", "This", "function", "assumes", "that", "items", "is", "sorted", "by", "time", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/store.py#L92-L106
train
productml/blurr
blurr/core/base.py
BaseSchema.build_expression
def build_expression(self, attribute: str) -> Optional[Expression]: """ Builds an expression object. Adds an error if expression creation has errors. """ expression_string = self._spec.get(attribute, None) if expression_string: try: return Expression(str(expression_...
python
def build_expression(self, attribute: str) -> Optional[Expression]: """ Builds an expression object. Adds an error if expression creation has errors. """ expression_string = self._spec.get(attribute, None) if expression_string: try: return Expression(str(expression_...
[ "def", "build_expression", "(", "self", ",", "attribute", ":", "str", ")", "->", "Optional", "[", "Expression", "]", ":", "expression_string", "=", "self", ".", "_spec", ".", "get", "(", "attribute", ",", "None", ")", "if", "expression_string", ":", "try",...
Builds an expression object. Adds an error if expression creation has errors.
[ "Builds", "an", "expression", "object", ".", "Adds", "an", "error", "if", "expression", "creation", "has", "errors", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L41-L52
train
productml/blurr
blurr/core/base.py
BaseSchema.add_errors
def add_errors(self, *errors: Union[BaseSchemaError, List[BaseSchemaError]]) -> None: """ Adds errors to the error repository in schema loader """ self.schema_loader.add_errors(*errors)
python
def add_errors(self, *errors: Union[BaseSchemaError, List[BaseSchemaError]]) -> None: """ Adds errors to the error repository in schema loader """ self.schema_loader.add_errors(*errors)
[ "def", "add_errors", "(", "self", ",", "*", "errors", ":", "Union", "[", "BaseSchemaError", ",", "List", "[", "BaseSchemaError", "]", "]", ")", "->", "None", ":", "self", ".", "schema_loader", ".", "add_errors", "(", "*", "errors", ")" ]
Adds errors to the error repository in schema loader
[ "Adds", "errors", "to", "the", "error", "repository", "in", "schema", "loader" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L54-L56
train
productml/blurr
blurr/core/base.py
BaseSchema.validate_required_attributes
def validate_required_attributes(self, *attributes: str) -> None: """ Validates that the schema contains a series of required attributes """ self.add_errors( validate_required_attributes(self.fully_qualified_name, self._spec, *attributes))
python
def validate_required_attributes(self, *attributes: str) -> None: """ Validates that the schema contains a series of required attributes """ self.add_errors( validate_required_attributes(self.fully_qualified_name, self._spec, *attributes))
[ "def", "validate_required_attributes", "(", "self", ",", "*", "attributes", ":", "str", ")", "->", "None", ":", "self", ".", "add_errors", "(", "validate_required_attributes", "(", "self", ".", "fully_qualified_name", ",", "self", ".", "_spec", ",", "*", "attr...
Validates that the schema contains a series of required attributes
[ "Validates", "that", "the", "schema", "contains", "a", "series", "of", "required", "attributes" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L63-L66
train
productml/blurr
blurr/core/base.py
BaseSchema.validate_number_attribute
def validate_number_attribute(self, attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] =...
python
def validate_number_attribute(self, attribute: str, value_type: Union[Type[int], Type[float]] = int, minimum: Optional[Union[int, float]] = None, maximum: Optional[Union[int, float]] =...
[ "def", "validate_number_attribute", "(", "self", ",", "attribute", ":", "str", ",", "value_type", ":", "Union", "[", "Type", "[", "int", "]", ",", "Type", "[", "float", "]", "]", "=", "int", ",", "minimum", ":", "Optional", "[", "Union", "[", "int", ...
Validates that the attribute contains a numeric value within boundaries if specified
[ "Validates", "that", "the", "attribute", "contains", "a", "numeric", "value", "within", "boundaries", "if", "specified" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L68-L76
train
productml/blurr
blurr/core/base.py
BaseSchema.validate_enum_attribute
def validate_enum_attribute(self, attribute: str, candidates: Set[Union[str, int, float]]) -> None: """ Validates that the attribute value is among the candidates """ self.add_errors( validate_enum_attribute(self.fully_qualified_name, self._spec, attribute, ca...
python
def validate_enum_attribute(self, attribute: str, candidates: Set[Union[str, int, float]]) -> None: """ Validates that the attribute value is among the candidates """ self.add_errors( validate_enum_attribute(self.fully_qualified_name, self._spec, attribute, ca...
[ "def", "validate_enum_attribute", "(", "self", ",", "attribute", ":", "str", ",", "candidates", ":", "Set", "[", "Union", "[", "str", ",", "int", ",", "float", "]", "]", ")", "->", "None", ":", "self", ".", "add_errors", "(", "validate_enum_attribute", "...
Validates that the attribute value is among the candidates
[ "Validates", "that", "the", "attribute", "value", "is", "among", "the", "candidates" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L78-L82
train
productml/blurr
blurr/core/base.py
BaseSchema.validate_schema_spec
def validate_schema_spec(self) -> None: """ Contains the validation routines that are to be executed as part of initialization by subclasses. When this method is being extended, the first line should always be: ```super().validate_schema_spec()``` """ self.add_errors( validate_empty_...
python
def validate_schema_spec(self) -> None: """ Contains the validation routines that are to be executed as part of initialization by subclasses. When this method is being extended, the first line should always be: ```super().validate_schema_spec()``` """ self.add_errors( validate_empty_...
[ "def", "validate_schema_spec", "(", "self", ")", "->", "None", ":", "self", ".", "add_errors", "(", "validate_empty_attributes", "(", "self", ".", "fully_qualified_name", ",", "self", ".", "_spec", ",", "*", "self", ".", "_spec", ".", "keys", "(", ")", ")"...
Contains the validation routines that are to be executed as part of initialization by subclasses. When this method is being extended, the first line should always be: ```super().validate_schema_spec()```
[ "Contains", "the", "validation", "routines", "that", "are", "to", "be", "executed", "as", "part", "of", "initialization", "by", "subclasses", ".", "When", "this", "method", "is", "being", "extended", "the", "first", "line", "should", "always", "be", ":", "su...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L84-L91
train
productml/blurr
blurr/core/base.py
BaseItem._needs_evaluation
def _needs_evaluation(self) -> bool: """ Returns True when: 1. Where clause is not specified 2. Where WHERE clause is specified and it evaluates to True Returns false if a where clause is specified and it evaluates to False """ return self._schema.when is ...
python
def _needs_evaluation(self) -> bool: """ Returns True when: 1. Where clause is not specified 2. Where WHERE clause is specified and it evaluates to True Returns false if a where clause is specified and it evaluates to False """ return self._schema.when is ...
[ "def", "_needs_evaluation", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_schema", ".", "when", "is", "None", "or", "self", ".", "_schema", ".", "when", ".", "evaluate", "(", "self", ".", "_evaluation_context", ")" ]
Returns True when: 1. Where clause is not specified 2. Where WHERE clause is specified and it evaluates to True Returns false if a where clause is specified and it evaluates to False
[ "Returns", "True", "when", ":", "1", ".", "Where", "clause", "is", "not", "specified", "2", ".", "Where", "WHERE", "clause", "is", "specified", "and", "it", "evaluates", "to", "True", "Returns", "false", "if", "a", "where", "clause", "is", "specified", "...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L147-L154
train
productml/blurr
blurr/core/base.py
BaseItemCollection.run_evaluate
def run_evaluate(self, *args, **kwargs) -> None: """ Evaluates the current item :returns An evaluation result object containing the result, or reasons why evaluation failed """ if self._needs_evaluation: for _, item in self._nested_items.items(): ...
python
def run_evaluate(self, *args, **kwargs) -> None: """ Evaluates the current item :returns An evaluation result object containing the result, or reasons why evaluation failed """ if self._needs_evaluation: for _, item in self._nested_items.items(): ...
[ "def", "run_evaluate", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "self", ".", "_needs_evaluation", ":", "for", "_", ",", "item", "in", "self", ".", "_nested_items", ".", "items", "(", ")", ":", "item", "....
Evaluates the current item :returns An evaluation result object containing the result, or reasons why evaluation failed
[ "Evaluates", "the", "current", "item", ":", "returns", "An", "evaluation", "result", "object", "containing", "the", "result", "or", "reasons", "why", "evaluation", "failed" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L208-L216
train
productml/blurr
blurr/core/base.py
BaseItemCollection._snapshot
def _snapshot(self) -> Dict[str, Any]: """ Implements snapshot for collections by recursively invoking snapshot of all child items """ try: return {name: item._snapshot for name, item in self._nested_items.items()} except Exception as e: raise SnapshotErro...
python
def _snapshot(self) -> Dict[str, Any]: """ Implements snapshot for collections by recursively invoking snapshot of all child items """ try: return {name: item._snapshot for name, item in self._nested_items.items()} except Exception as e: raise SnapshotErro...
[ "def", "_snapshot", "(", "self", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "try", ":", "return", "{", "name", ":", "item", ".", "_snapshot", "for", "name", ",", "item", "in", "self", ".", "_nested_items", ".", "items", "(", ")", "}", "...
Implements snapshot for collections by recursively invoking snapshot of all child items
[ "Implements", "snapshot", "for", "collections", "by", "recursively", "invoking", "snapshot", "of", "all", "child", "items" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L219-L226
train
productml/blurr
blurr/core/base.py
BaseItemCollection.run_restore
def run_restore(self, snapshot: Dict[Union[str, Key], Any]) -> 'BaseItemCollection': """ Restores the state of a collection from a snapshot """ try: for name, snap in snapshot.items(): if isinstance(name, Key): self._nested_items[name.grou...
python
def run_restore(self, snapshot: Dict[Union[str, Key], Any]) -> 'BaseItemCollection': """ Restores the state of a collection from a snapshot """ try: for name, snap in snapshot.items(): if isinstance(name, Key): self._nested_items[name.grou...
[ "def", "run_restore", "(", "self", ",", "snapshot", ":", "Dict", "[", "Union", "[", "str", ",", "Key", "]", ",", "Any", "]", ")", "->", "'BaseItemCollection'", ":", "try", ":", "for", "name", ",", "snap", "in", "snapshot", ".", "items", "(", ")", "...
Restores the state of a collection from a snapshot
[ "Restores", "the", "state", "of", "a", "collection", "from", "a", "snapshot" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/base.py#L228-L242
train
productml/blurr
blurr/core/aggregate_window.py
WindowAggregate._prepare_window
def _prepare_window(self, start_time: datetime) -> None: """ Prepares window if any is specified. :param start_time: The anchor block start_time from where the window should be generated. """ # evaluate window first which sets the correct window in the store store...
python
def _prepare_window(self, start_time: datetime) -> None: """ Prepares window if any is specified. :param start_time: The anchor block start_time from where the window should be generated. """ # evaluate window first which sets the correct window in the store store...
[ "def", "_prepare_window", "(", "self", ",", "start_time", ":", "datetime", ")", "->", "None", ":", "# evaluate window first which sets the correct window in the store", "store", "=", "self", ".", "_schema", ".", "schema_loader", ".", "get_store", "(", "self", ".", "...
Prepares window if any is specified. :param start_time: The anchor block start_time from where the window should be generated.
[ "Prepares", "window", "if", "any", "is", "specified", ".", ":", "param", "start_time", ":", "The", "anchor", "block", "start_time", "from", "where", "the", "window", "should", "be", "generated", "." ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_window.py#L60-L82
train
productml/blurr
blurr/core/aggregate_window.py
WindowAggregate._get_end_time
def _get_end_time(self, start_time: datetime) -> datetime: """ Generates the end time to be used for the store range query. :param start_time: Start time to use as an offset to calculate the end time based on the window type in the schema. :return: """ if Type.is_...
python
def _get_end_time(self, start_time: datetime) -> datetime: """ Generates the end time to be used for the store range query. :param start_time: Start time to use as an offset to calculate the end time based on the window type in the schema. :return: """ if Type.is_...
[ "def", "_get_end_time", "(", "self", ",", "start_time", ":", "datetime", ")", "->", "datetime", ":", "if", "Type", ".", "is_type_equal", "(", "self", ".", "_schema", ".", "window_type", ",", "Type", ".", "DAY", ")", ":", "return", "start_time", "+", "tim...
Generates the end time to be used for the store range query. :param start_time: Start time to use as an offset to calculate the end time based on the window type in the schema. :return:
[ "Generates", "the", "end", "time", "to", "be", "used", "for", "the", "store", "range", "query", ".", ":", "param", "start_time", ":", "Start", "time", "to", "use", "as", "an", "offset", "to", "calculate", "the", "end", "time", "based", "on", "the", "wi...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_window.py#L100-L110
train
productml/blurr
blurr/core/aggregate_window.py
WindowAggregate._load_blocks
def _load_blocks(self, blocks: List[Tuple[Key, Any]]) -> List[TimeAggregate]: """ Converts [(Key, block)] to [BlockAggregate] :param blocks: List of (Key, block) blocks. :return: List of BlockAggregate """ return [ TypeLoader.load_item(self._schema.source.type...
python
def _load_blocks(self, blocks: List[Tuple[Key, Any]]) -> List[TimeAggregate]: """ Converts [(Key, block)] to [BlockAggregate] :param blocks: List of (Key, block) blocks. :return: List of BlockAggregate """ return [ TypeLoader.load_item(self._schema.source.type...
[ "def", "_load_blocks", "(", "self", ",", "blocks", ":", "List", "[", "Tuple", "[", "Key", ",", "Any", "]", "]", ")", "->", "List", "[", "TimeAggregate", "]", ":", "return", "[", "TypeLoader", ".", "load_item", "(", "self", ".", "_schema", ".", "sourc...
Converts [(Key, block)] to [BlockAggregate] :param blocks: List of (Key, block) blocks. :return: List of BlockAggregate
[ "Converts", "[", "(", "Key", "block", ")", "]", "to", "[", "BlockAggregate", "]", ":", "param", "blocks", ":", "List", "of", "(", "Key", "block", ")", "blocks", ".", ":", "return", ":", "List", "of", "BlockAggregate" ]
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/core/aggregate_window.py#L112-L122
train
productml/blurr
blurr/runner/runner.py
Runner.execute_per_identity_records
def execute_per_identity_records( self, identity: str, records: List[TimeAndRecord], old_state: Optional[Dict[Key, Any]] = None) -> Tuple[str, Tuple[Dict, List]]: """ Executes the streaming and window BTS on the given records. An option old state can provi...
python
def execute_per_identity_records( self, identity: str, records: List[TimeAndRecord], old_state: Optional[Dict[Key, Any]] = None) -> Tuple[str, Tuple[Dict, List]]: """ Executes the streaming and window BTS on the given records. An option old state can provi...
[ "def", "execute_per_identity_records", "(", "self", ",", "identity", ":", "str", ",", "records", ":", "List", "[", "TimeAndRecord", "]", ",", "old_state", ":", "Optional", "[", "Dict", "[", "Key", ",", "Any", "]", "]", "=", "None", ")", "->", "Tuple", ...
Executes the streaming and window BTS on the given records. An option old state can provided which initializes the state for execution. This is useful for batch execution where the previous state is written out to storage and can be loaded for the next batch run. :param identity: Identity of th...
[ "Executes", "the", "streaming", "and", "window", "BTS", "on", "the", "given", "records", ".", "An", "option", "old", "state", "can", "provided", "which", "initializes", "the", "state", "for", "execution", ".", "This", "is", "useful", "for", "batch", "executi...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/runner/runner.py#L55-L80
train
productml/blurr
blurr/runner/runner.py
Runner.get_per_identity_records
def get_per_identity_records(self, events: Iterable, data_processor: DataProcessor ) -> Generator[Tuple[str, TimeAndRecord], None, None]: """ Uses the given iteratable events and the data processor convert the event into a list of Records along with its identity ...
python
def get_per_identity_records(self, events: Iterable, data_processor: DataProcessor ) -> Generator[Tuple[str, TimeAndRecord], None, None]: """ Uses the given iteratable events and the data processor convert the event into a list of Records along with its identity ...
[ "def", "get_per_identity_records", "(", "self", ",", "events", ":", "Iterable", ",", "data_processor", ":", "DataProcessor", ")", "->", "Generator", "[", "Tuple", "[", "str", ",", "TimeAndRecord", "]", ",", "None", ",", "None", "]", ":", "schema_loader", "="...
Uses the given iteratable events and the data processor convert the event into a list of Records along with its identity and time. :param events: iteratable events. :param data_processor: DataProcessor to process each event in events. :return: yields Tuple[Identity, TimeAndRecord] for al...
[ "Uses", "the", "given", "iteratable", "events", "and", "the", "data", "processor", "convert", "the", "event", "into", "a", "list", "of", "Records", "along", "with", "its", "identity", "and", "time", ".", ":", "param", "events", ":", "iteratable", "events", ...
1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa
https://github.com/productml/blurr/blob/1b688b2c4a9bbbb2139c58bf0682ddc05a6c24fa/blurr/runner/runner.py#L82-L105
train
svinota/mdns
mdns/zeroconf.py
DNSEntry.to_string
def to_string(self, hdr, other): """String representation with additional information""" result = "%s[%s,%s" % ( hdr, self.get_type(self.type), self.get_clazz(self.clazz)) if self.unique: result += "-unique," else: result += "," result += s...
python
def to_string(self, hdr, other): """String representation with additional information""" result = "%s[%s,%s" % ( hdr, self.get_type(self.type), self.get_clazz(self.clazz)) if self.unique: result += "-unique," else: result += "," result += s...
[ "def", "to_string", "(", "self", ",", "hdr", ",", "other", ")", ":", "result", "=", "\"%s[%s,%s\"", "%", "(", "hdr", ",", "self", ".", "get_type", "(", "self", ".", "type", ")", ",", "self", ".", "get_clazz", "(", "self", ".", "clazz", ")", ")", ...
String representation with additional information
[ "String", "representation", "with", "additional", "information" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L342-L355
train
svinota/mdns
mdns/zeroconf.py
DNSQuestion.answered_by
def answered_by(self, rec): """Returns true if the question is answered by the record""" return self.clazz == rec.clazz and \ (self.type == rec.type or self.type == _TYPE_ANY) and \ self.name == rec.name
python
def answered_by(self, rec): """Returns true if the question is answered by the record""" return self.clazz == rec.clazz and \ (self.type == rec.type or self.type == _TYPE_ANY) and \ self.name == rec.name
[ "def", "answered_by", "(", "self", ",", "rec", ")", ":", "return", "self", ".", "clazz", "==", "rec", ".", "clazz", "and", "(", "self", ".", "type", "==", "rec", ".", "type", "or", "self", ".", "type", "==", "_TYPE_ANY", ")", "and", "self", ".", ...
Returns true if the question is answered by the record
[ "Returns", "true", "if", "the", "question", "is", "answered", "by", "the", "record" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L370-L374
train
svinota/mdns
mdns/zeroconf.py
DNSRecord.reset_ttl
def reset_ttl(self, other): """Sets this record's TTL and created time to that of another record.""" self.created = other.created self.ttl = other.ttl
python
def reset_ttl(self, other): """Sets this record's TTL and created time to that of another record.""" self.created = other.created self.ttl = other.ttl
[ "def", "reset_ttl", "(", "self", ",", "other", ")", ":", "self", ".", "created", "=", "other", ".", "created", "self", ".", "ttl", "=", "other", ".", "ttl" ]
Sets this record's TTL and created time to that of another record.
[ "Sets", "this", "record", "s", "TTL", "and", "created", "time", "to", "that", "of", "another", "record", "." ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L425-L429
train
svinota/mdns
mdns/zeroconf.py
DNSRecord.to_string
def to_string(self, other): """String representation with addtional information""" arg = "%s/%s,%s" % ( self.ttl, self.get_remaining_ttl(current_time_millis()), other) return DNSEntry.to_string(self, "record", arg)
python
def to_string(self, other): """String representation with addtional information""" arg = "%s/%s,%s" % ( self.ttl, self.get_remaining_ttl(current_time_millis()), other) return DNSEntry.to_string(self, "record", arg)
[ "def", "to_string", "(", "self", ",", "other", ")", ":", "arg", "=", "\"%s/%s,%s\"", "%", "(", "self", ".", "ttl", ",", "self", ".", "get_remaining_ttl", "(", "current_time_millis", "(", ")", ")", ",", "other", ")", "return", "DNSEntry", ".", "to_string"...
String representation with addtional information
[ "String", "representation", "with", "addtional", "information" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L435-L439
train
svinota/mdns
mdns/zeroconf.py
DNSAddress.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.address, len(self.address))
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.address, len(self.address))
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_string", "(", "self", ".", "address", ",", "len", "(", "self", ".", "address", ")", ")" ]
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L528-L530
train
svinota/mdns
mdns/zeroconf.py
DNSHinfo.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.cpu, len(self.cpu)) out.write_string(self.os, len(self.os))
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.cpu, len(self.cpu)) out.write_string(self.os, len(self.os))
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_string", "(", "self", ".", "cpu", ",", "len", "(", "self", ".", "cpu", ")", ")", "out", ".", "write_string", "(", "self", ".", "os", ",", "len", "(", "self", ".", "os", ")", ...
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L568-L571
train
svinota/mdns
mdns/zeroconf.py
DNSText.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.text, len(self.text))
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_string(self.text, len(self.text))
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_string", "(", "self", ".", "text", ",", "len", "(", "self", ".", "text", ")", ")" ]
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L620-L622
train
svinota/mdns
mdns/zeroconf.py
DNSText.set_property
def set_property(self, key, value): """ Update only one property in the dict """ self.properties[key] = value self.sync_properties()
python
def set_property(self, key, value): """ Update only one property in the dict """ self.properties[key] = value self.sync_properties()
[ "def", "set_property", "(", "self", ",", "key", ",", "value", ")", ":", "self", ".", "properties", "[", "key", "]", "=", "value", "self", ".", "sync_properties", "(", ")" ]
Update only one property in the dict
[ "Update", "only", "one", "property", "in", "the", "dict" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L624-L629
train
svinota/mdns
mdns/zeroconf.py
DNSService.write
def write(self, out): """Used in constructing an outgoing packet""" out.write_short(self.priority) out.write_short(self.weight) out.write_short(self.port) out.write_name(self.server)
python
def write(self, out): """Used in constructing an outgoing packet""" out.write_short(self.priority) out.write_short(self.weight) out.write_short(self.port) out.write_name(self.server)
[ "def", "write", "(", "self", ",", "out", ")", ":", "out", ".", "write_short", "(", "self", ".", "priority", ")", "out", ".", "write_short", "(", "self", ".", "weight", ")", "out", ".", "write_short", "(", "self", ".", "port", ")", "out", ".", "writ...
Used in constructing an outgoing packet
[ "Used", "in", "constructing", "an", "outgoing", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L666-L671
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_header
def read_header(self): """Reads header portion of packet""" format = '!HHHHHH' length = struct.calcsize(format) info = struct.unpack(format, self.data[self.offset:self.offset + length]) self.offset += length self.id = info[0] self.flags = info[1] ...
python
def read_header(self): """Reads header portion of packet""" format = '!HHHHHH' length = struct.calcsize(format) info = struct.unpack(format, self.data[self.offset:self.offset + length]) self.offset += length self.id = info[0] self.flags = info[1] ...
[ "def", "read_header", "(", "self", ")", ":", "format", "=", "'!HHHHHH'", "length", "=", "struct", ".", "calcsize", "(", "format", ")", "info", "=", "struct", ".", "unpack", "(", "format", ",", "self", ".", "data", "[", "self", ".", "offset", ":", "se...
Reads header portion of packet
[ "Reads", "header", "portion", "of", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L708-L721
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_questions
def read_questions(self): """Reads questions section of packet""" format = '!HH' length = struct.calcsize(format) for i in range(0, self.num_questions): name = self.read_name() info = struct.unpack(format, self.data[self.offset:self.offset + le...
python
def read_questions(self): """Reads questions section of packet""" format = '!HH' length = struct.calcsize(format) for i in range(0, self.num_questions): name = self.read_name() info = struct.unpack(format, self.data[self.offset:self.offset + le...
[ "def", "read_questions", "(", "self", ")", ":", "format", "=", "'!HH'", "length", "=", "struct", ".", "calcsize", "(", "format", ")", "for", "i", "in", "range", "(", "0", ",", "self", ".", "num_questions", ")", ":", "name", "=", "self", ".", "read_na...
Reads questions section of packet
[ "Reads", "questions", "section", "of", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L723-L734
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_int
def read_int(self): """Reads an integer from the packet""" format = '!I' length = struct.calcsize(format) info = struct.unpack(format, self.data[self.offset:self.offset + length]) self.offset += length return info[0]
python
def read_int(self): """Reads an integer from the packet""" format = '!I' length = struct.calcsize(format) info = struct.unpack(format, self.data[self.offset:self.offset + length]) self.offset += length return info[0]
[ "def", "read_int", "(", "self", ")", ":", "format", "=", "'!I'", "length", "=", "struct", ".", "calcsize", "(", "format", ")", "info", "=", "struct", ".", "unpack", "(", "format", ",", "self", ".", "data", "[", "self", ".", "offset", ":", "self", "...
Reads an integer from the packet
[ "Reads", "an", "integer", "from", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L736-L743
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_character_string
def read_character_string(self): """Reads a character string from the packet""" length = ord(self.data[self.offset]) self.offset += 1 return self.read_string(length)
python
def read_character_string(self): """Reads a character string from the packet""" length = ord(self.data[self.offset]) self.offset += 1 return self.read_string(length)
[ "def", "read_character_string", "(", "self", ")", ":", "length", "=", "ord", "(", "self", ".", "data", "[", "self", ".", "offset", "]", ")", "self", ".", "offset", "+=", "1", "return", "self", ".", "read_string", "(", "length", ")" ]
Reads a character string from the packet
[ "Reads", "a", "character", "string", "from", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L745-L749
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_string
def read_string(self, len): """Reads a string of a given length from the packet""" format = '!' + str(len) + 's' length = struct.calcsize(format) info = struct.unpack(format, self.data[self.offset:self.offset + length]) self.offset += length return info[0]
python
def read_string(self, len): """Reads a string of a given length from the packet""" format = '!' + str(len) + 's' length = struct.calcsize(format) info = struct.unpack(format, self.data[self.offset:self.offset + length]) self.offset += length return info[0]
[ "def", "read_string", "(", "self", ",", "len", ")", ":", "format", "=", "'!'", "+", "str", "(", "len", ")", "+", "'s'", "length", "=", "struct", ".", "calcsize", "(", "format", ")", "info", "=", "struct", ".", "unpack", "(", "format", ",", "self", ...
Reads a string of a given length from the packet
[ "Reads", "a", "string", "of", "a", "given", "length", "from", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L751-L758
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_others
def read_others(self): """Reads the answers, authorities and additionals section of the packet""" format = '!HHiH' length = struct.calcsize(format) n = self.num_answers + self.num_authorities + self.num_additionals for i in range(0, n): domain = self.read_name...
python
def read_others(self): """Reads the answers, authorities and additionals section of the packet""" format = '!HHiH' length = struct.calcsize(format) n = self.num_answers + self.num_authorities + self.num_additionals for i in range(0, n): domain = self.read_name...
[ "def", "read_others", "(", "self", ")", ":", "format", "=", "'!HHiH'", "length", "=", "struct", ".", "calcsize", "(", "format", ")", "n", "=", "self", ".", "num_answers", "+", "self", ".", "num_authorities", "+", "self", ".", "num_additionals", "for", "i...
Reads the answers, authorities and additionals section of the packet
[ "Reads", "the", "answers", "authorities", "and", "additionals", "section", "of", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L769-L828
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_utf
def read_utf(self, offset, len): """Reads a UTF-8 string of a given length from the packet""" try: result = self.data[offset:offset + len].decode('utf-8') except UnicodeDecodeError: result = str('') return result
python
def read_utf(self, offset, len): """Reads a UTF-8 string of a given length from the packet""" try: result = self.data[offset:offset + len].decode('utf-8') except UnicodeDecodeError: result = str('') return result
[ "def", "read_utf", "(", "self", ",", "offset", ",", "len", ")", ":", "try", ":", "result", "=", "self", ".", "data", "[", "offset", ":", "offset", "+", "len", "]", ".", "decode", "(", "'utf-8'", ")", "except", "UnicodeDecodeError", ":", "result", "="...
Reads a UTF-8 string of a given length from the packet
[ "Reads", "a", "UTF", "-", "8", "string", "of", "a", "given", "length", "from", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L838-L844
train
svinota/mdns
mdns/zeroconf.py
DNSIncoming.read_name
def read_name(self): """Reads a domain name from the packet""" result = '' off = self.offset next = -1 first = off while 1: len = ord(self.data[off]) off += 1 if len == 0: break t = len & 0xC0 if...
python
def read_name(self): """Reads a domain name from the packet""" result = '' off = self.offset next = -1 first = off while 1: len = ord(self.data[off]) off += 1 if len == 0: break t = len & 0xC0 if...
[ "def", "read_name", "(", "self", ")", ":", "result", "=", "''", "off", "=", "self", ".", "offset", "next", "=", "-", "1", "first", "=", "off", "while", "1", ":", "len", "=", "ord", "(", "self", ".", "data", "[", "off", "]", ")", "off", "+=", ...
Reads a domain name from the packet
[ "Reads", "a", "domain", "name", "from", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L846-L878
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.add_answer
def add_answer(self, inp, record): """Adds an answer""" if not record.suppressed_by(inp): self.add_answer_at_time(record, 0)
python
def add_answer(self, inp, record): """Adds an answer""" if not record.suppressed_by(inp): self.add_answer_at_time(record, 0)
[ "def", "add_answer", "(", "self", ",", "inp", ",", "record", ")", ":", "if", "not", "record", ".", "suppressed_by", "(", "inp", ")", ":", "self", ".", "add_answer_at_time", "(", "record", ",", "0", ")" ]
Adds an answer
[ "Adds", "an", "answer" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L902-L905
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.add_answer_at_time
def add_answer_at_time(self, record, now): """Adds an answer if if does not expire by a certain time""" if record is not None: if now == 0 or not record.is_expired(now): self.answers.append((record, now)) if record.rrsig is not None: self.a...
python
def add_answer_at_time(self, record, now): """Adds an answer if if does not expire by a certain time""" if record is not None: if now == 0 or not record.is_expired(now): self.answers.append((record, now)) if record.rrsig is not None: self.a...
[ "def", "add_answer_at_time", "(", "self", ",", "record", ",", "now", ")", ":", "if", "record", "is", "not", "None", ":", "if", "now", "==", "0", "or", "not", "record", ".", "is_expired", "(", "now", ")", ":", "self", ".", "answers", ".", "append", ...
Adds an answer if if does not expire by a certain time
[ "Adds", "an", "answer", "if", "if", "does", "not", "expire", "by", "a", "certain", "time" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L907-L913
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_byte
def write_byte(self, value): """Writes a single byte to the packet""" format = '!B' self.data.append(struct.pack(format, value)) self.size += 1
python
def write_byte(self, value): """Writes a single byte to the packet""" format = '!B' self.data.append(struct.pack(format, value)) self.size += 1
[ "def", "write_byte", "(", "self", ",", "value", ")", ":", "format", "=", "'!B'", "self", ".", "data", ".", "append", "(", "struct", ".", "pack", "(", "format", ",", "value", ")", ")", "self", ".", "size", "+=", "1" ]
Writes a single byte to the packet
[ "Writes", "a", "single", "byte", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L923-L927
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.insert_short
def insert_short(self, index, value): """Inserts an unsigned short in a certain position in the packet""" format = '!H' self.data.insert(index, struct.pack(format, value)) self.size += 2
python
def insert_short(self, index, value): """Inserts an unsigned short in a certain position in the packet""" format = '!H' self.data.insert(index, struct.pack(format, value)) self.size += 2
[ "def", "insert_short", "(", "self", ",", "index", ",", "value", ")", ":", "format", "=", "'!H'", "self", ".", "data", ".", "insert", "(", "index", ",", "struct", ".", "pack", "(", "format", ",", "value", ")", ")", "self", ".", "size", "+=", "2" ]
Inserts an unsigned short in a certain position in the packet
[ "Inserts", "an", "unsigned", "short", "in", "a", "certain", "position", "in", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L935-L939
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_int
def write_int(self, value): """Writes an unsigned integer to the packet""" format = '!I' self.data.append(struct.pack(format, int(value))) self.size += 4
python
def write_int(self, value): """Writes an unsigned integer to the packet""" format = '!I' self.data.append(struct.pack(format, int(value))) self.size += 4
[ "def", "write_int", "(", "self", ",", "value", ")", ":", "format", "=", "'!I'", "self", ".", "data", ".", "append", "(", "struct", ".", "pack", "(", "format", ",", "int", "(", "value", ")", ")", ")", "self", ".", "size", "+=", "4" ]
Writes an unsigned integer to the packet
[ "Writes", "an", "unsigned", "integer", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L947-L951
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_string
def write_string(self, value, length): """Writes a string to the packet""" format = '!' + str(length) + 's' self.data.append(struct.pack(format, value)) self.size += length
python
def write_string(self, value, length): """Writes a string to the packet""" format = '!' + str(length) + 's' self.data.append(struct.pack(format, value)) self.size += length
[ "def", "write_string", "(", "self", ",", "value", ",", "length", ")", ":", "format", "=", "'!'", "+", "str", "(", "length", ")", "+", "'s'", "self", ".", "data", ".", "append", "(", "struct", ".", "pack", "(", "format", ",", "value", ")", ")", "s...
Writes a string to the packet
[ "Writes", "a", "string", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L953-L957
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_utf
def write_utf(self, s): """Writes a UTF-8 string of a given length to the packet""" utfstr = s.encode('utf-8') length = len(utfstr) if length > 64: raise NamePartTooLongException self.write_byte(length) self.write_string(utfstr, length)
python
def write_utf(self, s): """Writes a UTF-8 string of a given length to the packet""" utfstr = s.encode('utf-8') length = len(utfstr) if length > 64: raise NamePartTooLongException self.write_byte(length) self.write_string(utfstr, length)
[ "def", "write_utf", "(", "self", ",", "s", ")", ":", "utfstr", "=", "s", ".", "encode", "(", "'utf-8'", ")", "length", "=", "len", "(", "utfstr", ")", "if", "length", ">", "64", ":", "raise", "NamePartTooLongException", "self", ".", "write_byte", "(", ...
Writes a UTF-8 string of a given length to the packet
[ "Writes", "a", "UTF", "-", "8", "string", "of", "a", "given", "length", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L959-L966
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_name
def write_name(self, name): """Writes a domain name to the packet""" try: # Find existing instance of this name in packet # index = self.names[name] except KeyError: # No record of this name already, so write it # out as normal, record...
python
def write_name(self, name): """Writes a domain name to the packet""" try: # Find existing instance of this name in packet # index = self.names[name] except KeyError: # No record of this name already, so write it # out as normal, record...
[ "def", "write_name", "(", "self", ",", "name", ")", ":", "try", ":", "# Find existing instance of this name in packet", "#", "index", "=", "self", ".", "names", "[", "name", "]", "except", "KeyError", ":", "# No record of this name already, so write it", "# out as nor...
Writes a domain name to the packet
[ "Writes", "a", "domain", "name", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L968-L992
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_question
def write_question(self, question): """Writes a question to the packet""" self.write_name(question.name) self.write_short(question.type) self.write_short(question.clazz)
python
def write_question(self, question): """Writes a question to the packet""" self.write_name(question.name) self.write_short(question.type) self.write_short(question.clazz)
[ "def", "write_question", "(", "self", ",", "question", ")", ":", "self", ".", "write_name", "(", "question", ".", "name", ")", "self", ".", "write_short", "(", "question", ".", "type", ")", "self", ".", "write_short", "(", "question", ".", "clazz", ")" ]
Writes a question to the packet
[ "Writes", "a", "question", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L994-L998
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.write_record
def write_record(self, record, now): """Writes a record (answer, authoritative answer, additional) to the packet""" self.write_name(record.name) self.write_short(record.type) if record.unique and self.multicast: self.write_short(record.clazz | _CLASS_UNIQUE) e...
python
def write_record(self, record, now): """Writes a record (answer, authoritative answer, additional) to the packet""" self.write_name(record.name) self.write_short(record.type) if record.unique and self.multicast: self.write_short(record.clazz | _CLASS_UNIQUE) e...
[ "def", "write_record", "(", "self", ",", "record", ",", "now", ")", ":", "self", ".", "write_name", "(", "record", ".", "name", ")", "self", ".", "write_short", "(", "record", ".", "type", ")", "if", "record", ".", "unique", "and", "self", ".", "mult...
Writes a record (answer, authoritative answer, additional) to the packet
[ "Writes", "a", "record", "(", "answer", "authoritative", "answer", "additional", ")", "to", "the", "packet" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L1000-L1021
train
svinota/mdns
mdns/zeroconf.py
DNSOutgoing.packet
def packet(self): """Returns a string containing the packet's bytes No further parts should be added to the packet once this is done.""" if not self.finished: self.finished = 1 for question in self.questions: self.write_question(question) ...
python
def packet(self): """Returns a string containing the packet's bytes No further parts should be added to the packet once this is done.""" if not self.finished: self.finished = 1 for question in self.questions: self.write_question(question) ...
[ "def", "packet", "(", "self", ")", ":", "if", "not", "self", ".", "finished", ":", "self", ".", "finished", "=", "1", "for", "question", "in", "self", ".", "questions", ":", "self", ".", "write_question", "(", "question", ")", "for", "answer", ",", "...
Returns a string containing the packet's bytes No further parts should be added to the packet once this is done.
[ "Returns", "a", "string", "containing", "the", "packet", "s", "bytes" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L1023-L1048
train
svinota/mdns
mdns/zeroconf.py
DNSCache.add
def add(self, entry): """Adds an entry""" if self.get(entry) is not None: return try: list = self.cache[entry.key] except: list = self.cache[entry.key] = [] list.append(entry)
python
def add(self, entry): """Adds an entry""" if self.get(entry) is not None: return try: list = self.cache[entry.key] except: list = self.cache[entry.key] = [] list.append(entry)
[ "def", "add", "(", "self", ",", "entry", ")", ":", "if", "self", ".", "get", "(", "entry", ")", "is", "not", "None", ":", "return", "try", ":", "list", "=", "self", ".", "cache", "[", "entry", ".", "key", "]", "except", ":", "list", "=", "self"...
Adds an entry
[ "Adds", "an", "entry" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L1058-L1066
train
svinota/mdns
mdns/zeroconf.py
DNSCache.sign
def sign(self, entry, signer=None): """Adds and sign an entry""" if (self.get(entry) is not None): return if (entry.rrsig is None) and (self.private is not None): entry.rrsig = DNSSignatureS(entry.name, _TYPE_RRSIG, _CLASS_IN, entry, self.private, sign...
python
def sign(self, entry, signer=None): """Adds and sign an entry""" if (self.get(entry) is not None): return if (entry.rrsig is None) and (self.private is not None): entry.rrsig = DNSSignatureS(entry.name, _TYPE_RRSIG, _CLASS_IN, entry, self.private, sign...
[ "def", "sign", "(", "self", ",", "entry", ",", "signer", "=", "None", ")", ":", "if", "(", "self", ".", "get", "(", "entry", ")", "is", "not", "None", ")", ":", "return", "if", "(", "entry", ".", "rrsig", "is", "None", ")", "and", "(", "self", ...
Adds and sign an entry
[ "Adds", "and", "sign", "an", "entry" ]
295f6407132616a0ff7401124b9057d89555f91d
https://github.com/svinota/mdns/blob/295f6407132616a0ff7401124b9057d89555f91d/mdns/zeroconf.py#L1068-L1077
train