id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,400 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_pubs | def _process_pubs(self, limit):
"""
Flybase publications.
:param limit:
:return:
"""
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
model = Model(graph)
line_counter = 0
raw = '/'.join((self.ra... | python | def _process_pubs(self, limit):
"""
Flybase publications.
:param limit:
:return:
"""
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
model = Model(graph)
line_counter = 0
raw = '/'.join((self.ra... | [
"def",
"_process_pubs",
"(",
"self",
",",
"limit",
")",
":",
"if",
"self",
".",
"test_mode",
":",
"graph",
"=",
"self",
".",
"testgraph",
"else",
":",
"graph",
"=",
"self",
".",
"graph",
"model",
"=",
"Model",
"(",
"graph",
")",
"line_counter",
"=",
... | Flybase publications.
:param limit:
:return: | [
"Flybase",
"publications",
"."
] | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L483-L539 |
18,401 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_environments | def _process_environments(self):
"""
There's only about 30 environments in which the phenotypes
are recorded.
There are no externally accessible identifiers for environments,
so we make anonymous nodes for now.
Some of the environments are comprised of >1 of the other env... | python | def _process_environments(self):
"""
There's only about 30 environments in which the phenotypes
are recorded.
There are no externally accessible identifiers for environments,
so we make anonymous nodes for now.
Some of the environments are comprised of >1 of the other env... | [
"def",
"_process_environments",
"(",
"self",
")",
":",
"if",
"self",
".",
"test_mode",
":",
"graph",
"=",
"self",
".",
"testgraph",
"else",
":",
"graph",
"=",
"self",
".",
"graph",
"raw",
"=",
"'/'",
".",
"join",
"(",
"(",
"self",
".",
"rawdir",
",",... | There's only about 30 environments in which the phenotypes
are recorded.
There are no externally accessible identifiers for environments,
so we make anonymous nodes for now.
Some of the environments are comprised of >1 of the other environments;
we do some simple parsing to match... | [
"There",
"s",
"only",
"about",
"30",
"environments",
"in",
"which",
"the",
"phenotypes",
"are",
"recorded",
".",
"There",
"are",
"no",
"externally",
"accessible",
"identifiers",
"for",
"environments",
"so",
"we",
"make",
"anonymous",
"nodes",
"for",
"now",
"."... | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L542-L604 |
18,402 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_stock_genotype | def _process_stock_genotype(self, limit):
"""
The genotypes of the stocks.
:param limit:
:return:
"""
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
raw = '/'.join((self.rawdir, 'stock_genotype'))
LOG.... | python | def _process_stock_genotype(self, limit):
"""
The genotypes of the stocks.
:param limit:
:return:
"""
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
raw = '/'.join((self.rawdir, 'stock_genotype'))
LOG.... | [
"def",
"_process_stock_genotype",
"(",
"self",
",",
"limit",
")",
":",
"if",
"self",
".",
"test_mode",
":",
"graph",
"=",
"self",
".",
"testgraph",
"else",
":",
"graph",
"=",
"self",
".",
"graph",
"raw",
"=",
"'/'",
".",
"join",
"(",
"(",
"self",
"."... | The genotypes of the stocks.
:param limit:
:return: | [
"The",
"genotypes",
"of",
"the",
"stocks",
"."
] | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L926-L965 |
18,403 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_dbxref | def _process_dbxref(self):
"""
We bring in the dbxref identifiers and store them in a hashmap for
lookup in other functions.
Note that some dbxrefs aren't mapped to identifiers.
For example, 5004018 is mapped to a string,
"endosome & imaginal disc epithelial cell | so... | python | def _process_dbxref(self):
"""
We bring in the dbxref identifiers and store them in a hashmap for
lookup in other functions.
Note that some dbxrefs aren't mapped to identifiers.
For example, 5004018 is mapped to a string,
"endosome & imaginal disc epithelial cell | so... | [
"def",
"_process_dbxref",
"(",
"self",
")",
":",
"raw",
"=",
"'/'",
".",
"join",
"(",
"(",
"self",
".",
"rawdir",
",",
"'dbxref'",
")",
")",
"LOG",
".",
"info",
"(",
"\"processing dbxrefs\"",
")",
"line_counter",
"=",
"0",
"with",
"open",
"(",
"raw",
... | We bring in the dbxref identifiers and store them in a hashmap for
lookup in other functions.
Note that some dbxrefs aren't mapped to identifiers.
For example, 5004018 is mapped to a string,
"endosome & imaginal disc epithelial cell | somatic clone..."
In those cases, there j... | [
"We",
"bring",
"in",
"the",
"dbxref",
"identifiers",
"and",
"store",
"them",
"in",
"a",
"hashmap",
"for",
"lookup",
"in",
"other",
"functions",
".",
"Note",
"that",
"some",
"dbxrefs",
"aren",
"t",
"mapped",
"to",
"identifiers",
".",
"For",
"example",
"5004... | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L1033-L1103 |
18,404 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_phenotype | def _process_phenotype(self, limit):
"""
Get the phenotypes, and declare the classes.
If the "observable" is "unspecified", then we assign the phenotype to
the "cvalue" id; otherwise we convert the phenotype into a
uberpheno-style identifier, simply based on the anatomical part t... | python | def _process_phenotype(self, limit):
"""
Get the phenotypes, and declare the classes.
If the "observable" is "unspecified", then we assign the phenotype to
the "cvalue" id; otherwise we convert the phenotype into a
uberpheno-style identifier, simply based on the anatomical part t... | [
"def",
"_process_phenotype",
"(",
"self",
",",
"limit",
")",
":",
"if",
"self",
".",
"test_mode",
":",
"graph",
"=",
"self",
".",
"testgraph",
"else",
":",
"graph",
"=",
"self",
".",
"graph",
"model",
"=",
"Model",
"(",
"graph",
")",
"raw",
"=",
"'/'... | Get the phenotypes, and declare the classes.
If the "observable" is "unspecified", then we assign the phenotype to
the "cvalue" id; otherwise we convert the phenotype into a
uberpheno-style identifier, simply based on the anatomical part that's
affected...that is listed as the observable... | [
"Get",
"the",
"phenotypes",
"and",
"declare",
"the",
"classes",
".",
"If",
"the",
"observable",
"is",
"unspecified",
"then",
"we",
"assign",
"the",
"phenotype",
"to",
"the",
"cvalue",
"id",
";",
"otherwise",
"we",
"convert",
"the",
"phenotype",
"into",
"a",
... | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L1105-L1195 |
18,405 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_cvterm | def _process_cvterm(self):
"""
CVterms are the internal identifiers for any controlled vocab
or ontology term. Many are xrefd to actual ontologies. The actual
external id is stored in the dbxref table, which we place into
the internal hashmap for lookup with the cvterm id. The... | python | def _process_cvterm(self):
"""
CVterms are the internal identifiers for any controlled vocab
or ontology term. Many are xrefd to actual ontologies. The actual
external id is stored in the dbxref table, which we place into
the internal hashmap for lookup with the cvterm id. The... | [
"def",
"_process_cvterm",
"(",
"self",
")",
":",
"line_counter",
"=",
"0",
"raw",
"=",
"'/'",
".",
"join",
"(",
"(",
"self",
".",
"rawdir",
",",
"'cvterm'",
")",
")",
"LOG",
".",
"info",
"(",
"\"processing cvterms\"",
")",
"with",
"open",
"(",
"raw",
... | CVterms are the internal identifiers for any controlled vocab
or ontology term. Many are xrefd to actual ontologies. The actual
external id is stored in the dbxref table, which we place into
the internal hashmap for lookup with the cvterm id. The name of
the external term is stored in... | [
"CVterms",
"are",
"the",
"internal",
"identifiers",
"for",
"any",
"controlled",
"vocab",
"or",
"ontology",
"term",
".",
"Many",
"are",
"xrefd",
"to",
"actual",
"ontologies",
".",
"The",
"actual",
"external",
"id",
"is",
"stored",
"in",
"the",
"dbxref",
"tabl... | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L1324-L1389 |
18,406 | monarch-initiative/dipper | dipper/sources/FlyBase.py | FlyBase._process_organisms | def _process_organisms(self, limit):
"""
The internal identifiers for the organisms in flybase
:param limit:
:return:
"""
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
model = Model(graph)
raw = '/'.j... | python | def _process_organisms(self, limit):
"""
The internal identifiers for the organisms in flybase
:param limit:
:return:
"""
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
model = Model(graph)
raw = '/'.j... | [
"def",
"_process_organisms",
"(",
"self",
",",
"limit",
")",
":",
"if",
"self",
".",
"test_mode",
":",
"graph",
"=",
"self",
".",
"testgraph",
"else",
":",
"graph",
"=",
"self",
".",
"graph",
"model",
"=",
"Model",
"(",
"graph",
")",
"raw",
"=",
"'/'... | The internal identifiers for the organisms in flybase
:param limit:
:return: | [
"The",
"internal",
"identifiers",
"for",
"the",
"organisms",
"in",
"flybase"
] | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/FlyBase.py#L1792-L1844 |
18,407 | monarch-initiative/dipper | dipper/sources/NCBIGene.py | NCBIGene._add_gene_equivalencies | def _add_gene_equivalencies(self, xrefs, gene_id, taxon):
"""
Add equivalentClass and sameAs relationships
Uses external resource map located in
/resources/clique_leader.yaml to determine
if an NCBITaxon ID space is a clique leader
"""
clique_map = self.open_and... | python | def _add_gene_equivalencies(self, xrefs, gene_id, taxon):
"""
Add equivalentClass and sameAs relationships
Uses external resource map located in
/resources/clique_leader.yaml to determine
if an NCBITaxon ID space is a clique leader
"""
clique_map = self.open_and... | [
"def",
"_add_gene_equivalencies",
"(",
"self",
",",
"xrefs",
",",
"gene_id",
",",
"taxon",
")",
":",
"clique_map",
"=",
"self",
".",
"open_and_parse_yaml",
"(",
"self",
".",
"resources",
"[",
"'clique_leader'",
"]",
")",
"if",
"self",
".",
"test_mode",
":",
... | Add equivalentClass and sameAs relationships
Uses external resource map located in
/resources/clique_leader.yaml to determine
if an NCBITaxon ID space is a clique leader | [
"Add",
"equivalentClass",
"and",
"sameAs",
"relationships"
] | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/NCBIGene.py#L377-L430 |
18,408 | monarch-initiative/dipper | dipper/sources/NCBIGene.py | NCBIGene._get_gene2pubmed | def _get_gene2pubmed(self, limit):
"""
Loops through the gene2pubmed file and adds a simple triple to say
that a given publication is_about a gene.
Publications are added as NamedIndividuals.
These are filtered on the taxon.
:param limit:
:return:
"""
... | python | def _get_gene2pubmed(self, limit):
"""
Loops through the gene2pubmed file and adds a simple triple to say
that a given publication is_about a gene.
Publications are added as NamedIndividuals.
These are filtered on the taxon.
:param limit:
:return:
"""
... | [
"def",
"_get_gene2pubmed",
"(",
"self",
",",
"limit",
")",
":",
"src_key",
"=",
"'gene2pubmed'",
"if",
"self",
".",
"test_mode",
":",
"graph",
"=",
"self",
".",
"testgraph",
"else",
":",
"graph",
"=",
"self",
".",
"graph",
"model",
"=",
"Model",
"(",
"... | Loops through the gene2pubmed file and adds a simple triple to say
that a given publication is_about a gene.
Publications are added as NamedIndividuals.
These are filtered on the taxon.
:param limit:
:return: | [
"Loops",
"through",
"the",
"gene2pubmed",
"file",
"and",
"adds",
"a",
"simple",
"triple",
"to",
"say",
"that",
"a",
"given",
"publication",
"is_about",
"a",
"gene",
".",
"Publications",
"are",
"added",
"as",
"NamedIndividuals",
"."
] | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/NCBIGene.py#L516-L598 |
18,409 | monarch-initiative/dipper | dipper/sources/OMIM.py | OMIM.process_entries | def process_entries(
self, omimids, transform, included_fields=None, graph=None, limit=None,
globaltt=None
):
"""
Given a list of omim ids,
this will use the omim API to fetch the entries, according to the
```included_fields``` passed as a parameter.
I... | python | def process_entries(
self, omimids, transform, included_fields=None, graph=None, limit=None,
globaltt=None
):
"""
Given a list of omim ids,
this will use the omim API to fetch the entries, according to the
```included_fields``` passed as a parameter.
I... | [
"def",
"process_entries",
"(",
"self",
",",
"omimids",
",",
"transform",
",",
"included_fields",
"=",
"None",
",",
"graph",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"globaltt",
"=",
"None",
")",
":",
"omimparams",
"=",
"{",
"}",
"# add the included_fie... | Given a list of omim ids,
this will use the omim API to fetch the entries, according to the
```included_fields``` passed as a parameter.
If a transformation function is supplied,
this will iterate over each entry,
and either add the results to the supplied ```graph```
or ... | [
"Given",
"a",
"list",
"of",
"omim",
"ids",
"this",
"will",
"use",
"the",
"omim",
"API",
"to",
"fetch",
"the",
"entries",
"according",
"to",
"the",
"included_fields",
"passed",
"as",
"a",
"parameter",
".",
"If",
"a",
"transformation",
"function",
"is",
"sup... | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/OMIM.py#L253-L367 |
18,410 | monarch-initiative/dipper | dipper/sources/OMIM.py | OMIM._process_all | def _process_all(self, limit):
"""
This takes the list of omim identifiers from the omim.txt.Z file,
and iteratively queries the omim api for the json-formatted data.
This will create OMIM classes, with the label,
definition, and some synonyms.
If an entry is "removed",
... | python | def _process_all(self, limit):
"""
This takes the list of omim identifiers from the omim.txt.Z file,
and iteratively queries the omim api for the json-formatted data.
This will create OMIM classes, with the label,
definition, and some synonyms.
If an entry is "removed",
... | [
"def",
"_process_all",
"(",
"self",
",",
"limit",
")",
":",
"omimids",
"=",
"self",
".",
"_get_omim_ids",
"(",
")",
"LOG",
".",
"info",
"(",
"'Have %i omim numbers to fetch records from their API'",
",",
"len",
"(",
"omimids",
")",
")",
"LOG",
".",
"info",
"... | This takes the list of omim identifiers from the omim.txt.Z file,
and iteratively queries the omim api for the json-formatted data.
This will create OMIM classes, with the label,
definition, and some synonyms.
If an entry is "removed",
it is added as a deprecated class.
... | [
"This",
"takes",
"the",
"list",
"of",
"omim",
"identifiers",
"from",
"the",
"omim",
".",
"txt",
".",
"Z",
"file",
"and",
"iteratively",
"queries",
"the",
"omim",
"api",
"for",
"the",
"json",
"-",
"formatted",
"data",
".",
"This",
"will",
"create",
"OMIM"... | 24cc80db355bbe15776edc5c7b41e0886959ba41 | https://github.com/monarch-initiative/dipper/blob/24cc80db355bbe15776edc5c7b41e0886959ba41/dipper/sources/OMIM.py#L369-L412 |
18,411 | ethereum/py-trie | trie/smt.py | SparseMerkleProof.update | def update(self, key: bytes, value: bytes, node_updates: Sequence[Hash32]):
"""
Merge an update for another key with the one we are tracking internally.
:param key: keypath of the update we are processing
:param value: value of the update we are processing
:param node_updates: s... | python | def update(self, key: bytes, value: bytes, node_updates: Sequence[Hash32]):
"""
Merge an update for another key with the one we are tracking internally.
:param key: keypath of the update we are processing
:param value: value of the update we are processing
:param node_updates: s... | [
"def",
"update",
"(",
"self",
",",
"key",
":",
"bytes",
",",
"value",
":",
"bytes",
",",
"node_updates",
":",
"Sequence",
"[",
"Hash32",
"]",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"validate_length",
"(",
"key",
",",
"self",
".",
"_key_size",
... | Merge an update for another key with the one we are tracking internally.
:param key: keypath of the update we are processing
:param value: value of the update we are processing
:param node_updates: sequence of sibling nodes (in root->leaf order)
must be at least as ... | [
"Merge",
"an",
"update",
"for",
"another",
"key",
"with",
"the",
"one",
"we",
"are",
"tracking",
"internally",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/smt.py#L144-L186 |
18,412 | ethereum/py-trie | trie/smt.py | SparseMerkleTree._get | def _get(self, key: bytes) -> Tuple[bytes, Tuple[Hash32]]:
"""
Returns db value and branch in root->leaf order
"""
validate_is_bytes(key)
validate_length(key, self._key_size)
branch = []
target_bit = 1 << (self.depth - 1)
path = to_int(key)
node_h... | python | def _get(self, key: bytes) -> Tuple[bytes, Tuple[Hash32]]:
"""
Returns db value and branch in root->leaf order
"""
validate_is_bytes(key)
validate_length(key, self._key_size)
branch = []
target_bit = 1 << (self.depth - 1)
path = to_int(key)
node_h... | [
"def",
"_get",
"(",
"self",
",",
"key",
":",
"bytes",
")",
"->",
"Tuple",
"[",
"bytes",
",",
"Tuple",
"[",
"Hash32",
"]",
"]",
":",
"validate_is_bytes",
"(",
"key",
")",
"validate_length",
"(",
"key",
",",
"self",
".",
"_key_size",
")",
"branch",
"="... | Returns db value and branch in root->leaf order | [
"Returns",
"db",
"value",
"and",
"branch",
"in",
"root",
"-",
">",
"leaf",
"order"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/smt.py#L271-L297 |
18,413 | ethereum/py-trie | trie/smt.py | SparseMerkleTree.set | def set(self, key: bytes, value: bytes) -> Tuple[Hash32]:
"""
Returns all updated hashes in root->leaf order
"""
validate_is_bytes(key)
validate_length(key, self._key_size)
validate_is_bytes(value)
path = to_int(key)
node = value
_, branch = self.... | python | def set(self, key: bytes, value: bytes) -> Tuple[Hash32]:
"""
Returns all updated hashes in root->leaf order
"""
validate_is_bytes(key)
validate_length(key, self._key_size)
validate_is_bytes(value)
path = to_int(key)
node = value
_, branch = self.... | [
"def",
"set",
"(",
"self",
",",
"key",
":",
"bytes",
",",
"value",
":",
"bytes",
")",
"->",
"Tuple",
"[",
"Hash32",
"]",
":",
"validate_is_bytes",
"(",
"key",
")",
"validate_length",
"(",
"key",
",",
"self",
".",
"_key_size",
")",
"validate_is_bytes",
... | Returns all updated hashes in root->leaf order | [
"Returns",
"all",
"updated",
"hashes",
"in",
"root",
"-",
">",
"leaf",
"order"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/smt.py#L299-L333 |
18,414 | ethereum/py-trie | trie/smt.py | SparseMerkleTree.delete | def delete(self, key: bytes) -> Tuple[Hash32]:
"""
Equals to setting the value to None
Returns all updated hashes in root->leaf order
"""
validate_is_bytes(key)
validate_length(key, self._key_size)
return self.set(key, self._default) | python | def delete(self, key: bytes) -> Tuple[Hash32]:
"""
Equals to setting the value to None
Returns all updated hashes in root->leaf order
"""
validate_is_bytes(key)
validate_length(key, self._key_size)
return self.set(key, self._default) | [
"def",
"delete",
"(",
"self",
",",
"key",
":",
"bytes",
")",
"->",
"Tuple",
"[",
"Hash32",
"]",
":",
"validate_is_bytes",
"(",
"key",
")",
"validate_length",
"(",
"key",
",",
"self",
".",
"_key_size",
")",
"return",
"self",
".",
"set",
"(",
"key",
",... | Equals to setting the value to None
Returns all updated hashes in root->leaf order | [
"Equals",
"to",
"setting",
"the",
"value",
"to",
"None",
"Returns",
"all",
"updated",
"hashes",
"in",
"root",
"-",
">",
"leaf",
"order"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/smt.py#L345-L353 |
18,415 | ethereum/py-trie | trie/sync.py | HexaryTrieSync.next_batch | def next_batch(self, n=1):
"""Return the next requests that should be dispatched."""
if len(self.queue) == 0:
return []
batch = list(reversed((self.queue[-n:])))
self.queue = self.queue[:-n]
return batch | python | def next_batch(self, n=1):
"""Return the next requests that should be dispatched."""
if len(self.queue) == 0:
return []
batch = list(reversed((self.queue[-n:])))
self.queue = self.queue[:-n]
return batch | [
"def",
"next_batch",
"(",
"self",
",",
"n",
"=",
"1",
")",
":",
"if",
"len",
"(",
"self",
".",
"queue",
")",
"==",
"0",
":",
"return",
"[",
"]",
"batch",
"=",
"list",
"(",
"reversed",
"(",
"(",
"self",
".",
"queue",
"[",
"-",
"n",
":",
"]",
... | Return the next requests that should be dispatched. | [
"Return",
"the",
"next",
"requests",
"that",
"should",
"be",
"dispatched",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/sync.py#L120-L126 |
18,416 | ethereum/py-trie | trie/sync.py | HexaryTrieSync.schedule | def schedule(self, node_key, parent, depth, leaf_callback, is_raw=False):
"""Schedule a request for the node with the given key."""
if node_key in self._existing_nodes:
self.logger.debug("Node %s already exists in db" % encode_hex(node_key))
return
if node_key in self.db... | python | def schedule(self, node_key, parent, depth, leaf_callback, is_raw=False):
"""Schedule a request for the node with the given key."""
if node_key in self._existing_nodes:
self.logger.debug("Node %s already exists in db" % encode_hex(node_key))
return
if node_key in self.db... | [
"def",
"schedule",
"(",
"self",
",",
"node_key",
",",
"parent",
",",
"depth",
",",
"leaf_callback",
",",
"is_raw",
"=",
"False",
")",
":",
"if",
"node_key",
"in",
"self",
".",
"_existing_nodes",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"Node %s a... | Schedule a request for the node with the given key. | [
"Schedule",
"a",
"request",
"for",
"the",
"node",
"with",
"the",
"given",
"key",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/sync.py#L128-L155 |
18,417 | ethereum/py-trie | trie/sync.py | HexaryTrieSync.get_children | def get_children(self, request):
"""Return all children of the node retrieved by the given request.
:rtype: A two-tuple with one list containing the children that reference other nodes and
another containing the leaf children.
"""
node = decode_node(request.data)
return ... | python | def get_children(self, request):
"""Return all children of the node retrieved by the given request.
:rtype: A two-tuple with one list containing the children that reference other nodes and
another containing the leaf children.
"""
node = decode_node(request.data)
return ... | [
"def",
"get_children",
"(",
"self",
",",
"request",
")",
":",
"node",
"=",
"decode_node",
"(",
"request",
".",
"data",
")",
"return",
"_get_children",
"(",
"node",
",",
"request",
".",
"depth",
")"
] | Return all children of the node retrieved by the given request.
:rtype: A two-tuple with one list containing the children that reference other nodes and
another containing the leaf children. | [
"Return",
"all",
"children",
"of",
"the",
"node",
"retrieved",
"by",
"the",
"given",
"request",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/sync.py#L157-L164 |
18,418 | ethereum/py-trie | trie/sync.py | HexaryTrieSync.process | def process(self, results):
"""Process request results.
:param results: A list of two-tuples containing the node's key and data.
"""
for node_key, data in results:
request = self.requests.get(node_key)
if request is None:
# This may happen if we r... | python | def process(self, results):
"""Process request results.
:param results: A list of two-tuples containing the node's key and data.
"""
for node_key, data in results:
request = self.requests.get(node_key)
if request is None:
# This may happen if we r... | [
"def",
"process",
"(",
"self",
",",
"results",
")",
":",
"for",
"node_key",
",",
"data",
"in",
"results",
":",
"request",
"=",
"self",
".",
"requests",
".",
"get",
"(",
"node_key",
")",
"if",
"request",
"is",
"None",
":",
"# This may happen if we resend a ... | Process request results.
:param results: A list of two-tuples containing the node's key and data. | [
"Process",
"request",
"results",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/sync.py#L166-L199 |
18,419 | ethereum/py-trie | trie/branches.py | check_if_branch_exist | def check_if_branch_exist(db, root_hash, key_prefix):
"""
Given a key prefix, return whether this prefix is
the prefix of an existing key in the trie.
"""
validate_is_bytes(key_prefix)
return _check_if_branch_exist(db, root_hash, encode_to_bin(key_prefix)) | python | def check_if_branch_exist(db, root_hash, key_prefix):
"""
Given a key prefix, return whether this prefix is
the prefix of an existing key in the trie.
"""
validate_is_bytes(key_prefix)
return _check_if_branch_exist(db, root_hash, encode_to_bin(key_prefix)) | [
"def",
"check_if_branch_exist",
"(",
"db",
",",
"root_hash",
",",
"key_prefix",
")",
":",
"validate_is_bytes",
"(",
"key_prefix",
")",
"return",
"_check_if_branch_exist",
"(",
"db",
",",
"root_hash",
",",
"encode_to_bin",
"(",
"key_prefix",
")",
")"
] | Given a key prefix, return whether this prefix is
the prefix of an existing key in the trie. | [
"Given",
"a",
"key",
"prefix",
"return",
"whether",
"this",
"prefix",
"is",
"the",
"prefix",
"of",
"an",
"existing",
"key",
"in",
"the",
"trie",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/branches.py#L30-L37 |
18,420 | ethereum/py-trie | trie/branches.py | get_branch | def get_branch(db, root_hash, key):
"""
Get a long-format Merkle branch
"""
validate_is_bytes(key)
return tuple(_get_branch(db, root_hash, encode_to_bin(key))) | python | def get_branch(db, root_hash, key):
"""
Get a long-format Merkle branch
"""
validate_is_bytes(key)
return tuple(_get_branch(db, root_hash, encode_to_bin(key))) | [
"def",
"get_branch",
"(",
"db",
",",
"root_hash",
",",
"key",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"return",
"tuple",
"(",
"_get_branch",
"(",
"db",
",",
"root_hash",
",",
"encode_to_bin",
"(",
"key",
")",
")",
")"
] | Get a long-format Merkle branch | [
"Get",
"a",
"long",
"-",
"format",
"Merkle",
"branch"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/branches.py#L71-L77 |
18,421 | ethereum/py-trie | trie/branches.py | get_witness_for_key_prefix | def get_witness_for_key_prefix(db, node_hash, key):
"""
Get all witness given a keypath prefix.
Include
1. witness along the keypath and
2. witness in the subtrie of the last node in keypath
"""
validate_is_bytes(key)
return tuple(_get_witness_for_key_prefix(db, node_hash, encode_to_bi... | python | def get_witness_for_key_prefix(db, node_hash, key):
"""
Get all witness given a keypath prefix.
Include
1. witness along the keypath and
2. witness in the subtrie of the last node in keypath
"""
validate_is_bytes(key)
return tuple(_get_witness_for_key_prefix(db, node_hash, encode_to_bi... | [
"def",
"get_witness_for_key_prefix",
"(",
"db",
",",
"node_hash",
",",
"key",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"return",
"tuple",
"(",
"_get_witness_for_key_prefix",
"(",
"db",
",",
"node_hash",
",",
"encode_to_bin",
"(",
"key",
")",
")",
")"
] | Get all witness given a keypath prefix.
Include
1. witness along the keypath and
2. witness in the subtrie of the last node in keypath | [
"Get",
"all",
"witness",
"given",
"a",
"keypath",
"prefix",
".",
"Include"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/branches.py#L155-L165 |
18,422 | ethereum/py-trie | trie/utils/nodes.py | encode_branch_node | def encode_branch_node(left_child_node_hash, right_child_node_hash):
"""
Serializes a branch node
"""
validate_is_bytes(left_child_node_hash)
validate_length(left_child_node_hash, 32)
validate_is_bytes(right_child_node_hash)
validate_length(right_child_node_hash, 32)
return BRANCH_TYPE_P... | python | def encode_branch_node(left_child_node_hash, right_child_node_hash):
"""
Serializes a branch node
"""
validate_is_bytes(left_child_node_hash)
validate_length(left_child_node_hash, 32)
validate_is_bytes(right_child_node_hash)
validate_length(right_child_node_hash, 32)
return BRANCH_TYPE_P... | [
"def",
"encode_branch_node",
"(",
"left_child_node_hash",
",",
"right_child_node_hash",
")",
":",
"validate_is_bytes",
"(",
"left_child_node_hash",
")",
"validate_length",
"(",
"left_child_node_hash",
",",
"32",
")",
"validate_is_bytes",
"(",
"right_child_node_hash",
")",
... | Serializes a branch node | [
"Serializes",
"a",
"branch",
"node"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/nodes.py#L157-L165 |
18,423 | ethereum/py-trie | trie/utils/nodes.py | encode_leaf_node | def encode_leaf_node(value):
"""
Serializes a leaf node
"""
validate_is_bytes(value)
if value is None or value == b'':
raise ValidationError("Value of leaf node can not be empty")
return LEAF_TYPE_PREFIX + value | python | def encode_leaf_node(value):
"""
Serializes a leaf node
"""
validate_is_bytes(value)
if value is None or value == b'':
raise ValidationError("Value of leaf node can not be empty")
return LEAF_TYPE_PREFIX + value | [
"def",
"encode_leaf_node",
"(",
"value",
")",
":",
"validate_is_bytes",
"(",
"value",
")",
"if",
"value",
"is",
"None",
"or",
"value",
"==",
"b''",
":",
"raise",
"ValidationError",
"(",
"\"Value of leaf node can not be empty\"",
")",
"return",
"LEAF_TYPE_PREFIX",
... | Serializes a leaf node | [
"Serializes",
"a",
"leaf",
"node"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/nodes.py#L168-L175 |
18,424 | ethereum/py-trie | trie/utils/db.py | ScratchDB.batch_commit | def batch_commit(self, *, do_deletes=False):
'''
Batch and commit and end of context
'''
try:
yield
except Exception as exc:
raise exc
else:
for key, value in self.cache.items():
if value is not DELETED:
... | python | def batch_commit(self, *, do_deletes=False):
'''
Batch and commit and end of context
'''
try:
yield
except Exception as exc:
raise exc
else:
for key, value in self.cache.items():
if value is not DELETED:
... | [
"def",
"batch_commit",
"(",
"self",
",",
"*",
",",
"do_deletes",
"=",
"False",
")",
":",
"try",
":",
"yield",
"except",
"Exception",
"as",
"exc",
":",
"raise",
"exc",
"else",
":",
"for",
"key",
",",
"value",
"in",
"self",
".",
"cache",
".",
"items",
... | Batch and commit and end of context | [
"Batch",
"and",
"commit",
"and",
"end",
"of",
"context"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/db.py#L48-L64 |
18,425 | ethereum/py-trie | trie/hexary.py | HexaryTrie._prune_node | def _prune_node(self, node):
"""
Prune the given node if context exits cleanly.
"""
if self.is_pruning:
# node is mutable, so capture the key for later pruning now
prune_key, node_body = self._node_to_db_mapping(node)
should_prune = (node_body is not N... | python | def _prune_node(self, node):
"""
Prune the given node if context exits cleanly.
"""
if self.is_pruning:
# node is mutable, so capture the key for later pruning now
prune_key, node_body = self._node_to_db_mapping(node)
should_prune = (node_body is not N... | [
"def",
"_prune_node",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"is_pruning",
":",
"# node is mutable, so capture the key for later pruning now",
"prune_key",
",",
"node_body",
"=",
"self",
".",
"_node_to_db_mapping",
"(",
"node",
")",
"should_prune",
"... | Prune the given node if context exits cleanly. | [
"Prune",
"the",
"given",
"node",
"if",
"context",
"exits",
"cleanly",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/hexary.py#L231-L246 |
18,426 | ethereum/py-trie | trie/hexary.py | HexaryTrie._normalize_branch_node | def _normalize_branch_node(self, node):
"""
A branch node which is left with only a single non-blank item should be
turned into either a leaf or extension node.
"""
iter_node = iter(node)
if any(iter_node) and any(iter_node):
return node
if node[16]:
... | python | def _normalize_branch_node(self, node):
"""
A branch node which is left with only a single non-blank item should be
turned into either a leaf or extension node.
"""
iter_node = iter(node)
if any(iter_node) and any(iter_node):
return node
if node[16]:
... | [
"def",
"_normalize_branch_node",
"(",
"self",
",",
"node",
")",
":",
"iter_node",
"=",
"iter",
"(",
"node",
")",
"if",
"any",
"(",
"iter_node",
")",
"and",
"any",
"(",
"iter_node",
")",
":",
"return",
"node",
"if",
"node",
"[",
"16",
"]",
":",
"retur... | A branch node which is left with only a single non-blank item should be
turned into either a leaf or extension node. | [
"A",
"branch",
"node",
"which",
"is",
"left",
"with",
"only",
"a",
"single",
"non",
"-",
"blank",
"item",
"should",
"be",
"turned",
"into",
"either",
"a",
"leaf",
"or",
"extension",
"node",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/hexary.py#L324-L356 |
18,427 | ethereum/py-trie | trie/hexary.py | HexaryTrie._delete_branch_node | def _delete_branch_node(self, node, trie_key):
"""
Delete a key from inside or underneath a branch node
"""
if not trie_key:
node[-1] = BLANK_NODE
return self._normalize_branch_node(node)
node_to_delete = self.get_node(node[trie_key[0]])
sub_node... | python | def _delete_branch_node(self, node, trie_key):
"""
Delete a key from inside or underneath a branch node
"""
if not trie_key:
node[-1] = BLANK_NODE
return self._normalize_branch_node(node)
node_to_delete = self.get_node(node[trie_key[0]])
sub_node... | [
"def",
"_delete_branch_node",
"(",
"self",
",",
"node",
",",
"trie_key",
")",
":",
"if",
"not",
"trie_key",
":",
"node",
"[",
"-",
"1",
"]",
"=",
"BLANK_NODE",
"return",
"self",
".",
"_normalize_branch_node",
"(",
"node",
")",
"node_to_delete",
"=",
"self"... | Delete a key from inside or underneath a branch node | [
"Delete",
"a",
"key",
"from",
"inside",
"or",
"underneath",
"a",
"branch",
"node"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/hexary.py#L361-L381 |
18,428 | ethereum/py-trie | trie/binary.py | BinaryTrie.get | def get(self, key):
"""
Fetches the value with a given keypath from the given node.
Key will be encoded into binary array format first.
"""
validate_is_bytes(key)
return self._get(self.root_hash, encode_to_bin(key)) | python | def get(self, key):
"""
Fetches the value with a given keypath from the given node.
Key will be encoded into binary array format first.
"""
validate_is_bytes(key)
return self._get(self.root_hash, encode_to_bin(key)) | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"return",
"self",
".",
"_get",
"(",
"self",
".",
"root_hash",
",",
"encode_to_bin",
"(",
"key",
")",
")"
] | Fetches the value with a given keypath from the given node.
Key will be encoded into binary array format first. | [
"Fetches",
"the",
"value",
"with",
"a",
"given",
"keypath",
"from",
"the",
"given",
"node",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/binary.py#L38-L46 |
18,429 | ethereum/py-trie | trie/binary.py | BinaryTrie.set | def set(self, key, value):
"""
Sets the value at the given keypath from the given node
Key will be encoded into binary array format first.
"""
validate_is_bytes(key)
validate_is_bytes(value)
self.root_hash = self._set(self.root_hash, encode_to_bin(key), value) | python | def set(self, key, value):
"""
Sets the value at the given keypath from the given node
Key will be encoded into binary array format first.
"""
validate_is_bytes(key)
validate_is_bytes(value)
self.root_hash = self._set(self.root_hash, encode_to_bin(key), value) | [
"def",
"set",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"validate_is_bytes",
"(",
"value",
")",
"self",
".",
"root_hash",
"=",
"self",
".",
"_set",
"(",
"self",
".",
"root_hash",
",",
"encode_to_bin",
"(",
"... | Sets the value at the given keypath from the given node
Key will be encoded into binary array format first. | [
"Sets",
"the",
"value",
"at",
"the",
"given",
"keypath",
"from",
"the",
"given",
"node"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/binary.py#L79-L88 |
18,430 | ethereum/py-trie | trie/binary.py | BinaryTrie._set | def _set(self, node_hash, keypath, value, if_delete_subtrie=False):
"""
If if_delete_subtrie is set to True, what it will do is that it take in a keypath
and traverse til the end of keypath, then delete the whole subtrie of that node.
Note: keypath should be in binary array format, i.e.... | python | def _set(self, node_hash, keypath, value, if_delete_subtrie=False):
"""
If if_delete_subtrie is set to True, what it will do is that it take in a keypath
and traverse til the end of keypath, then delete the whole subtrie of that node.
Note: keypath should be in binary array format, i.e.... | [
"def",
"_set",
"(",
"self",
",",
"node_hash",
",",
"keypath",
",",
"value",
",",
"if_delete_subtrie",
"=",
"False",
")",
":",
"# Empty trie",
"if",
"node_hash",
"==",
"BLANK_HASH",
":",
"if",
"value",
":",
"return",
"self",
".",
"_hash_and_save",
"(",
"enc... | If if_delete_subtrie is set to True, what it will do is that it take in a keypath
and traverse til the end of keypath, then delete the whole subtrie of that node.
Note: keypath should be in binary array format, i.e., encoded by encode_to_bin() | [
"If",
"if_delete_subtrie",
"is",
"set",
"to",
"True",
"what",
"it",
"will",
"do",
"is",
"that",
"it",
"take",
"in",
"a",
"keypath",
"and",
"traverse",
"til",
"the",
"end",
"of",
"keypath",
"then",
"delete",
"the",
"whole",
"subtrie",
"of",
"that",
"node"... | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/binary.py#L90-L153 |
18,431 | ethereum/py-trie | trie/binary.py | BinaryTrie.delete | def delete(self, key):
"""
Equals to setting the value to None
"""
validate_is_bytes(key)
self.root_hash = self._set(self.root_hash, encode_to_bin(key), b'') | python | def delete(self, key):
"""
Equals to setting the value to None
"""
validate_is_bytes(key)
self.root_hash = self._set(self.root_hash, encode_to_bin(key), b'') | [
"def",
"delete",
"(",
"self",
",",
"key",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"self",
".",
"root_hash",
"=",
"self",
".",
"_set",
"(",
"self",
".",
"root_hash",
",",
"encode_to_bin",
"(",
"key",
")",
",",
"b''",
")"
] | Equals to setting the value to None | [
"Equals",
"to",
"setting",
"the",
"value",
"to",
"None"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/binary.py#L297-L303 |
18,432 | ethereum/py-trie | trie/binary.py | BinaryTrie.delete_subtrie | def delete_subtrie(self, key):
"""
Given a key prefix, delete the whole subtrie that starts with the key prefix.
Key will be encoded into binary array format first.
It will call `_set` with `if_delete_subtrie` set to True.
"""
validate_is_bytes(key)
self.root_h... | python | def delete_subtrie(self, key):
"""
Given a key prefix, delete the whole subtrie that starts with the key prefix.
Key will be encoded into binary array format first.
It will call `_set` with `if_delete_subtrie` set to True.
"""
validate_is_bytes(key)
self.root_h... | [
"def",
"delete_subtrie",
"(",
"self",
",",
"key",
")",
":",
"validate_is_bytes",
"(",
"key",
")",
"self",
".",
"root_hash",
"=",
"self",
".",
"_set",
"(",
"self",
".",
"root_hash",
",",
"encode_to_bin",
"(",
"key",
")",
",",
"value",
"=",
"b''",
",",
... | Given a key prefix, delete the whole subtrie that starts with the key prefix.
Key will be encoded into binary array format first.
It will call `_set` with `if_delete_subtrie` set to True. | [
"Given",
"a",
"key",
"prefix",
"delete",
"the",
"whole",
"subtrie",
"that",
"starts",
"with",
"the",
"key",
"prefix",
"."
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/binary.py#L305-L320 |
18,433 | ethereum/py-trie | trie/binary.py | BinaryTrie._hash_and_save | def _hash_and_save(self, node):
"""
Saves a node into the database and returns its hash
"""
validate_is_bin_node(node)
node_hash = keccak(node)
self.db[node_hash] = node
return node_hash | python | def _hash_and_save(self, node):
"""
Saves a node into the database and returns its hash
"""
validate_is_bin_node(node)
node_hash = keccak(node)
self.db[node_hash] = node
return node_hash | [
"def",
"_hash_and_save",
"(",
"self",
",",
"node",
")",
":",
"validate_is_bin_node",
"(",
"node",
")",
"node_hash",
"=",
"keccak",
"(",
"node",
")",
"self",
".",
"db",
"[",
"node_hash",
"]",
"=",
"node",
"return",
"node_hash"
] | Saves a node into the database and returns its hash | [
"Saves",
"a",
"node",
"into",
"the",
"database",
"and",
"returns",
"its",
"hash"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/binary.py#L338-L346 |
18,434 | ethereum/py-trie | trie/utils/binaries.py | decode_from_bin | def decode_from_bin(input_bin):
"""
0100000101010111010000110100100101001001 -> ASCII
"""
for chunk in partition_all(8, input_bin):
yield sum(
2**exp * bit
for exp, bit
in enumerate(reversed(chunk))
) | python | def decode_from_bin(input_bin):
"""
0100000101010111010000110100100101001001 -> ASCII
"""
for chunk in partition_all(8, input_bin):
yield sum(
2**exp * bit
for exp, bit
in enumerate(reversed(chunk))
) | [
"def",
"decode_from_bin",
"(",
"input_bin",
")",
":",
"for",
"chunk",
"in",
"partition_all",
"(",
"8",
",",
"input_bin",
")",
":",
"yield",
"sum",
"(",
"2",
"**",
"exp",
"*",
"bit",
"for",
"exp",
",",
"bit",
"in",
"enumerate",
"(",
"reversed",
"(",
"... | 0100000101010111010000110100100101001001 -> ASCII | [
"0100000101010111010000110100100101001001",
"-",
">",
"ASCII"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/binaries.py#L18-L27 |
18,435 | ethereum/py-trie | trie/utils/binaries.py | encode_to_bin | def encode_to_bin(value):
"""
ASCII -> 0100000101010111010000110100100101001001
"""
for char in value:
for exp in EXP:
if char & exp:
yield True
else:
yield False | python | def encode_to_bin(value):
"""
ASCII -> 0100000101010111010000110100100101001001
"""
for char in value:
for exp in EXP:
if char & exp:
yield True
else:
yield False | [
"def",
"encode_to_bin",
"(",
"value",
")",
":",
"for",
"char",
"in",
"value",
":",
"for",
"exp",
"in",
"EXP",
":",
"if",
"char",
"&",
"exp",
":",
"yield",
"True",
"else",
":",
"yield",
"False"
] | ASCII -> 0100000101010111010000110100100101001001 | [
"ASCII",
"-",
">",
"0100000101010111010000110100100101001001"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/binaries.py#L31-L40 |
18,436 | ethereum/py-trie | trie/utils/binaries.py | encode_from_bin_keypath | def encode_from_bin_keypath(input_bin):
"""
Encodes a sequence of 0s and 1s into tightly packed bytes
Used in encoding key path of a KV-NODE
"""
padded_bin = bytes((4 - len(input_bin)) % 4) + input_bin
prefix = TWO_BITS[len(input_bin) % 4]
if len(padded_bin) % 8 == 4:
return decode_f... | python | def encode_from_bin_keypath(input_bin):
"""
Encodes a sequence of 0s and 1s into tightly packed bytes
Used in encoding key path of a KV-NODE
"""
padded_bin = bytes((4 - len(input_bin)) % 4) + input_bin
prefix = TWO_BITS[len(input_bin) % 4]
if len(padded_bin) % 8 == 4:
return decode_f... | [
"def",
"encode_from_bin_keypath",
"(",
"input_bin",
")",
":",
"padded_bin",
"=",
"bytes",
"(",
"(",
"4",
"-",
"len",
"(",
"input_bin",
")",
")",
"%",
"4",
")",
"+",
"input_bin",
"prefix",
"=",
"TWO_BITS",
"[",
"len",
"(",
"input_bin",
")",
"%",
"4",
... | Encodes a sequence of 0s and 1s into tightly packed bytes
Used in encoding key path of a KV-NODE | [
"Encodes",
"a",
"sequence",
"of",
"0s",
"and",
"1s",
"into",
"tightly",
"packed",
"bytes",
"Used",
"in",
"encoding",
"key",
"path",
"of",
"a",
"KV",
"-",
"NODE"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/binaries.py#L43-L53 |
18,437 | ethereum/py-trie | trie/utils/binaries.py | decode_to_bin_keypath | def decode_to_bin_keypath(path):
"""
Decodes bytes into a sequence of 0s and 1s
Used in decoding key path of a KV-NODE
"""
path = encode_to_bin(path)
if path[0] == 1:
path = path[4:]
assert path[0:2] == PREFIX_00
padded_len = TWO_BITS.index(path[2:4])
return path[4+((4 - padd... | python | def decode_to_bin_keypath(path):
"""
Decodes bytes into a sequence of 0s and 1s
Used in decoding key path of a KV-NODE
"""
path = encode_to_bin(path)
if path[0] == 1:
path = path[4:]
assert path[0:2] == PREFIX_00
padded_len = TWO_BITS.index(path[2:4])
return path[4+((4 - padd... | [
"def",
"decode_to_bin_keypath",
"(",
"path",
")",
":",
"path",
"=",
"encode_to_bin",
"(",
"path",
")",
"if",
"path",
"[",
"0",
"]",
"==",
"1",
":",
"path",
"=",
"path",
"[",
"4",
":",
"]",
"assert",
"path",
"[",
"0",
":",
"2",
"]",
"==",
"PREFIX_... | Decodes bytes into a sequence of 0s and 1s
Used in decoding key path of a KV-NODE | [
"Decodes",
"bytes",
"into",
"a",
"sequence",
"of",
"0s",
"and",
"1s",
"Used",
"in",
"decoding",
"key",
"path",
"of",
"a",
"KV",
"-",
"NODE"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/binaries.py#L56-L66 |
18,438 | ethereum/py-trie | trie/utils/nibbles.py | encode_nibbles | def encode_nibbles(nibbles):
"""
The Hex Prefix function
"""
if is_nibbles_terminated(nibbles):
flag = HP_FLAG_2
else:
flag = HP_FLAG_0
raw_nibbles = remove_nibbles_terminator(nibbles)
is_odd = len(raw_nibbles) % 2
if is_odd:
flagged_nibbles = tuple(itertools.c... | python | def encode_nibbles(nibbles):
"""
The Hex Prefix function
"""
if is_nibbles_terminated(nibbles):
flag = HP_FLAG_2
else:
flag = HP_FLAG_0
raw_nibbles = remove_nibbles_terminator(nibbles)
is_odd = len(raw_nibbles) % 2
if is_odd:
flagged_nibbles = tuple(itertools.c... | [
"def",
"encode_nibbles",
"(",
"nibbles",
")",
":",
"if",
"is_nibbles_terminated",
"(",
"nibbles",
")",
":",
"flag",
"=",
"HP_FLAG_2",
"else",
":",
"flag",
"=",
"HP_FLAG_0",
"raw_nibbles",
"=",
"remove_nibbles_terminator",
"(",
"nibbles",
")",
"is_odd",
"=",
"l... | The Hex Prefix function | [
"The",
"Hex",
"Prefix",
"function"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/nibbles.py#L78-L104 |
18,439 | ethereum/py-trie | trie/utils/nibbles.py | decode_nibbles | def decode_nibbles(value):
"""
The inverse of the Hex Prefix function
"""
nibbles_with_flag = bytes_to_nibbles(value)
flag = nibbles_with_flag[0]
needs_terminator = flag in {HP_FLAG_2, HP_FLAG_2 + 1}
is_odd_length = flag in {HP_FLAG_0 + 1, HP_FLAG_2 + 1}
if is_odd_length:
raw_n... | python | def decode_nibbles(value):
"""
The inverse of the Hex Prefix function
"""
nibbles_with_flag = bytes_to_nibbles(value)
flag = nibbles_with_flag[0]
needs_terminator = flag in {HP_FLAG_2, HP_FLAG_2 + 1}
is_odd_length = flag in {HP_FLAG_0 + 1, HP_FLAG_2 + 1}
if is_odd_length:
raw_n... | [
"def",
"decode_nibbles",
"(",
"value",
")",
":",
"nibbles_with_flag",
"=",
"bytes_to_nibbles",
"(",
"value",
")",
"flag",
"=",
"nibbles_with_flag",
"[",
"0",
"]",
"needs_terminator",
"=",
"flag",
"in",
"{",
"HP_FLAG_2",
",",
"HP_FLAG_2",
"+",
"1",
"}",
"is_o... | The inverse of the Hex Prefix function | [
"The",
"inverse",
"of",
"the",
"Hex",
"Prefix",
"function"
] | d33108d21b54d59ee311f61d978496c84a6f1f8b | https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/nibbles.py#L107-L127 |
18,440 | neon-jungle/wagtailvideos | wagtailvideos/models.py | get_local_file | def get_local_file(file):
"""
Get a local version of the file, downloading it from the remote storage if
required. The returned value should be used as a context manager to
ensure any temporary files are cleaned up afterwards.
"""
try:
with open(file.path):
yield file.path
... | python | def get_local_file(file):
"""
Get a local version of the file, downloading it from the remote storage if
required. The returned value should be used as a context manager to
ensure any temporary files are cleaned up afterwards.
"""
try:
with open(file.path):
yield file.path
... | [
"def",
"get_local_file",
"(",
"file",
")",
":",
"try",
":",
"with",
"open",
"(",
"file",
".",
"path",
")",
":",
"yield",
"file",
".",
"path",
"except",
"NotImplementedError",
":",
"_",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"file",... | Get a local version of the file, downloading it from the remote storage if
required. The returned value should be used as a context manager to
ensure any temporary files are cleaned up afterwards. | [
"Get",
"a",
"local",
"version",
"of",
"the",
"file",
"downloading",
"it",
"from",
"the",
"remote",
"storage",
"if",
"required",
".",
"The",
"returned",
"value",
"should",
"be",
"used",
"as",
"a",
"context",
"manager",
"to",
"ensure",
"any",
"temporary",
"f... | 05a43571ac4b5e7cf07fbb89e804e53447b699c2 | https://github.com/neon-jungle/wagtailvideos/blob/05a43571ac4b5e7cf07fbb89e804e53447b699c2/wagtailvideos/models.py#L292-L311 |
18,441 | getsentry/semaphore | py/semaphore/utils.py | rustcall | def rustcall(func, *args):
"""Calls rust method and does some error handling."""
lib.semaphore_err_clear()
rv = func(*args)
err = lib.semaphore_err_get_last_code()
if not err:
return rv
msg = lib.semaphore_err_get_last_message()
cls = exceptions_by_code.get(err, SemaphoreError)
e... | python | def rustcall(func, *args):
"""Calls rust method and does some error handling."""
lib.semaphore_err_clear()
rv = func(*args)
err = lib.semaphore_err_get_last_code()
if not err:
return rv
msg = lib.semaphore_err_get_last_message()
cls = exceptions_by_code.get(err, SemaphoreError)
e... | [
"def",
"rustcall",
"(",
"func",
",",
"*",
"args",
")",
":",
"lib",
".",
"semaphore_err_clear",
"(",
")",
"rv",
"=",
"func",
"(",
"*",
"args",
")",
"err",
"=",
"lib",
".",
"semaphore_err_get_last_code",
"(",
")",
"if",
"not",
"err",
":",
"return",
"rv... | Calls rust method and does some error handling. | [
"Calls",
"rust",
"method",
"and",
"does",
"some",
"error",
"handling",
"."
] | 6f260b4092261e893b4debd9a3a7a78232f46c5e | https://github.com/getsentry/semaphore/blob/6f260b4092261e893b4debd9a3a7a78232f46c5e/py/semaphore/utils.py#L17-L30 |
18,442 | getsentry/semaphore | py/semaphore/utils.py | decode_str | def decode_str(s, free=False):
"""Decodes a SymbolicStr"""
try:
if s.len == 0:
return u""
return ffi.unpack(s.data, s.len).decode("utf-8", "replace")
finally:
if free:
lib.semaphore_str_free(ffi.addressof(s)) | python | def decode_str(s, free=False):
"""Decodes a SymbolicStr"""
try:
if s.len == 0:
return u""
return ffi.unpack(s.data, s.len).decode("utf-8", "replace")
finally:
if free:
lib.semaphore_str_free(ffi.addressof(s)) | [
"def",
"decode_str",
"(",
"s",
",",
"free",
"=",
"False",
")",
":",
"try",
":",
"if",
"s",
".",
"len",
"==",
"0",
":",
"return",
"u\"\"",
"return",
"ffi",
".",
"unpack",
"(",
"s",
".",
"data",
",",
"s",
".",
"len",
")",
".",
"decode",
"(",
"\... | Decodes a SymbolicStr | [
"Decodes",
"a",
"SymbolicStr"
] | 6f260b4092261e893b4debd9a3a7a78232f46c5e | https://github.com/getsentry/semaphore/blob/6f260b4092261e893b4debd9a3a7a78232f46c5e/py/semaphore/utils.py#L69-L77 |
18,443 | getsentry/semaphore | py/semaphore/utils.py | encode_str | def encode_str(s, mutable=False):
"""Encodes a SemaphoreStr"""
rv = ffi.new("SemaphoreStr *")
if isinstance(s, text_type):
s = s.encode("utf-8")
if mutable:
s = bytearray(s)
rv.data = ffi.from_buffer(s)
rv.len = len(s)
# we have to hold a weak reference here to ensure our str... | python | def encode_str(s, mutable=False):
"""Encodes a SemaphoreStr"""
rv = ffi.new("SemaphoreStr *")
if isinstance(s, text_type):
s = s.encode("utf-8")
if mutable:
s = bytearray(s)
rv.data = ffi.from_buffer(s)
rv.len = len(s)
# we have to hold a weak reference here to ensure our str... | [
"def",
"encode_str",
"(",
"s",
",",
"mutable",
"=",
"False",
")",
":",
"rv",
"=",
"ffi",
".",
"new",
"(",
"\"SemaphoreStr *\"",
")",
"if",
"isinstance",
"(",
"s",
",",
"text_type",
")",
":",
"s",
"=",
"s",
".",
"encode",
"(",
"\"utf-8\"",
")",
"if"... | Encodes a SemaphoreStr | [
"Encodes",
"a",
"SemaphoreStr"
] | 6f260b4092261e893b4debd9a3a7a78232f46c5e | https://github.com/getsentry/semaphore/blob/6f260b4092261e893b4debd9a3a7a78232f46c5e/py/semaphore/utils.py#L80-L92 |
18,444 | getsentry/semaphore | py/semaphore/utils.py | decode_uuid | def decode_uuid(value):
"""Decodes the given uuid value."""
return uuid.UUID(bytes=bytes(bytearray(ffi.unpack(value.data, 16)))) | python | def decode_uuid(value):
"""Decodes the given uuid value."""
return uuid.UUID(bytes=bytes(bytearray(ffi.unpack(value.data, 16)))) | [
"def",
"decode_uuid",
"(",
"value",
")",
":",
"return",
"uuid",
".",
"UUID",
"(",
"bytes",
"=",
"bytes",
"(",
"bytearray",
"(",
"ffi",
".",
"unpack",
"(",
"value",
".",
"data",
",",
"16",
")",
")",
")",
")"
] | Decodes the given uuid value. | [
"Decodes",
"the",
"given",
"uuid",
"value",
"."
] | 6f260b4092261e893b4debd9a3a7a78232f46c5e | https://github.com/getsentry/semaphore/blob/6f260b4092261e893b4debd9a3a7a78232f46c5e/py/semaphore/utils.py#L104-L106 |
18,445 | getsentry/semaphore | scripts/git-precommit-hook.py | has_cargo_fmt | def has_cargo_fmt():
"""Runs a quick check to see if cargo fmt is installed."""
try:
c = subprocess.Popen(
["cargo", "fmt", "--", "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return c.wait() == 0
except OSError:
return False | python | def has_cargo_fmt():
"""Runs a quick check to see if cargo fmt is installed."""
try:
c = subprocess.Popen(
["cargo", "fmt", "--", "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return c.wait() == 0
except OSError:
return False | [
"def",
"has_cargo_fmt",
"(",
")",
":",
"try",
":",
"c",
"=",
"subprocess",
".",
"Popen",
"(",
"[",
"\"cargo\"",
",",
"\"fmt\"",
",",
"\"--\"",
",",
"\"--help\"",
"]",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",... | Runs a quick check to see if cargo fmt is installed. | [
"Runs",
"a",
"quick",
"check",
"to",
"see",
"if",
"cargo",
"fmt",
"is",
"installed",
"."
] | 6f260b4092261e893b4debd9a3a7a78232f46c5e | https://github.com/getsentry/semaphore/blob/6f260b4092261e893b4debd9a3a7a78232f46c5e/scripts/git-precommit-hook.py#L8-L18 |
18,446 | getsentry/semaphore | scripts/git-precommit-hook.py | get_modified_files | def get_modified_files():
"""Returns a list of all modified files."""
c = subprocess.Popen(
["git", "diff-index", "--cached", "--name-only", "HEAD"], stdout=subprocess.PIPE
)
return c.communicate()[0].splitlines() | python | def get_modified_files():
"""Returns a list of all modified files."""
c = subprocess.Popen(
["git", "diff-index", "--cached", "--name-only", "HEAD"], stdout=subprocess.PIPE
)
return c.communicate()[0].splitlines() | [
"def",
"get_modified_files",
"(",
")",
":",
"c",
"=",
"subprocess",
".",
"Popen",
"(",
"[",
"\"git\"",
",",
"\"diff-index\"",
",",
"\"--cached\"",
",",
"\"--name-only\"",
",",
"\"HEAD\"",
"]",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
")",
"return",
"... | Returns a list of all modified files. | [
"Returns",
"a",
"list",
"of",
"all",
"modified",
"files",
"."
] | 6f260b4092261e893b4debd9a3a7a78232f46c5e | https://github.com/getsentry/semaphore/blob/6f260b4092261e893b4debd9a3a7a78232f46c5e/scripts/git-precommit-hook.py#L21-L26 |
18,447 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | _get_next_chunk | def _get_next_chunk(fp, previously_read_position, chunk_size):
"""Return next chunk of data that we would from the file pointer.
Args:
fp: file-like object
previously_read_position: file pointer position that we have read from
chunk_size: desired read chunk_size
Returns:
(b... | python | def _get_next_chunk(fp, previously_read_position, chunk_size):
"""Return next chunk of data that we would from the file pointer.
Args:
fp: file-like object
previously_read_position: file pointer position that we have read from
chunk_size: desired read chunk_size
Returns:
(b... | [
"def",
"_get_next_chunk",
"(",
"fp",
",",
"previously_read_position",
",",
"chunk_size",
")",
":",
"seek_position",
",",
"read_size",
"=",
"_get_what_to_read_next",
"(",
"fp",
",",
"previously_read_position",
",",
"chunk_size",
")",
"fp",
".",
"seek",
"(",
"seek_p... | Return next chunk of data that we would from the file pointer.
Args:
fp: file-like object
previously_read_position: file pointer position that we have read from
chunk_size: desired read chunk_size
Returns:
(bytestring, int): data that has been read in, the file pointer position... | [
"Return",
"next",
"chunk",
"of",
"data",
"that",
"we",
"would",
"from",
"the",
"file",
"pointer",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L95-L110 |
18,448 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | _get_what_to_read_next | def _get_what_to_read_next(fp, previously_read_position, chunk_size):
"""Return information on which file pointer position to read from and how many bytes.
Args:
fp
past_read_positon (int): The file pointer position that has been read previously
chunk_size(int): ideal io chunk_size
... | python | def _get_what_to_read_next(fp, previously_read_position, chunk_size):
"""Return information on which file pointer position to read from and how many bytes.
Args:
fp
past_read_positon (int): The file pointer position that has been read previously
chunk_size(int): ideal io chunk_size
... | [
"def",
"_get_what_to_read_next",
"(",
"fp",
",",
"previously_read_position",
",",
"chunk_size",
")",
":",
"seek_position",
"=",
"max",
"(",
"previously_read_position",
"-",
"chunk_size",
",",
"0",
")",
"read_size",
"=",
"chunk_size",
"# examples: say, our new_lines are ... | Return information on which file pointer position to read from and how many bytes.
Args:
fp
past_read_positon (int): The file pointer position that has been read previously
chunk_size(int): ideal io chunk_size
Returns:
(int, int): The next seek position, how many bytes to read ... | [
"Return",
"information",
"on",
"which",
"file",
"pointer",
"position",
"to",
"read",
"from",
"and",
"how",
"many",
"bytes",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L113-L143 |
18,449 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | _remove_trailing_new_line | def _remove_trailing_new_line(l):
"""Remove a single instance of new line at the end of l if it exists.
Returns:
bytestring
"""
# replace only 1 instance of newline
# match longest line first (hence the reverse=True), we want to match "\r\n" rather than "\n" if we can
for n in sorted(ne... | python | def _remove_trailing_new_line(l):
"""Remove a single instance of new line at the end of l if it exists.
Returns:
bytestring
"""
# replace only 1 instance of newline
# match longest line first (hence the reverse=True), we want to match "\r\n" rather than "\n" if we can
for n in sorted(ne... | [
"def",
"_remove_trailing_new_line",
"(",
"l",
")",
":",
"# replace only 1 instance of newline",
"# match longest line first (hence the reverse=True), we want to match \"\\r\\n\" rather than \"\\n\" if we can",
"for",
"n",
"in",
"sorted",
"(",
"new_lines_bytes",
",",
"key",
"=",
"la... | Remove a single instance of new line at the end of l if it exists.
Returns:
bytestring | [
"Remove",
"a",
"single",
"instance",
"of",
"new",
"line",
"at",
"the",
"end",
"of",
"l",
"if",
"it",
"exists",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L146-L158 |
18,450 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | _find_furthest_new_line | def _find_furthest_new_line(read_buffer):
"""Return -1 if read_buffer does not contain new line otherwise the position of the rightmost newline.
Args:
read_buffer (bytestring)
Returns:
int: The right most position of new line character in read_buffer if found, else -1
"""
new_line_... | python | def _find_furthest_new_line(read_buffer):
"""Return -1 if read_buffer does not contain new line otherwise the position of the rightmost newline.
Args:
read_buffer (bytestring)
Returns:
int: The right most position of new line character in read_buffer if found, else -1
"""
new_line_... | [
"def",
"_find_furthest_new_line",
"(",
"read_buffer",
")",
":",
"new_line_positions",
"=",
"[",
"read_buffer",
".",
"rfind",
"(",
"n",
")",
"for",
"n",
"in",
"new_lines_bytes",
"]",
"return",
"max",
"(",
"new_line_positions",
")"
] | Return -1 if read_buffer does not contain new line otherwise the position of the rightmost newline.
Args:
read_buffer (bytestring)
Returns:
int: The right most position of new line character in read_buffer if found, else -1 | [
"Return",
"-",
"1",
"if",
"read_buffer",
"does",
"not",
"contain",
"new",
"line",
"otherwise",
"the",
"position",
"of",
"the",
"rightmost",
"newline",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L161-L171 |
18,451 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | BufferWorkSpace.add_to_buffer | def add_to_buffer(self, content, read_position):
"""Add additional bytes content as read from the read_position.
Args:
content (bytes): data to be added to buffer working BufferWorkSpac.
read_position (int): where in the file pointer the data was read from.
"""
s... | python | def add_to_buffer(self, content, read_position):
"""Add additional bytes content as read from the read_position.
Args:
content (bytes): data to be added to buffer working BufferWorkSpac.
read_position (int): where in the file pointer the data was read from.
"""
s... | [
"def",
"add_to_buffer",
"(",
"self",
",",
"content",
",",
"read_position",
")",
":",
"self",
".",
"read_position",
"=",
"read_position",
"if",
"self",
".",
"read_buffer",
"is",
"None",
":",
"self",
".",
"read_buffer",
"=",
"content",
"else",
":",
"self",
"... | Add additional bytes content as read from the read_position.
Args:
content (bytes): data to be added to buffer working BufferWorkSpac.
read_position (int): where in the file pointer the data was read from. | [
"Add",
"additional",
"bytes",
"content",
"as",
"read",
"from",
"the",
"read_position",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L29-L40 |
18,452 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | BufferWorkSpace.yieldable | def yieldable(self):
"""Return True if there is a line that the buffer can return, False otherwise."""
if self.read_buffer is None:
return False
t = _remove_trailing_new_line(self.read_buffer)
n = _find_furthest_new_line(t)
if n >= 0:
return True
... | python | def yieldable(self):
"""Return True if there is a line that the buffer can return, False otherwise."""
if self.read_buffer is None:
return False
t = _remove_trailing_new_line(self.read_buffer)
n = _find_furthest_new_line(t)
if n >= 0:
return True
... | [
"def",
"yieldable",
"(",
"self",
")",
":",
"if",
"self",
".",
"read_buffer",
"is",
"None",
":",
"return",
"False",
"t",
"=",
"_remove_trailing_new_line",
"(",
"self",
".",
"read_buffer",
")",
"n",
"=",
"_find_furthest_new_line",
"(",
"t",
")",
"if",
"n",
... | Return True if there is a line that the buffer can return, False otherwise. | [
"Return",
"True",
"if",
"there",
"is",
"a",
"line",
"that",
"the",
"buffer",
"can",
"return",
"False",
"otherwise",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L42-L55 |
18,453 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | BufferWorkSpace.return_line | def return_line(self):
"""Return a new line if it is available.
Precondition: self.yieldable() must be True
"""
assert(self.yieldable())
t = _remove_trailing_new_line(self.read_buffer)
i = _find_furthest_new_line(t)
if i >= 0:
l = i + 1
... | python | def return_line(self):
"""Return a new line if it is available.
Precondition: self.yieldable() must be True
"""
assert(self.yieldable())
t = _remove_trailing_new_line(self.read_buffer)
i = _find_furthest_new_line(t)
if i >= 0:
l = i + 1
... | [
"def",
"return_line",
"(",
"self",
")",
":",
"assert",
"(",
"self",
".",
"yieldable",
"(",
")",
")",
"t",
"=",
"_remove_trailing_new_line",
"(",
"self",
".",
"read_buffer",
")",
"i",
"=",
"_find_furthest_new_line",
"(",
"t",
")",
"if",
"i",
">=",
"0",
... | Return a new line if it is available.
Precondition: self.yieldable() must be True | [
"Return",
"a",
"new",
"line",
"if",
"it",
"is",
"available",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L57-L76 |
18,454 | RobinNil/file_read_backwards | file_read_backwards/buffer_work_space.py | BufferWorkSpace.read_until_yieldable | def read_until_yieldable(self):
"""Read in additional chunks until it is yieldable."""
while not self.yieldable():
read_content, read_position = _get_next_chunk(self.fp, self.read_position, self.chunk_size)
self.add_to_buffer(read_content, read_position) | python | def read_until_yieldable(self):
"""Read in additional chunks until it is yieldable."""
while not self.yieldable():
read_content, read_position = _get_next_chunk(self.fp, self.read_position, self.chunk_size)
self.add_to_buffer(read_content, read_position) | [
"def",
"read_until_yieldable",
"(",
"self",
")",
":",
"while",
"not",
"self",
".",
"yieldable",
"(",
")",
":",
"read_content",
",",
"read_position",
"=",
"_get_next_chunk",
"(",
"self",
".",
"fp",
",",
"self",
".",
"read_position",
",",
"self",
".",
"chunk... | Read in additional chunks until it is yieldable. | [
"Read",
"in",
"additional",
"chunks",
"until",
"it",
"is",
"yieldable",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/buffer_work_space.py#L78-L82 |
18,455 | RobinNil/file_read_backwards | file_read_backwards/file_read_backwards.py | FileReadBackwardsIterator.next | def next(self):
"""Returns unicode string from the last line until the beginning of file.
Gets exhausted if::
* already reached the beginning of the file on previous iteration
* the file got closed
When it gets exhausted, it closes the file handler.
"""
... | python | def next(self):
"""Returns unicode string from the last line until the beginning of file.
Gets exhausted if::
* already reached the beginning of the file on previous iteration
* the file got closed
When it gets exhausted, it closes the file handler.
"""
... | [
"def",
"next",
"(",
"self",
")",
":",
"# Using binary mode, because some encodings such as \"utf-8\" use variable number of",
"# bytes to encode different Unicode points.",
"# Without using binary mode, we would probably need to understand each encoding more",
"# and do the seek operations to find... | Returns unicode string from the last line until the beginning of file.
Gets exhausted if::
* already reached the beginning of the file on previous iteration
* the file got closed
When it gets exhausted, it closes the file handler. | [
"Returns",
"unicode",
"string",
"from",
"the",
"last",
"line",
"until",
"the",
"beginning",
"of",
"file",
"."
] | e56443095b58aae309fbc43a0943eba867dc8500 | https://github.com/RobinNil/file_read_backwards/blob/e56443095b58aae309fbc43a0943eba867dc8500/file_read_backwards/file_read_backwards.py#L91-L112 |
18,456 | hendrix/hendrix | examples/django_hx_chatserver/example_app/chat/views.py | home | def home(request, chat_channel_name=None):
"""
if we have a chat_channel_name kwarg,
have the response include that channel name
so the javascript knows to subscribe to that
channel...
"""
if not chat_channel_name:
chat_channel_name = 'homepage'
context = {
... | python | def home(request, chat_channel_name=None):
"""
if we have a chat_channel_name kwarg,
have the response include that channel name
so the javascript knows to subscribe to that
channel...
"""
if not chat_channel_name:
chat_channel_name = 'homepage'
context = {
... | [
"def",
"home",
"(",
"request",
",",
"chat_channel_name",
"=",
"None",
")",
":",
"if",
"not",
"chat_channel_name",
":",
"chat_channel_name",
"=",
"'homepage'",
"context",
"=",
"{",
"'address'",
":",
"chat_channel_name",
",",
"'history'",
":",
"[",
"]",
",",
"... | if we have a chat_channel_name kwarg,
have the response include that channel name
so the javascript knows to subscribe to that
channel... | [
"if",
"we",
"have",
"a",
"chat_channel_name",
"kwarg",
"have",
"the",
"response",
"include",
"that",
"channel",
"name",
"so",
"the",
"javascript",
"knows",
"to",
"subscribe",
"to",
"that",
"channel",
"..."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/examples/django_hx_chatserver/example_app/chat/views.py#L9-L37 |
18,457 | hendrix/hendrix | hendrix/ux.py | hendrixLauncher | def hendrixLauncher(action, options, with_tiempo=False):
"""
Decides which version of HendrixDeploy to use and then
launches it.
"""
if options['key'] and options['cert'] and options['cache']:
from hendrix.deploy import hybrid
HendrixDeploy = hybrid.HendrixDeployHybrid
elif optio... | python | def hendrixLauncher(action, options, with_tiempo=False):
"""
Decides which version of HendrixDeploy to use and then
launches it.
"""
if options['key'] and options['cert'] and options['cache']:
from hendrix.deploy import hybrid
HendrixDeploy = hybrid.HendrixDeployHybrid
elif optio... | [
"def",
"hendrixLauncher",
"(",
"action",
",",
"options",
",",
"with_tiempo",
"=",
"False",
")",
":",
"if",
"options",
"[",
"'key'",
"]",
"and",
"options",
"[",
"'cert'",
"]",
"and",
"options",
"[",
"'cache'",
"]",
":",
"from",
"hendrix",
".",
"deploy",
... | Decides which version of HendrixDeploy to use and then
launches it. | [
"Decides",
"which",
"version",
"of",
"HendrixDeploy",
"to",
"use",
"and",
"then",
"launches",
"it",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/ux.py#L67-L87 |
18,458 | hendrix/hendrix | hendrix/ux.py | logReload | def logReload(options):
"""
encompasses all the logic for reloading observer.
"""
event_handler = Reload(options)
observer = Observer()
observer.schedule(event_handler, path='.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterr... | python | def logReload(options):
"""
encompasses all the logic for reloading observer.
"""
event_handler = Reload(options)
observer = Observer()
observer.schedule(event_handler, path='.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterr... | [
"def",
"logReload",
"(",
"options",
")",
":",
"event_handler",
"=",
"Reload",
"(",
"options",
")",
"observer",
"=",
"Observer",
"(",
")",
"observer",
".",
"schedule",
"(",
"event_handler",
",",
"path",
"=",
"'.'",
",",
"recursive",
"=",
"True",
")",
"obs... | encompasses all the logic for reloading observer. | [
"encompasses",
"all",
"the",
"logic",
"for",
"reloading",
"observer",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/ux.py#L100-L118 |
18,459 | hendrix/hendrix | hendrix/ux.py | launch | def launch(*args, **options):
"""
launch acts on the user specified action and options by executing
Hedrix.run
"""
action = args[0]
if options['reload']:
logReload(options)
else:
assignDeploymentInstance(action, options) | python | def launch(*args, **options):
"""
launch acts on the user specified action and options by executing
Hedrix.run
"""
action = args[0]
if options['reload']:
logReload(options)
else:
assignDeploymentInstance(action, options) | [
"def",
"launch",
"(",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"action",
"=",
"args",
"[",
"0",
"]",
"if",
"options",
"[",
"'reload'",
"]",
":",
"logReload",
"(",
"options",
")",
"else",
":",
"assignDeploymentInstance",
"(",
"action",
",",
"o... | launch acts on the user specified action and options by executing
Hedrix.run | [
"launch",
"acts",
"on",
"the",
"user",
"specified",
"action",
"and",
"options",
"by",
"executing",
"Hedrix",
".",
"run"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/ux.py#L121-L130 |
18,460 | hendrix/hendrix | hendrix/ux.py | findSettingsModule | def findSettingsModule():
"Find the settings module dot path within django's manage.py file"
try:
with open('manage.py', 'r') as manage:
manage_contents = manage.read()
search = re.search(
r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents
)
... | python | def findSettingsModule():
"Find the settings module dot path within django's manage.py file"
try:
with open('manage.py', 'r') as manage:
manage_contents = manage.read()
search = re.search(
r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents
)
... | [
"def",
"findSettingsModule",
"(",
")",
":",
"try",
":",
"with",
"open",
"(",
"'manage.py'",
",",
"'r'",
")",
"as",
"manage",
":",
"manage_contents",
"=",
"manage",
".",
"read",
"(",
")",
"search",
"=",
"re",
".",
"search",
"(",
"r\"([\\\"\\'](?P<module>[a-... | Find the settings module dot path within django's manage.py file | [
"Find",
"the",
"settings",
"module",
"dot",
"path",
"within",
"django",
"s",
"manage",
".",
"py",
"file"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/ux.py#L133-L165 |
18,461 | hendrix/hendrix | hendrix/ux.py | subprocessLaunch | def subprocessLaunch():
"""
This function is called by the hxw script.
It takes no arguments, and returns an instance of HendrixDeploy
"""
if not redis_available:
raise RedisException("can't launch this subprocess without tiempo/redis.")
try:
action = 'start'
options = RE... | python | def subprocessLaunch():
"""
This function is called by the hxw script.
It takes no arguments, and returns an instance of HendrixDeploy
"""
if not redis_available:
raise RedisException("can't launch this subprocess without tiempo/redis.")
try:
action = 'start'
options = RE... | [
"def",
"subprocessLaunch",
"(",
")",
":",
"if",
"not",
"redis_available",
":",
"raise",
"RedisException",
"(",
"\"can't launch this subprocess without tiempo/redis.\"",
")",
"try",
":",
"action",
"=",
"'start'",
"options",
"=",
"REDIS",
".",
"get",
"(",
"'worker_arg... | This function is called by the hxw script.
It takes no arguments, and returns an instance of HendrixDeploy | [
"This",
"function",
"is",
"called",
"by",
"the",
"hxw",
"script",
".",
"It",
"takes",
"no",
"arguments",
"and",
"returns",
"an",
"instance",
"of",
"HendrixDeploy"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/ux.py#L227-L240 |
18,462 | hendrix/hendrix | hendrix/ux.py | main | def main(args=None):
"The function to execute when running hx"
if args is None:
args = sys.argv[1:]
options, args = HendrixOptionParser.parse_args(args)
options = vars(options)
try:
action = args[0]
except IndexError:
HendrixOptionParser.print_help()
return
... | python | def main(args=None):
"The function to execute when running hx"
if args is None:
args = sys.argv[1:]
options, args = HendrixOptionParser.parse_args(args)
options = vars(options)
try:
action = args[0]
except IndexError:
HendrixOptionParser.print_help()
return
... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
"options",
",",
"args",
"=",
"HendrixOptionParser",
".",
"parse_args",
"(",
"args",
")",
"options",
"=",
"vars"... | The function to execute when running hx | [
"The",
"function",
"to",
"execute",
"when",
"running",
"hx"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/ux.py#L243-L268 |
18,463 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheClient.handleHeader | def handleHeader(self, key, value):
"extends handleHeader to save headers to a local response object"
key_lower = key.lower()
if key_lower == 'location':
value = self.modLocationPort(value)
self._response.headers[key_lower] = value
if key_lower != 'cache-control':
... | python | def handleHeader(self, key, value):
"extends handleHeader to save headers to a local response object"
key_lower = key.lower()
if key_lower == 'location':
value = self.modLocationPort(value)
self._response.headers[key_lower] = value
if key_lower != 'cache-control':
... | [
"def",
"handleHeader",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"key_lower",
"=",
"key",
".",
"lower",
"(",
")",
"if",
"key_lower",
"==",
"'location'",
":",
"value",
"=",
"self",
".",
"modLocationPort",
"(",
"value",
")",
"self",
".",
"_respons... | extends handleHeader to save headers to a local response object | [
"extends",
"handleHeader",
"to",
"save",
"headers",
"to",
"a",
"local",
"response",
"object"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L38-L49 |
18,464 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheClient.handleStatus | def handleStatus(self, version, code, message):
"extends handleStatus to instantiate a local response object"
proxy.ProxyClient.handleStatus(self, version, code, message)
# client.Response is currently just a container for needed data
self._response = client.Response(version, code, messa... | python | def handleStatus(self, version, code, message):
"extends handleStatus to instantiate a local response object"
proxy.ProxyClient.handleStatus(self, version, code, message)
# client.Response is currently just a container for needed data
self._response = client.Response(version, code, messa... | [
"def",
"handleStatus",
"(",
"self",
",",
"version",
",",
"code",
",",
"message",
")",
":",
"proxy",
".",
"ProxyClient",
".",
"handleStatus",
"(",
"self",
",",
"version",
",",
"code",
",",
"message",
")",
"# client.Response is currently just a container for needed ... | extends handleStatus to instantiate a local response object | [
"extends",
"handleStatus",
"to",
"instantiate",
"a",
"local",
"response",
"object"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L51-L55 |
18,465 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheClient.modLocationPort | def modLocationPort(self, location):
"""
Ensures that the location port is a the given port value
Used in `handleHeader`
"""
components = urlparse.urlparse(location)
reverse_proxy_port = self.father.getHost().port
reverse_proxy_host = self.father.getHost().host
... | python | def modLocationPort(self, location):
"""
Ensures that the location port is a the given port value
Used in `handleHeader`
"""
components = urlparse.urlparse(location)
reverse_proxy_port = self.father.getHost().port
reverse_proxy_host = self.father.getHost().host
... | [
"def",
"modLocationPort",
"(",
"self",
",",
"location",
")",
":",
"components",
"=",
"urlparse",
".",
"urlparse",
"(",
"location",
")",
"reverse_proxy_port",
"=",
"self",
".",
"father",
".",
"getHost",
"(",
")",
".",
"port",
"reverse_proxy_host",
"=",
"self"... | Ensures that the location port is a the given port value
Used in `handleHeader` | [
"Ensures",
"that",
"the",
"location",
"port",
"is",
"a",
"the",
"given",
"port",
"value",
"Used",
"in",
"handleHeader"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L57-L70 |
18,466 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheClient.handleResponsePart | def handleResponsePart(self, buffer):
"""
Sends the content to the browser and keeps a local copy of it.
buffer is just a str of the content to be shown, father is the intial
request.
"""
self.father.write(buffer)
self.buffer.write(buffer) | python | def handleResponsePart(self, buffer):
"""
Sends the content to the browser and keeps a local copy of it.
buffer is just a str of the content to be shown, father is the intial
request.
"""
self.father.write(buffer)
self.buffer.write(buffer) | [
"def",
"handleResponsePart",
"(",
"self",
",",
"buffer",
")",
":",
"self",
".",
"father",
".",
"write",
"(",
"buffer",
")",
"self",
".",
"buffer",
".",
"write",
"(",
"buffer",
")"
] | Sends the content to the browser and keeps a local copy of it.
buffer is just a str of the content to be shown, father is the intial
request. | [
"Sends",
"the",
"content",
"to",
"the",
"browser",
"and",
"keeps",
"a",
"local",
"copy",
"of",
"it",
".",
"buffer",
"is",
"just",
"a",
"str",
"of",
"the",
"content",
"to",
"be",
"shown",
"father",
"is",
"the",
"intial",
"request",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L92-L99 |
18,467 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheProxyResource.getChild | def getChild(self, path, request):
"""
This is necessary because the parent class would call
proxy.ReverseProxyResource instead of CacheProxyResource
"""
return CacheProxyResource(
self.host, self.port, self.path + '/' + urlquote(path, safe=""),
self.react... | python | def getChild(self, path, request):
"""
This is necessary because the parent class would call
proxy.ReverseProxyResource instead of CacheProxyResource
"""
return CacheProxyResource(
self.host, self.port, self.path + '/' + urlquote(path, safe=""),
self.react... | [
"def",
"getChild",
"(",
"self",
",",
"path",
",",
"request",
")",
":",
"return",
"CacheProxyResource",
"(",
"self",
".",
"host",
",",
"self",
".",
"port",
",",
"self",
".",
"path",
"+",
"'/'",
"+",
"urlquote",
"(",
"path",
",",
"safe",
"=",
"\"\"",
... | This is necessary because the parent class would call
proxy.ReverseProxyResource instead of CacheProxyResource | [
"This",
"is",
"necessary",
"because",
"the",
"parent",
"class",
"would",
"call",
"proxy",
".",
"ReverseProxyResource",
"instead",
"of",
"CacheProxyResource"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L148-L156 |
18,468 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheProxyResource.getChildWithDefault | def getChildWithDefault(self, path, request):
"""
Retrieve a static or dynamically generated child resource from me.
"""
cached_resource = self.getCachedResource(request)
if cached_resource:
reactor.callInThread(
responseInColor,
reques... | python | def getChildWithDefault(self, path, request):
"""
Retrieve a static or dynamically generated child resource from me.
"""
cached_resource = self.getCachedResource(request)
if cached_resource:
reactor.callInThread(
responseInColor,
reques... | [
"def",
"getChildWithDefault",
"(",
"self",
",",
"path",
",",
"request",
")",
":",
"cached_resource",
"=",
"self",
".",
"getCachedResource",
"(",
"request",
")",
"if",
"cached_resource",
":",
"reactor",
".",
"callInThread",
"(",
"responseInColor",
",",
"request",... | Retrieve a static or dynamically generated child resource from me. | [
"Retrieve",
"a",
"static",
"or",
"dynamically",
"generated",
"child",
"resource",
"from",
"me",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L158-L176 |
18,469 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheProxyResource.render | def render(self, request):
"""
Render a request by forwarding it to the proxied server.
"""
# set up and evaluate a connection to the target server
if self.port == 80:
host = self.host
else:
host = "%s:%d" % (self.host, self.port)
request.r... | python | def render(self, request):
"""
Render a request by forwarding it to the proxied server.
"""
# set up and evaluate a connection to the target server
if self.port == 80:
host = self.host
else:
host = "%s:%d" % (self.host, self.port)
request.r... | [
"def",
"render",
"(",
"self",
",",
"request",
")",
":",
"# set up and evaluate a connection to the target server",
"if",
"self",
".",
"port",
"==",
"80",
":",
"host",
"=",
"self",
".",
"host",
"else",
":",
"host",
"=",
"\"%s:%d\"",
"%",
"(",
"self",
".",
"... | Render a request by forwarding it to the proxied server. | [
"Render",
"a",
"request",
"by",
"forwarding",
"it",
"to",
"the",
"proxied",
"server",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L178-L204 |
18,470 | hendrix/hendrix | hendrix/contrib/cache/resource.py | CacheProxyResource.getGlobalSelf | def getGlobalSelf(self):
"""
This searches the reactor for the original instance of
CacheProxyResource. This is necessary because with each call of
getChild a new instance of CacheProxyResource is created.
"""
transports = self.reactor.getReaders()
for transport i... | python | def getGlobalSelf(self):
"""
This searches the reactor for the original instance of
CacheProxyResource. This is necessary because with each call of
getChild a new instance of CacheProxyResource is created.
"""
transports = self.reactor.getReaders()
for transport i... | [
"def",
"getGlobalSelf",
"(",
"self",
")",
":",
"transports",
"=",
"self",
".",
"reactor",
".",
"getReaders",
"(",
")",
"for",
"transport",
"in",
"transports",
":",
"try",
":",
"resource",
"=",
"transport",
".",
"factory",
".",
"resource",
"if",
"isinstance... | This searches the reactor for the original instance of
CacheProxyResource. This is necessary because with each call of
getChild a new instance of CacheProxyResource is created. | [
"This",
"searches",
"the",
"reactor",
"for",
"the",
"original",
"instance",
"of",
"CacheProxyResource",
".",
"This",
"is",
"necessary",
"because",
"with",
"each",
"call",
"of",
"getChild",
"a",
"new",
"instance",
"of",
"CacheProxyResource",
"is",
"created",
"."
... | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L209-L223 |
18,471 | hendrix/hendrix | hendrix/contrib/concurrency/resources.py | MessageHandlerProtocol.dataReceived | def dataReceived(self, data):
"""
Takes "data" which we assume is json encoded
If data has a subject_id attribute, we pass that to the dispatcher
as the subject_id so it will get carried through into any
return communications and be identifiable to the client
... | python | def dataReceived(self, data):
"""
Takes "data" which we assume is json encoded
If data has a subject_id attribute, we pass that to the dispatcher
as the subject_id so it will get carried through into any
return communications and be identifiable to the client
... | [
"def",
"dataReceived",
"(",
"self",
",",
"data",
")",
":",
"try",
":",
"address",
"=",
"self",
".",
"guid",
"data",
"=",
"json",
".",
"loads",
"(",
"data",
")",
"threads",
".",
"deferToThread",
"(",
"send_signal",
",",
"self",
".",
"dispatcher",
",",
... | Takes "data" which we assume is json encoded
If data has a subject_id attribute, we pass that to the dispatcher
as the subject_id so it will get carried through into any
return communications and be identifiable to the client
falls back to just passing the message along.... | [
"Takes",
"data",
"which",
"we",
"assume",
"is",
"json",
"encoded",
"If",
"data",
"has",
"a",
"subject_id",
"attribute",
"we",
"pass",
"that",
"to",
"the",
"dispatcher",
"as",
"the",
"subject_id",
"so",
"it",
"will",
"get",
"carried",
"through",
"into",
"an... | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/resources.py#L26-L57 |
18,472 | hendrix/hendrix | hendrix/contrib/concurrency/resources.py | MessageHandlerProtocol.connectionMade | def connectionMade(self):
"""
establish the address of this new connection and add it to the list of
sockets managed by the dispatcher
reply to the transport with a "setup_connection" notice
containing the recipient's address for use by the client as a return
address for... | python | def connectionMade(self):
"""
establish the address of this new connection and add it to the list of
sockets managed by the dispatcher
reply to the transport with a "setup_connection" notice
containing the recipient's address for use by the client as a return
address for... | [
"def",
"connectionMade",
"(",
"self",
")",
":",
"self",
".",
"transport",
".",
"uid",
"=",
"str",
"(",
"uuid",
".",
"uuid1",
"(",
")",
")",
"self",
".",
"guid",
"=",
"self",
".",
"dispatcher",
".",
"add",
"(",
"self",
".",
"transport",
")",
"self",... | establish the address of this new connection and add it to the list of
sockets managed by the dispatcher
reply to the transport with a "setup_connection" notice
containing the recipient's address for use by the client as a return
address for future communications | [
"establish",
"the",
"address",
"of",
"this",
"new",
"connection",
"and",
"add",
"it",
"to",
"the",
"list",
"of",
"sockets",
"managed",
"by",
"the",
"dispatcher"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/resources.py#L59-L71 |
18,473 | hendrix/hendrix | hendrix/utils/conf.py | generateInitd | def generateInitd(conf_file):
"""
Helper function to generate the text content needed to create an init.d
executable
"""
allowed_opts = [
'virtualenv', 'project_path', 'settings', 'processes',
'http_port', 'cache', 'cache_port', 'https_port', 'key', 'cert'
]
base_opts = ['--d... | python | def generateInitd(conf_file):
"""
Helper function to generate the text content needed to create an init.d
executable
"""
allowed_opts = [
'virtualenv', 'project_path', 'settings', 'processes',
'http_port', 'cache', 'cache_port', 'https_port', 'key', 'cert'
]
base_opts = ['--d... | [
"def",
"generateInitd",
"(",
"conf_file",
")",
":",
"allowed_opts",
"=",
"[",
"'virtualenv'",
",",
"'project_path'",
",",
"'settings'",
",",
"'processes'",
",",
"'http_port'",
",",
"'cache'",
",",
"'cache_port'",
",",
"'https_port'",
",",
"'key'",
",",
"'cert'",... | Helper function to generate the text content needed to create an init.d
executable | [
"Helper",
"function",
"to",
"generate",
"the",
"text",
"content",
"needed",
"to",
"create",
"an",
"init",
".",
"d",
"executable"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/utils/conf.py#L9-L61 |
18,474 | hendrix/hendrix | hendrix/facilities/response.py | LoudWSGIResponse.startResponse | def startResponse(self, status, headers, excInfo=None):
"""
extends startResponse to call speakerBox in a thread
"""
self.status = status
self.headers = headers
self.reactor.callInThread(
responseInColor, self.request, status, headers
)
return ... | python | def startResponse(self, status, headers, excInfo=None):
"""
extends startResponse to call speakerBox in a thread
"""
self.status = status
self.headers = headers
self.reactor.callInThread(
responseInColor, self.request, status, headers
)
return ... | [
"def",
"startResponse",
"(",
"self",
",",
"status",
",",
"headers",
",",
"excInfo",
"=",
"None",
")",
":",
"self",
".",
"status",
"=",
"status",
"self",
".",
"headers",
"=",
"headers",
"self",
".",
"reactor",
".",
"callInThread",
"(",
"responseInColor",
... | extends startResponse to call speakerBox in a thread | [
"extends",
"startResponse",
"to",
"call",
"speakerBox",
"in",
"a",
"thread"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/facilities/response.py#L41-L50 |
18,475 | hendrix/hendrix | hendrix/contrib/cache/backends/__init__.py | CacheBackend.cacheContent | def cacheContent(self, request, response, buffer):
"""
Checks if the response should be cached.
Caches the content in a gzipped format given that a `cache_it` flag is
True
To be used CacheClient
"""
content = buffer.getvalue()
code = int(response.code)
... | python | def cacheContent(self, request, response, buffer):
"""
Checks if the response should be cached.
Caches the content in a gzipped format given that a `cache_it` flag is
True
To be used CacheClient
"""
content = buffer.getvalue()
code = int(response.code)
... | [
"def",
"cacheContent",
"(",
"self",
",",
"request",
",",
"response",
",",
"buffer",
")",
":",
"content",
"=",
"buffer",
".",
"getvalue",
"(",
")",
"code",
"=",
"int",
"(",
"response",
".",
"code",
")",
"cache_it",
"=",
"False",
"uri",
",",
"bust",
"=... | Checks if the response should be cached.
Caches the content in a gzipped format given that a `cache_it` flag is
True
To be used CacheClient | [
"Checks",
"if",
"the",
"response",
"should",
"be",
"cached",
".",
"Caches",
"the",
"content",
"in",
"a",
"gzipped",
"format",
"given",
"that",
"a",
"cache_it",
"flag",
"is",
"True",
"To",
"be",
"used",
"CacheClient"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/backends/__init__.py#L70-L94 |
18,476 | hendrix/hendrix | hendrix/facilities/gather.py | get_additional_services | def get_additional_services(settings_module):
"""
if HENDRIX_SERVICES is specified in settings_module,
it should be a list twisted internet services
example:
HENDRIX_SERVICES = (
('myServiceName', 'apps.offload.services.TimeService'),
)
"""
ad... | python | def get_additional_services(settings_module):
"""
if HENDRIX_SERVICES is specified in settings_module,
it should be a list twisted internet services
example:
HENDRIX_SERVICES = (
('myServiceName', 'apps.offload.services.TimeService'),
)
"""
ad... | [
"def",
"get_additional_services",
"(",
"settings_module",
")",
":",
"additional_services",
"=",
"[",
"]",
"if",
"hasattr",
"(",
"settings_module",
",",
"'HENDRIX_SERVICES'",
")",
":",
"for",
"name",
",",
"module_path",
"in",
"settings_module",
".",
"HENDRIX_SERVICES... | if HENDRIX_SERVICES is specified in settings_module,
it should be a list twisted internet services
example:
HENDRIX_SERVICES = (
('myServiceName', 'apps.offload.services.TimeService'),
) | [
"if",
"HENDRIX_SERVICES",
"is",
"specified",
"in",
"settings_module",
"it",
"should",
"be",
"a",
"list",
"twisted",
"internet",
"services"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/facilities/gather.py#L4-L25 |
18,477 | hendrix/hendrix | hendrix/facilities/gather.py | get_additional_resources | def get_additional_resources(settings_module):
"""
if HENDRIX_CHILD_RESOURCES is specified in settings_module,
it should be a list resources subclassed from hendrix.contrib.NamedResource
example:
HENDRIX_CHILD_RESOURCES = (
'apps.offload.resources.LongRunningProcessResource',
... | python | def get_additional_resources(settings_module):
"""
if HENDRIX_CHILD_RESOURCES is specified in settings_module,
it should be a list resources subclassed from hendrix.contrib.NamedResource
example:
HENDRIX_CHILD_RESOURCES = (
'apps.offload.resources.LongRunningProcessResource',
... | [
"def",
"get_additional_resources",
"(",
"settings_module",
")",
":",
"additional_resources",
"=",
"[",
"]",
"if",
"hasattr",
"(",
"settings_module",
",",
"'HENDRIX_CHILD_RESOURCES'",
")",
":",
"for",
"module_path",
"in",
"settings_module",
".",
"HENDRIX_CHILD_RESOURCES"... | if HENDRIX_CHILD_RESOURCES is specified in settings_module,
it should be a list resources subclassed from hendrix.contrib.NamedResource
example:
HENDRIX_CHILD_RESOURCES = (
'apps.offload.resources.LongRunningProcessResource',
'apps.chat.resources.ChatResource',
) | [
"if",
"HENDRIX_CHILD_RESOURCES",
"is",
"specified",
"in",
"settings_module",
"it",
"should",
"be",
"a",
"list",
"resources",
"subclassed",
"from",
"hendrix",
".",
"contrib",
".",
"NamedResource"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/facilities/gather.py#L28-L52 |
18,478 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.getConf | def getConf(cls, settings, options):
"updates the options dict to use config options in the settings module"
ports = ['http_port', 'https_port', 'cache_port']
for port_name in ports:
port = getattr(settings, port_name.upper(), None)
# only use the settings ports if the de... | python | def getConf(cls, settings, options):
"updates the options dict to use config options in the settings module"
ports = ['http_port', 'https_port', 'cache_port']
for port_name in ports:
port = getattr(settings, port_name.upper(), None)
# only use the settings ports if the de... | [
"def",
"getConf",
"(",
"cls",
",",
"settings",
",",
"options",
")",
":",
"ports",
"=",
"[",
"'http_port'",
",",
"'https_port'",
",",
"'cache_port'",
"]",
"for",
"port_name",
"in",
"ports",
":",
"port",
"=",
"getattr",
"(",
"settings",
",",
"port_name",
"... | updates the options dict to use config options in the settings module | [
"updates",
"the",
"options",
"dict",
"to",
"use",
"config",
"options",
"in",
"the",
"settings",
"module"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L99-L121 |
18,479 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.addHendrix | def addHendrix(self):
'''
Instantiates a HendrixService with this object's threadpool.
It will be added as a service later.
'''
self.hendrix = HendrixService(
self.application,
threadpool=self.getThreadPool(),
resources=self.resources,
... | python | def addHendrix(self):
'''
Instantiates a HendrixService with this object's threadpool.
It will be added as a service later.
'''
self.hendrix = HendrixService(
self.application,
threadpool=self.getThreadPool(),
resources=self.resources,
... | [
"def",
"addHendrix",
"(",
"self",
")",
":",
"self",
".",
"hendrix",
"=",
"HendrixService",
"(",
"self",
".",
"application",
",",
"threadpool",
"=",
"self",
".",
"getThreadPool",
"(",
")",
",",
"resources",
"=",
"self",
".",
"resources",
",",
"services",
... | Instantiates a HendrixService with this object's threadpool.
It will be added as a service later. | [
"Instantiates",
"a",
"HendrixService",
"with",
"this",
"object",
"s",
"threadpool",
".",
"It",
"will",
"be",
"added",
"as",
"a",
"service",
"later",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L144-L157 |
18,480 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.catalogServers | def catalogServers(self, hendrix):
"collects a list of service names serving on TCP or SSL"
for service in hendrix.services:
if isinstance(service, (TCPServer, SSLServer)):
self.servers.append(service.name) | python | def catalogServers(self, hendrix):
"collects a list of service names serving on TCP or SSL"
for service in hendrix.services:
if isinstance(service, (TCPServer, SSLServer)):
self.servers.append(service.name) | [
"def",
"catalogServers",
"(",
"self",
",",
"hendrix",
")",
":",
"for",
"service",
"in",
"hendrix",
".",
"services",
":",
"if",
"isinstance",
"(",
"service",
",",
"(",
"TCPServer",
",",
"SSLServer",
")",
")",
":",
"self",
".",
"servers",
".",
"append",
... | collects a list of service names serving on TCP or SSL | [
"collects",
"a",
"list",
"of",
"service",
"names",
"serving",
"on",
"TCP",
"or",
"SSL"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L159-L163 |
18,481 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.run | def run(self):
"sets up the desired services and runs the requested action"
self.addServices()
self.catalogServers(self.hendrix)
action = self.action
fd = self.options['fd']
if action.startswith('start'):
chalk.blue(self._listening_message())
geta... | python | def run(self):
"sets up the desired services and runs the requested action"
self.addServices()
self.catalogServers(self.hendrix)
action = self.action
fd = self.options['fd']
if action.startswith('start'):
chalk.blue(self._listening_message())
geta... | [
"def",
"run",
"(",
"self",
")",
":",
"self",
".",
"addServices",
"(",
")",
"self",
".",
"catalogServers",
"(",
"self",
".",
"hendrix",
")",
"action",
"=",
"self",
".",
"action",
"fd",
"=",
"self",
".",
"options",
"[",
"'fd'",
"]",
"if",
"action",
"... | sets up the desired services and runs the requested action | [
"sets",
"up",
"the",
"desired",
"services",
"and",
"runs",
"the",
"requested",
"action"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L169-L191 |
18,482 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.setFDs | def setFDs(self):
"""
Iterator for file descriptors.
Seperated from launchworkers for clarity and readability.
"""
# 0 corresponds to stdin, 1 to stdout, 2 to stderr
self.childFDs = {0: 0, 1: 1, 2: 2}
self.fds = {}
for name in self.servers:
sel... | python | def setFDs(self):
"""
Iterator for file descriptors.
Seperated from launchworkers for clarity and readability.
"""
# 0 corresponds to stdin, 1 to stdout, 2 to stderr
self.childFDs = {0: 0, 1: 1, 2: 2}
self.fds = {}
for name in self.servers:
sel... | [
"def",
"setFDs",
"(",
"self",
")",
":",
"# 0 corresponds to stdin, 1 to stdout, 2 to stderr",
"self",
".",
"childFDs",
"=",
"{",
"0",
":",
"0",
",",
"1",
":",
"1",
",",
"2",
":",
"2",
"}",
"self",
".",
"fds",
"=",
"{",
"}",
"for",
"name",
"in",
"self... | Iterator for file descriptors.
Seperated from launchworkers for clarity and readability. | [
"Iterator",
"for",
"file",
"descriptors",
".",
"Seperated",
"from",
"launchworkers",
"for",
"clarity",
"and",
"readability",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L240-L252 |
18,483 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.addSubprocess | def addSubprocess(self, fds, name, factory):
"""
Public method for _addSubprocess.
Wraps reactor.adoptStreamConnection in
a simple DeferredLock to guarantee
workers play well together.
"""
self._lock.run(self._addSubprocess, self, fds, name, factory) | python | def addSubprocess(self, fds, name, factory):
"""
Public method for _addSubprocess.
Wraps reactor.adoptStreamConnection in
a simple DeferredLock to guarantee
workers play well together.
"""
self._lock.run(self._addSubprocess, self, fds, name, factory) | [
"def",
"addSubprocess",
"(",
"self",
",",
"fds",
",",
"name",
",",
"factory",
")",
":",
"self",
".",
"_lock",
".",
"run",
"(",
"self",
".",
"_addSubprocess",
",",
"self",
",",
"fds",
",",
"name",
",",
"factory",
")"
] | Public method for _addSubprocess.
Wraps reactor.adoptStreamConnection in
a simple DeferredLock to guarantee
workers play well together. | [
"Public",
"method",
"for",
"_addSubprocess",
".",
"Wraps",
"reactor",
".",
"adoptStreamConnection",
"in",
"a",
"simple",
"DeferredLock",
"to",
"guarantee",
"workers",
"play",
"well",
"together",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L273-L280 |
18,484 | hendrix/hendrix | hendrix/deploy/base.py | HendrixDeploy.disownService | def disownService(self, name):
"""
disowns a service on hendirix by name
returns a factory for use in the adoptStreamPort part of setting up
multiple processes
"""
_service = self.hendrix.getServiceNamed(name)
_service.disownServiceParent()
return _service... | python | def disownService(self, name):
"""
disowns a service on hendirix by name
returns a factory for use in the adoptStreamPort part of setting up
multiple processes
"""
_service = self.hendrix.getServiceNamed(name)
_service.disownServiceParent()
return _service... | [
"def",
"disownService",
"(",
"self",
",",
"name",
")",
":",
"_service",
"=",
"self",
".",
"hendrix",
".",
"getServiceNamed",
"(",
"name",
")",
"_service",
".",
"disownServiceParent",
"(",
")",
"return",
"_service",
".",
"factory"
] | disowns a service on hendirix by name
returns a factory for use in the adoptStreamPort part of setting up
multiple processes | [
"disowns",
"a",
"service",
"on",
"hendirix",
"by",
"name",
"returns",
"a",
"factory",
"for",
"use",
"in",
"the",
"adoptStreamPort",
"part",
"of",
"setting",
"up",
"multiple",
"processes"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/base.py#L307-L315 |
18,485 | hendrix/hendrix | hendrix/utils/__init__.py | get_pid | def get_pid(options):
"""returns The default location of the pid file for process management"""
namespace = options['settings'] if options['settings'] else options['wsgi']
return os.path.join('{}', '{}_{}.pid').format(PID_DIR, options['http_port'], namespace.replace('.', '_')) | python | def get_pid(options):
"""returns The default location of the pid file for process management"""
namespace = options['settings'] if options['settings'] else options['wsgi']
return os.path.join('{}', '{}_{}.pid').format(PID_DIR, options['http_port'], namespace.replace('.', '_')) | [
"def",
"get_pid",
"(",
"options",
")",
":",
"namespace",
"=",
"options",
"[",
"'settings'",
"]",
"if",
"options",
"[",
"'settings'",
"]",
"else",
"options",
"[",
"'wsgi'",
"]",
"return",
"os",
".",
"path",
".",
"join",
"(",
"'{}'",
",",
"'{}_{}.pid'",
... | returns The default location of the pid file for process management | [
"returns",
"The",
"default",
"location",
"of",
"the",
"pid",
"file",
"for",
"process",
"management"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/utils/__init__.py#L21-L24 |
18,486 | hendrix/hendrix | hendrix/utils/__init__.py | responseInColor | def responseInColor(request, status, headers, prefix='Response', opts=None):
"Prints the response info in color"
code, message = status.split(None, 1)
message = '%s [%s] => Request %s %s %s on pid %d' % (
prefix,
code,
str(request.host),
request.method,
request.path,
... | python | def responseInColor(request, status, headers, prefix='Response', opts=None):
"Prints the response info in color"
code, message = status.split(None, 1)
message = '%s [%s] => Request %s %s %s on pid %d' % (
prefix,
code,
str(request.host),
request.method,
request.path,
... | [
"def",
"responseInColor",
"(",
"request",
",",
"status",
",",
"headers",
",",
"prefix",
"=",
"'Response'",
",",
"opts",
"=",
"None",
")",
":",
"code",
",",
"message",
"=",
"status",
".",
"split",
"(",
"None",
",",
"1",
")",
"message",
"=",
"'%s [%s] =>... | Prints the response info in color | [
"Prints",
"the",
"response",
"info",
"in",
"color"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/utils/__init__.py#L27-L44 |
18,487 | hendrix/hendrix | hendrix/deploy/cache.py | HendrixDeployCache.addLocalCacheService | def addLocalCacheService(self):
"adds a CacheService to the instatiated HendrixService"
_cache = self.getCacheService()
_cache.setName('cache_proxy')
_cache.setServiceParent(self.hendrix) | python | def addLocalCacheService(self):
"adds a CacheService to the instatiated HendrixService"
_cache = self.getCacheService()
_cache.setName('cache_proxy')
_cache.setServiceParent(self.hendrix) | [
"def",
"addLocalCacheService",
"(",
"self",
")",
":",
"_cache",
"=",
"self",
".",
"getCacheService",
"(",
")",
"_cache",
".",
"setName",
"(",
"'cache_proxy'",
")",
"_cache",
".",
"setServiceParent",
"(",
"self",
".",
"hendrix",
")"
] | adds a CacheService to the instatiated HendrixService | [
"adds",
"a",
"CacheService",
"to",
"the",
"instatiated",
"HendrixService"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/cache.py#L24-L28 |
18,488 | hendrix/hendrix | hendrix/deploy/cache.py | HendrixDeployCache.addGlobalServices | def addGlobalServices(self):
"""
This is where we put service that we don't want to be duplicated on
worker subprocesses
"""
if self.options.get('global_cache') and self.options.get('cache'):
# only add the cache service here if the global_cache and cache
... | python | def addGlobalServices(self):
"""
This is where we put service that we don't want to be duplicated on
worker subprocesses
"""
if self.options.get('global_cache') and self.options.get('cache'):
# only add the cache service here if the global_cache and cache
... | [
"def",
"addGlobalServices",
"(",
"self",
")",
":",
"if",
"self",
".",
"options",
".",
"get",
"(",
"'global_cache'",
")",
"and",
"self",
".",
"options",
".",
"get",
"(",
"'cache'",
")",
":",
"# only add the cache service here if the global_cache and cache",
"# opti... | This is where we put service that we don't want to be duplicated on
worker subprocesses | [
"This",
"is",
"where",
"we",
"put",
"service",
"that",
"we",
"don",
"t",
"want",
"to",
"be",
"duplicated",
"on",
"worker",
"subprocesses"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/deploy/cache.py#L38-L47 |
18,489 | hendrix/hendrix | hendrix/facilities/resources.py | HendrixResource.putNamedChild | def putNamedChild(self, res):
"""
putNamedChild takes either an instance of hendrix.contrib.NamedResource
or any resource.Resource with a "namespace" attribute as a means of
allowing application level control of resource namespacing.
if a child is already found at an existing pa... | python | def putNamedChild(self, res):
"""
putNamedChild takes either an instance of hendrix.contrib.NamedResource
or any resource.Resource with a "namespace" attribute as a means of
allowing application level control of resource namespacing.
if a child is already found at an existing pa... | [
"def",
"putNamedChild",
"(",
"self",
",",
"res",
")",
":",
"try",
":",
"EmptyResource",
"=",
"resource",
".",
"Resource",
"namespace",
"=",
"res",
".",
"namespace",
"parts",
"=",
"namespace",
".",
"strip",
"(",
"'/'",
")",
".",
"split",
"(",
"'/'",
")"... | putNamedChild takes either an instance of hendrix.contrib.NamedResource
or any resource.Resource with a "namespace" attribute as a means of
allowing application level control of resource namespacing.
if a child is already found at an existing path,
resources with paths that are children... | [
"putNamedChild",
"takes",
"either",
"an",
"instance",
"of",
"hendrix",
".",
"contrib",
".",
"NamedResource",
"or",
"any",
"resource",
".",
"Resource",
"with",
"a",
"namespace",
"attribute",
"as",
"a",
"means",
"of",
"allowing",
"application",
"level",
"control",... | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/facilities/resources.py#L59-L105 |
18,490 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | send_json_message | def send_json_message(address, message, **kwargs):
"""
a shortcut for message sending
"""
data = {
'message': message,
}
if not kwargs.get('subject_id'):
data['subject_id'] = address
data.update(kwargs)
hxdispatcher.send(address, data) | python | def send_json_message(address, message, **kwargs):
"""
a shortcut for message sending
"""
data = {
'message': message,
}
if not kwargs.get('subject_id'):
data['subject_id'] = address
data.update(kwargs)
hxdispatcher.send(address, data) | [
"def",
"send_json_message",
"(",
"address",
",",
"message",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'message'",
":",
"message",
",",
"}",
"if",
"not",
"kwargs",
".",
"get",
"(",
"'subject_id'",
")",
":",
"data",
"[",
"'subject_id'",
"]",
... | a shortcut for message sending | [
"a",
"shortcut",
"for",
"message",
"sending"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L125-L139 |
18,491 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | send_callback_json_message | def send_callback_json_message(value, *args, **kwargs):
"""
useful for sending messages from callbacks as it puts the
result of the callback in the dict for serialization
"""
if value:
kwargs['result'] = value
send_json_message(args[0], args[1], **kwargs)
return value | python | def send_callback_json_message(value, *args, **kwargs):
"""
useful for sending messages from callbacks as it puts the
result of the callback in the dict for serialization
"""
if value:
kwargs['result'] = value
send_json_message(args[0], args[1], **kwargs)
return value | [
"def",
"send_callback_json_message",
"(",
"value",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"value",
":",
"kwargs",
"[",
"'result'",
"]",
"=",
"value",
"send_json_message",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
","... | useful for sending messages from callbacks as it puts the
result of the callback in the dict for serialization | [
"useful",
"for",
"sending",
"messages",
"from",
"callbacks",
"as",
"it",
"puts",
"the",
"result",
"of",
"the",
"callback",
"in",
"the",
"dict",
"for",
"serialization"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L142-L153 |
18,492 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | RecipientManager.send | def send(self, message): # usually a json string...
"""
sends whatever it is to each transport
"""
for transport in self.transports.values():
transport.protocol.sendMessage(message) | python | def send(self, message): # usually a json string...
"""
sends whatever it is to each transport
"""
for transport in self.transports.values():
transport.protocol.sendMessage(message) | [
"def",
"send",
"(",
"self",
",",
"message",
")",
":",
"# usually a json string...",
"for",
"transport",
"in",
"self",
".",
"transports",
".",
"values",
"(",
")",
":",
"transport",
".",
"protocol",
".",
"sendMessage",
"(",
"message",
")"
] | sends whatever it is to each transport | [
"sends",
"whatever",
"it",
"is",
"to",
"each",
"transport"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L34-L39 |
18,493 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | RecipientManager.remove | def remove(self, transport):
"""
removes a transport if a member of this group
"""
if transport.uid in self.transports:
del (self.transports[transport.uid]) | python | def remove(self, transport):
"""
removes a transport if a member of this group
"""
if transport.uid in self.transports:
del (self.transports[transport.uid]) | [
"def",
"remove",
"(",
"self",
",",
"transport",
")",
":",
"if",
"transport",
".",
"uid",
"in",
"self",
".",
"transports",
":",
"del",
"(",
"self",
".",
"transports",
"[",
"transport",
".",
"uid",
"]",
")"
] | removes a transport if a member of this group | [
"removes",
"a",
"transport",
"if",
"a",
"member",
"of",
"this",
"group"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L41-L46 |
18,494 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | MessageDispatcher.add | def add(self, transport, address=None):
"""
add a new recipient to be addressable by this MessageDispatcher
generate a new uuid address if one is not specified
"""
if not address:
address = str(uuid.uuid1())
if address in self.recipients:
... | python | def add(self, transport, address=None):
"""
add a new recipient to be addressable by this MessageDispatcher
generate a new uuid address if one is not specified
"""
if not address:
address = str(uuid.uuid1())
if address in self.recipients:
... | [
"def",
"add",
"(",
"self",
",",
"transport",
",",
"address",
"=",
"None",
")",
":",
"if",
"not",
"address",
":",
"address",
"=",
"str",
"(",
"uuid",
".",
"uuid1",
"(",
")",
")",
"if",
"address",
"in",
"self",
".",
"recipients",
":",
"self",
".",
... | add a new recipient to be addressable by this MessageDispatcher
generate a new uuid address if one is not specified | [
"add",
"a",
"new",
"recipient",
"to",
"be",
"addressable",
"by",
"this",
"MessageDispatcher",
"generate",
"a",
"new",
"uuid",
"address",
"if",
"one",
"is",
"not",
"specified"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L69-L83 |
18,495 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | MessageDispatcher.remove | def remove(self, transport):
"""
removes a transport from all channels to which it belongs.
"""
recipients = copy.copy(self.recipients)
for address, recManager in recipients.items():
recManager.remove(transport)
if not len(recManager.transports):
... | python | def remove(self, transport):
"""
removes a transport from all channels to which it belongs.
"""
recipients = copy.copy(self.recipients)
for address, recManager in recipients.items():
recManager.remove(transport)
if not len(recManager.transports):
... | [
"def",
"remove",
"(",
"self",
",",
"transport",
")",
":",
"recipients",
"=",
"copy",
".",
"copy",
"(",
"self",
".",
"recipients",
")",
"for",
"address",
",",
"recManager",
"in",
"recipients",
".",
"items",
"(",
")",
":",
"recManager",
".",
"remove",
"(... | removes a transport from all channels to which it belongs. | [
"removes",
"a",
"transport",
"from",
"all",
"channels",
"to",
"which",
"it",
"belongs",
"."
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L85-L93 |
18,496 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | MessageDispatcher.send | def send(self, address, data_dict):
"""
address can either be a string or a list of strings
data_dict gets sent along as is and could contain anything
"""
if type(address) == list:
recipients = [self.recipients.get(rec) for rec in address]
else:
... | python | def send(self, address, data_dict):
"""
address can either be a string or a list of strings
data_dict gets sent along as is and could contain anything
"""
if type(address) == list:
recipients = [self.recipients.get(rec) for rec in address]
else:
... | [
"def",
"send",
"(",
"self",
",",
"address",
",",
"data_dict",
")",
":",
"if",
"type",
"(",
"address",
")",
"==",
"list",
":",
"recipients",
"=",
"[",
"self",
".",
"recipients",
".",
"get",
"(",
"rec",
")",
"for",
"rec",
"in",
"address",
"]",
"else"... | address can either be a string or a list of strings
data_dict gets sent along as is and could contain anything | [
"address",
"can",
"either",
"be",
"a",
"string",
"or",
"a",
"list",
"of",
"strings"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L95-L110 |
18,497 | hendrix/hendrix | hendrix/contrib/concurrency/messaging.py | MessageDispatcher.subscribe | def subscribe(self, transport, data):
"""
adds a transport to a channel
"""
self.add(transport, address=data.get('hx_subscribe').encode())
self.send(
data['hx_subscribe'],
{'message': "%r is listening" % transport}
) | python | def subscribe(self, transport, data):
"""
adds a transport to a channel
"""
self.add(transport, address=data.get('hx_subscribe').encode())
self.send(
data['hx_subscribe'],
{'message': "%r is listening" % transport}
) | [
"def",
"subscribe",
"(",
"self",
",",
"transport",
",",
"data",
")",
":",
"self",
".",
"add",
"(",
"transport",
",",
"address",
"=",
"data",
".",
"get",
"(",
"'hx_subscribe'",
")",
".",
"encode",
"(",
")",
")",
"self",
".",
"send",
"(",
"data",
"["... | adds a transport to a channel | [
"adds",
"a",
"transport",
"to",
"a",
"channel"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/concurrency/messaging.py#L112-L122 |
18,498 | hendrix/hendrix | hendrix/options.py | cleanOptions | def cleanOptions(options):
"""
Takes an options dict and returns a tuple containing the daemonize boolean,
the reload boolean, and the parsed list of cleaned options as would be
expected to be passed to hx
"""
_reload = options.pop('reload')
dev = options.pop('dev')
opts = []
store_t... | python | def cleanOptions(options):
"""
Takes an options dict and returns a tuple containing the daemonize boolean,
the reload boolean, and the parsed list of cleaned options as would be
expected to be passed to hx
"""
_reload = options.pop('reload')
dev = options.pop('dev')
opts = []
store_t... | [
"def",
"cleanOptions",
"(",
"options",
")",
":",
"_reload",
"=",
"options",
".",
"pop",
"(",
"'reload'",
")",
"dev",
"=",
"options",
".",
"pop",
"(",
"'dev'",
")",
"opts",
"=",
"[",
"]",
"store_true",
"=",
"[",
"'--nocache'",
",",
"'--global_cache'",
"... | Takes an options dict and returns a tuple containing the daemonize boolean,
the reload boolean, and the parsed list of cleaned options as would be
expected to be passed to hx | [
"Takes",
"an",
"options",
"dict",
"and",
"returns",
"a",
"tuple",
"containing",
"the",
"daemonize",
"boolean",
"the",
"reload",
"boolean",
"and",
"the",
"parsed",
"list",
"of",
"cleaned",
"options",
"as",
"would",
"be",
"expected",
"to",
"be",
"passed",
"to"... | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/options.py#L7-L26 |
18,499 | hendrix/hendrix | hendrix/options.py | options | def options(argv=[]):
"""
A helper function that returns a dictionary of the default key-values pairs
"""
parser = HendrixOptionParser
parsed_args = parser.parse_args(argv)
return vars(parsed_args[0]) | python | def options(argv=[]):
"""
A helper function that returns a dictionary of the default key-values pairs
"""
parser = HendrixOptionParser
parsed_args = parser.parse_args(argv)
return vars(parsed_args[0]) | [
"def",
"options",
"(",
"argv",
"=",
"[",
"]",
")",
":",
"parser",
"=",
"HendrixOptionParser",
"parsed_args",
"=",
"parser",
".",
"parse_args",
"(",
"argv",
")",
"return",
"vars",
"(",
"parsed_args",
"[",
"0",
"]",
")"
] | A helper function that returns a dictionary of the default key-values pairs | [
"A",
"helper",
"function",
"that",
"returns",
"a",
"dictionary",
"of",
"the",
"default",
"key",
"-",
"values",
"pairs"
] | 175af011a7e5822b772bfec0e11a46466bb8688d | https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/options.py#L195-L201 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.