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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1,100 | simonvh/genomepy | genomepy/functions.py | Genome.get_random_sequences | def get_random_sequences(self, n=10, length=200, chroms=None, max_n=0.1):
"""Return random genomic sequences.
Parameters
----------
n : int , optional
Number of sequences to return.
length : int , optional
Length of sequences to return.
chroms :... | python | def get_random_sequences(self, n=10, length=200, chroms=None, max_n=0.1):
"""Return random genomic sequences.
Parameters
----------
n : int , optional
Number of sequences to return.
length : int , optional
Length of sequences to return.
chroms :... | [
"def",
"get_random_sequences",
"(",
"self",
",",
"n",
"=",
"10",
",",
"length",
"=",
"200",
",",
"chroms",
"=",
"None",
",",
"max_n",
"=",
"0.1",
")",
":",
"retries",
"=",
"100",
"cutoff",
"=",
"length",
"*",
"max_n",
"if",
"not",
"chroms",
":",
"c... | Return random genomic sequences.
Parameters
----------
n : int , optional
Number of sequences to return.
length : int , optional
Length of sequences to return.
chroms : list , optional
Return sequences only from these chromosomes.
m... | [
"Return",
"random",
"genomic",
"sequences",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/functions.py#L455-L512 |
1,101 | simonvh/genomepy | genomepy/cli.py | search | def search(term, provider=None):
"""Search for genomes that contain TERM in their name or description."""
for row in genomepy.search(term, provider):
print("\t".join([x.decode('utf-8', 'ignore') for x in row])) | python | def search(term, provider=None):
"""Search for genomes that contain TERM in their name or description."""
for row in genomepy.search(term, provider):
print("\t".join([x.decode('utf-8', 'ignore') for x in row])) | [
"def",
"search",
"(",
"term",
",",
"provider",
"=",
"None",
")",
":",
"for",
"row",
"in",
"genomepy",
".",
"search",
"(",
"term",
",",
"provider",
")",
":",
"print",
"(",
"\"\\t\"",
".",
"join",
"(",
"[",
"x",
".",
"decode",
"(",
"'utf-8'",
",",
... | Search for genomes that contain TERM in their name or description. | [
"Search",
"for",
"genomes",
"that",
"contain",
"TERM",
"in",
"their",
"name",
"or",
"description",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/cli.py#L20-L23 |
1,102 | simonvh/genomepy | genomepy/cli.py | install | def install(name, provider, genome_dir, localname, mask, regex, match, annotation):
"""Install genome NAME from provider PROVIDER in directory GENOME_DIR."""
genomepy.install_genome(
name, provider, genome_dir=genome_dir, localname=localname, mask=mask,
regex=regex, invert_match=not(mat... | python | def install(name, provider, genome_dir, localname, mask, regex, match, annotation):
"""Install genome NAME from provider PROVIDER in directory GENOME_DIR."""
genomepy.install_genome(
name, provider, genome_dir=genome_dir, localname=localname, mask=mask,
regex=regex, invert_match=not(mat... | [
"def",
"install",
"(",
"name",
",",
"provider",
",",
"genome_dir",
",",
"localname",
",",
"mask",
",",
"regex",
",",
"match",
",",
"annotation",
")",
":",
"genomepy",
".",
"install_genome",
"(",
"name",
",",
"provider",
",",
"genome_dir",
"=",
"genome_dir"... | Install genome NAME from provider PROVIDER in directory GENOME_DIR. | [
"Install",
"genome",
"NAME",
"from",
"provider",
"PROVIDER",
"in",
"directory",
"GENOME_DIR",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/cli.py#L34-L38 |
1,103 | simonvh/genomepy | genomepy/utils.py | generate_gap_bed | def generate_gap_bed(fname, outname):
""" Generate a BED file with gap locations.
Parameters
----------
fname : str
Filename of input FASTA file.
outname : str
Filename of output BED file.
"""
f = Fasta(fname)
with open(outname, "w") as bed:
for chrom in f.keys... | python | def generate_gap_bed(fname, outname):
""" Generate a BED file with gap locations.
Parameters
----------
fname : str
Filename of input FASTA file.
outname : str
Filename of output BED file.
"""
f = Fasta(fname)
with open(outname, "w") as bed:
for chrom in f.keys... | [
"def",
"generate_gap_bed",
"(",
"fname",
",",
"outname",
")",
":",
"f",
"=",
"Fasta",
"(",
"fname",
")",
"with",
"open",
"(",
"outname",
",",
"\"w\"",
")",
"as",
"bed",
":",
"for",
"chrom",
"in",
"f",
".",
"keys",
"(",
")",
":",
"for",
"m",
"in",... | Generate a BED file with gap locations.
Parameters
----------
fname : str
Filename of input FASTA file.
outname : str
Filename of output BED file. | [
"Generate",
"a",
"BED",
"file",
"with",
"gap",
"locations",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/utils.py#L10-L25 |
1,104 | simonvh/genomepy | genomepy/utils.py | generate_sizes | def generate_sizes(name, genome_dir):
"""Generate a sizes file with length of sequences in FASTA file."""
fa = os.path.join(genome_dir, name, "{}.fa".format(name))
sizes = fa + ".sizes"
g = Fasta(fa)
with open(sizes, "w") as f:
for seqname in g.keys():
f.write("{}\t{}\n".format(s... | python | def generate_sizes(name, genome_dir):
"""Generate a sizes file with length of sequences in FASTA file."""
fa = os.path.join(genome_dir, name, "{}.fa".format(name))
sizes = fa + ".sizes"
g = Fasta(fa)
with open(sizes, "w") as f:
for seqname in g.keys():
f.write("{}\t{}\n".format(s... | [
"def",
"generate_sizes",
"(",
"name",
",",
"genome_dir",
")",
":",
"fa",
"=",
"os",
".",
"path",
".",
"join",
"(",
"genome_dir",
",",
"name",
",",
"\"{}.fa\"",
".",
"format",
"(",
"name",
")",
")",
"sizes",
"=",
"fa",
"+",
"\".sizes\"",
"g",
"=",
"... | Generate a sizes file with length of sequences in FASTA file. | [
"Generate",
"a",
"sizes",
"file",
"with",
"length",
"of",
"sequences",
"in",
"FASTA",
"file",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/utils.py#L27-L34 |
1,105 | simonvh/genomepy | genomepy/utils.py | filter_fasta | def filter_fasta(infa, outfa, regex=".*", v=False, force=False):
"""Filter fasta file based on regex.
Parameters
----------
infa : str
Filename of input fasta file.
outfa : str
Filename of output fasta file. Cannot be the same as infa.
regex : str, optional
Regular... | python | def filter_fasta(infa, outfa, regex=".*", v=False, force=False):
"""Filter fasta file based on regex.
Parameters
----------
infa : str
Filename of input fasta file.
outfa : str
Filename of output fasta file. Cannot be the same as infa.
regex : str, optional
Regular... | [
"def",
"filter_fasta",
"(",
"infa",
",",
"outfa",
",",
"regex",
"=",
"\".*\"",
",",
"v",
"=",
"False",
",",
"force",
"=",
"False",
")",
":",
"if",
"infa",
"==",
"outfa",
":",
"raise",
"ValueError",
"(",
"\"Input and output FASTA are the same file.\"",
")",
... | Filter fasta file based on regex.
Parameters
----------
infa : str
Filename of input fasta file.
outfa : str
Filename of output fasta file. Cannot be the same as infa.
regex : str, optional
Regular expression used for selecting sequences.
v : bool, optional
... | [
"Filter",
"fasta",
"file",
"based",
"on",
"regex",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/utils.py#L36-L89 |
1,106 | simonvh/genomepy | genomepy/utils.py | cmd_ok | def cmd_ok(cmd):
"""Returns True if cmd can be run.
"""
try:
sp.check_call(cmd, stderr=sp.PIPE, stdout=sp.PIPE)
except sp.CalledProcessError:
# bwa gives return code of 1 with no argument
pass
except:
sys.stderr.write("{} not found, skipping\n".format(cmd))
r... | python | def cmd_ok(cmd):
"""Returns True if cmd can be run.
"""
try:
sp.check_call(cmd, stderr=sp.PIPE, stdout=sp.PIPE)
except sp.CalledProcessError:
# bwa gives return code of 1 with no argument
pass
except:
sys.stderr.write("{} not found, skipping\n".format(cmd))
r... | [
"def",
"cmd_ok",
"(",
"cmd",
")",
":",
"try",
":",
"sp",
".",
"check_call",
"(",
"cmd",
",",
"stderr",
"=",
"sp",
".",
"PIPE",
",",
"stdout",
"=",
"sp",
".",
"PIPE",
")",
"except",
"sp",
".",
"CalledProcessError",
":",
"# bwa gives return code of 1 with ... | Returns True if cmd can be run. | [
"Returns",
"True",
"if",
"cmd",
"can",
"be",
"run",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/utils.py#L101-L112 |
1,107 | simonvh/genomepy | genomepy/utils.py | run_index_cmd | def run_index_cmd(name, cmd):
"""Run command, show errors if the returncode is non-zero."""
sys.stderr.write("Creating {} index...\n".format(name))
# Create index
p = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
sys.stde... | python | def run_index_cmd(name, cmd):
"""Run command, show errors if the returncode is non-zero."""
sys.stderr.write("Creating {} index...\n".format(name))
# Create index
p = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
sys.stde... | [
"def",
"run_index_cmd",
"(",
"name",
",",
"cmd",
")",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"Creating {} index...\\n\"",
".",
"format",
"(",
"name",
")",
")",
"# Create index",
"p",
"=",
"sp",
".",
"Popen",
"(",
"cmd",
",",
"shell",
"=",
"Tru... | Run command, show errors if the returncode is non-zero. | [
"Run",
"command",
"show",
"errors",
"if",
"the",
"returncode",
"is",
"non",
"-",
"zero",
"."
] | abace2366511dbe855fe1430b1f7d9ec4cbf6d29 | https://github.com/simonvh/genomepy/blob/abace2366511dbe855fe1430b1f7d9ec4cbf6d29/genomepy/utils.py#L114-L123 |
1,108 | peo3/cgroup-utils | cgutils/cgroup.py | scan_cgroups | def scan_cgroups(subsys_name, filters=list()):
"""
It returns a control group hierarchy which belong to the subsys_name.
When collecting cgroups, filters are applied to the cgroups. See pydoc
of apply_filters method of CGroup for more information about the filters.
"""
status = SubsystemStatus()... | python | def scan_cgroups(subsys_name, filters=list()):
"""
It returns a control group hierarchy which belong to the subsys_name.
When collecting cgroups, filters are applied to the cgroups. See pydoc
of apply_filters method of CGroup for more information about the filters.
"""
status = SubsystemStatus()... | [
"def",
"scan_cgroups",
"(",
"subsys_name",
",",
"filters",
"=",
"list",
"(",
")",
")",
":",
"status",
"=",
"SubsystemStatus",
"(",
")",
"if",
"subsys_name",
"not",
"in",
"status",
".",
"get_all",
"(",
")",
":",
"raise",
"NoSuchSubsystemError",
"(",
"\"No s... | It returns a control group hierarchy which belong to the subsys_name.
When collecting cgroups, filters are applied to the cgroups. See pydoc
of apply_filters method of CGroup for more information about the filters. | [
"It",
"returns",
"a",
"control",
"group",
"hierarchy",
"which",
"belong",
"to",
"the",
"subsys_name",
".",
"When",
"collecting",
"cgroups",
"filters",
"are",
"applied",
"to",
"the",
"cgroups",
".",
"See",
"pydoc",
"of",
"apply_filters",
"method",
"of",
"CGroup... | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L917-L935 |
1,109 | peo3/cgroup-utils | cgutils/cgroup.py | walk_cgroups | def walk_cgroups(cgroup, action, opaque):
"""
The function applies the action function with the opaque object
to each control group under the cgroup recursively.
"""
action(cgroup, opaque)
for child in cgroup.childs:
walk_cgroups(child, action, opaque) | python | def walk_cgroups(cgroup, action, opaque):
"""
The function applies the action function with the opaque object
to each control group under the cgroup recursively.
"""
action(cgroup, opaque)
for child in cgroup.childs:
walk_cgroups(child, action, opaque) | [
"def",
"walk_cgroups",
"(",
"cgroup",
",",
"action",
",",
"opaque",
")",
":",
"action",
"(",
"cgroup",
",",
"opaque",
")",
"for",
"child",
"in",
"cgroup",
".",
"childs",
":",
"walk_cgroups",
"(",
"child",
",",
"action",
",",
"opaque",
")"
] | The function applies the action function with the opaque object
to each control group under the cgroup recursively. | [
"The",
"function",
"applies",
"the",
"action",
"function",
"with",
"the",
"opaque",
"object",
"to",
"each",
"control",
"group",
"under",
"the",
"cgroup",
"recursively",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L938-L945 |
1,110 | peo3/cgroup-utils | cgutils/cgroup.py | get_cgroup | def get_cgroup(fullpath):
"""
It returns a CGroup object which is pointed by the fullpath.
"""
# Canonicalize symbolic links
fullpath = os.path.realpath(fullpath)
status = SubsystemStatus()
name = None
for name, path in status.paths.items():
if path in fullpath:
brea... | python | def get_cgroup(fullpath):
"""
It returns a CGroup object which is pointed by the fullpath.
"""
# Canonicalize symbolic links
fullpath = os.path.realpath(fullpath)
status = SubsystemStatus()
name = None
for name, path in status.paths.items():
if path in fullpath:
brea... | [
"def",
"get_cgroup",
"(",
"fullpath",
")",
":",
"# Canonicalize symbolic links",
"fullpath",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"fullpath",
")",
"status",
"=",
"SubsystemStatus",
"(",
")",
"name",
"=",
"None",
"for",
"name",
",",
"path",
"in",
"... | It returns a CGroup object which is pointed by the fullpath. | [
"It",
"returns",
"a",
"CGroup",
"object",
"which",
"is",
"pointed",
"by",
"the",
"fullpath",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L948-L964 |
1,111 | peo3/cgroup-utils | cgutils/cgroup.py | RdmaStat.parse | def parse(content):
""" Parse rdma.curren and rdma.max
Example contents:
mlx4_0 hca_handle=2 hca_object=2000
ocrdma1 hca_handle=3 hca_object=max
>>> RdmaStat.parse("mlx4_0 hca_handle=2 hca_object=2000\\nocrdma1 hca_handle=3 hca_object=max")
{'mlx4_0': {'hca_handle':... | python | def parse(content):
""" Parse rdma.curren and rdma.max
Example contents:
mlx4_0 hca_handle=2 hca_object=2000
ocrdma1 hca_handle=3 hca_object=max
>>> RdmaStat.parse("mlx4_0 hca_handle=2 hca_object=2000\\nocrdma1 hca_handle=3 hca_object=max")
{'mlx4_0': {'hca_handle':... | [
"def",
"parse",
"(",
"content",
")",
":",
"ret",
"=",
"{",
"}",
"lines",
"=",
"content",
".",
"split",
"(",
"'\\n'",
")",
"for",
"line",
"in",
"lines",
":",
"m",
"=",
"RdmaStat",
".",
"_RE",
".",
"match",
"(",
"line",
")",
"if",
"m",
"is",
"Non... | Parse rdma.curren and rdma.max
Example contents:
mlx4_0 hca_handle=2 hca_object=2000
ocrdma1 hca_handle=3 hca_object=max
>>> RdmaStat.parse("mlx4_0 hca_handle=2 hca_object=2000\\nocrdma1 hca_handle=3 hca_object=max")
{'mlx4_0': {'hca_handle': 2, 'hca_object': 2000}, 'ocrdma... | [
"Parse",
"rdma",
".",
"curren",
"and",
"rdma",
".",
"max"
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L313-L335 |
1,112 | peo3/cgroup-utils | cgutils/cgroup.py | CGroup.apply_filters | def apply_filters(self, filters):
"""
It applies a specified filters. The filters are used to reduce the control groups
which are accessed by get_confgs, get_stats, and get_defaults methods.
"""
_configs = self.configs
_stats = self.stats
self.configs = {}
... | python | def apply_filters(self, filters):
"""
It applies a specified filters. The filters are used to reduce the control groups
which are accessed by get_confgs, get_stats, and get_defaults methods.
"""
_configs = self.configs
_stats = self.stats
self.configs = {}
... | [
"def",
"apply_filters",
"(",
"self",
",",
"filters",
")",
":",
"_configs",
"=",
"self",
".",
"configs",
"_stats",
"=",
"self",
".",
"stats",
"self",
".",
"configs",
"=",
"{",
"}",
"self",
".",
"stats",
"=",
"{",
"}",
"for",
"f",
"in",
"filters",
":... | It applies a specified filters. The filters are used to reduce the control groups
which are accessed by get_confgs, get_stats, and get_defaults methods. | [
"It",
"applies",
"a",
"specified",
"filters",
".",
"The",
"filters",
"are",
"used",
"to",
"reduce",
"the",
"control",
"groups",
"which",
"are",
"accessed",
"by",
"get_confgs",
"get_stats",
"and",
"get_defaults",
"methods",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L722-L737 |
1,113 | peo3/cgroup-utils | cgutils/cgroup.py | CGroup.get_configs | def get_configs(self):
"""
It returns a name and a current value pairs of control files
which are categorised in the configs group.
"""
configs = {}
for name, default in self.configs.items():
cls = default.__class__
path = self.paths[name]
... | python | def get_configs(self):
"""
It returns a name and a current value pairs of control files
which are categorised in the configs group.
"""
configs = {}
for name, default in self.configs.items():
cls = default.__class__
path = self.paths[name]
... | [
"def",
"get_configs",
"(",
"self",
")",
":",
"configs",
"=",
"{",
"}",
"for",
"name",
",",
"default",
"in",
"self",
".",
"configs",
".",
"items",
"(",
")",
":",
"cls",
"=",
"default",
".",
"__class__",
"path",
"=",
"self",
".",
"paths",
"[",
"name"... | It returns a name and a current value pairs of control files
which are categorised in the configs group. | [
"It",
"returns",
"a",
"name",
"and",
"a",
"current",
"value",
"pairs",
"of",
"control",
"files",
"which",
"are",
"categorised",
"in",
"the",
"configs",
"group",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L739-L759 |
1,114 | peo3/cgroup-utils | cgutils/cgroup.py | CGroup.get_stats | def get_stats(self):
"""
It returns a name and a value pairs of control files
which are categorised in the stats group.
"""
stats = {}
for name, cls in self.stats.items():
path = self.paths[name]
if os.path.exists(path):
try:
... | python | def get_stats(self):
"""
It returns a name and a value pairs of control files
which are categorised in the stats group.
"""
stats = {}
for name, cls in self.stats.items():
path = self.paths[name]
if os.path.exists(path):
try:
... | [
"def",
"get_stats",
"(",
"self",
")",
":",
"stats",
"=",
"{",
"}",
"for",
"name",
",",
"cls",
"in",
"self",
".",
"stats",
".",
"items",
"(",
")",
":",
"path",
"=",
"self",
".",
"paths",
"[",
"name",
"]",
"if",
"os",
".",
"path",
".",
"exists",
... | It returns a name and a value pairs of control files
which are categorised in the stats group. | [
"It",
"returns",
"a",
"name",
"and",
"a",
"value",
"pairs",
"of",
"control",
"files",
"which",
"are",
"categorised",
"in",
"the",
"stats",
"group",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L768-L791 |
1,115 | peo3/cgroup-utils | cgutils/cgroup.py | CGroup.update | def update(self):
"""It updates process information of the cgroup."""
pids = fileops.readlines(self.paths['cgroup.procs'])
self.pids = [int(pid) for pid in pids if pid != '']
self.n_procs = len(pids) | python | def update(self):
"""It updates process information of the cgroup."""
pids = fileops.readlines(self.paths['cgroup.procs'])
self.pids = [int(pid) for pid in pids if pid != '']
self.n_procs = len(pids) | [
"def",
"update",
"(",
"self",
")",
":",
"pids",
"=",
"fileops",
".",
"readlines",
"(",
"self",
".",
"paths",
"[",
"'cgroup.procs'",
"]",
")",
"self",
".",
"pids",
"=",
"[",
"int",
"(",
"pid",
")",
"for",
"pid",
"in",
"pids",
"if",
"pid",
"!=",
"'... | It updates process information of the cgroup. | [
"It",
"updates",
"process",
"information",
"of",
"the",
"cgroup",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L793-L797 |
1,116 | peo3/cgroup-utils | cgutils/cgroup.py | EventListener.wait | def wait(self):
"""
It returns when an event which we have configured by set_threshold happens.
Note that it blocks until then.
"""
ret = os.read(self.event_fd, 64 / 8)
return struct.unpack('Q', ret) | python | def wait(self):
"""
It returns when an event which we have configured by set_threshold happens.
Note that it blocks until then.
"""
ret = os.read(self.event_fd, 64 / 8)
return struct.unpack('Q', ret) | [
"def",
"wait",
"(",
"self",
")",
":",
"ret",
"=",
"os",
".",
"read",
"(",
"self",
".",
"event_fd",
",",
"64",
"/",
"8",
")",
"return",
"struct",
".",
"unpack",
"(",
"'Q'",
",",
"ret",
")"
] | It returns when an event which we have configured by set_threshold happens.
Note that it blocks until then. | [
"It",
"returns",
"when",
"an",
"event",
"which",
"we",
"have",
"configured",
"by",
"set_threshold",
"happens",
".",
"Note",
"that",
"it",
"blocks",
"until",
"then",
"."
] | fd7e99f438ce334bac5669fba0d08a6502fd7a82 | https://github.com/peo3/cgroup-utils/blob/fd7e99f438ce334bac5669fba0d08a6502fd7a82/cgutils/cgroup.py#L887-L893 |
1,117 | peakwinter/python-nginx | nginx.py | dumpf | def dumpf(obj, path):
"""
Write an nginx configuration to file.
:param obj obj: nginx object (Conf, Server, Container)
:param str path: path to nginx configuration on disk
:returns: path the configuration was written to
"""
with open(path, 'w') as f:
dump(obj, f)
return path | python | def dumpf(obj, path):
"""
Write an nginx configuration to file.
:param obj obj: nginx object (Conf, Server, Container)
:param str path: path to nginx configuration on disk
:returns: path the configuration was written to
"""
with open(path, 'w') as f:
dump(obj, f)
return path | [
"def",
"dumpf",
"(",
"obj",
",",
"path",
")",
":",
"with",
"open",
"(",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"dump",
"(",
"obj",
",",
"f",
")",
"return",
"path"
] | Write an nginx configuration to file.
:param obj obj: nginx object (Conf, Server, Container)
:param str path: path to nginx configuration on disk
:returns: path the configuration was written to | [
"Write",
"an",
"nginx",
"configuration",
"to",
"file",
"."
] | 4ecd1cd2e1f11ffb633d188a578a004712eaae16 | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L581-L591 |
1,118 | peakwinter/python-nginx | nginx.py | Conf.as_strings | def as_strings(self):
"""Return the entire Conf as nginx config strings."""
ret = []
for x in self.children:
if isinstance(x, (Key, Comment)):
ret.append(x.as_strings)
else:
for y in x.as_strings:
ret.append(y)
i... | python | def as_strings(self):
"""Return the entire Conf as nginx config strings."""
ret = []
for x in self.children:
if isinstance(x, (Key, Comment)):
ret.append(x.as_strings)
else:
for y in x.as_strings:
ret.append(y)
i... | [
"def",
"as_strings",
"(",
"self",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"x",
"in",
"self",
".",
"children",
":",
"if",
"isinstance",
"(",
"x",
",",
"(",
"Key",
",",
"Comment",
")",
")",
":",
"ret",
".",
"append",
"(",
"x",
".",
"as_strings",
"... | Return the entire Conf as nginx config strings. | [
"Return",
"the",
"entire",
"Conf",
"as",
"nginx",
"config",
"strings",
"."
] | 4ecd1cd2e1f11ffb633d188a578a004712eaae16 | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L98-L109 |
1,119 | peakwinter/python-nginx | nginx.py | Container.as_list | def as_list(self):
"""Return all child objects in nested lists of strings."""
return [self.name, self.value, [x.as_list for x in self.children]] | python | def as_list(self):
"""Return all child objects in nested lists of strings."""
return [self.name, self.value, [x.as_list for x in self.children]] | [
"def",
"as_list",
"(",
"self",
")",
":",
"return",
"[",
"self",
".",
"name",
",",
"self",
".",
"value",
",",
"[",
"x",
".",
"as_list",
"for",
"x",
"in",
"self",
".",
"children",
"]",
"]"
] | Return all child objects in nested lists of strings. | [
"Return",
"all",
"child",
"objects",
"in",
"nested",
"lists",
"of",
"strings",
"."
] | 4ecd1cd2e1f11ffb633d188a578a004712eaae16 | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L190-L192 |
1,120 | peakwinter/python-nginx | nginx.py | Container.as_dict | def as_dict(self):
"""Return all child objects in nested dict."""
dicts = [x.as_dict for x in self.children]
return {'{0} {1}'.format(self.name, self.value): dicts} | python | def as_dict(self):
"""Return all child objects in nested dict."""
dicts = [x.as_dict for x in self.children]
return {'{0} {1}'.format(self.name, self.value): dicts} | [
"def",
"as_dict",
"(",
"self",
")",
":",
"dicts",
"=",
"[",
"x",
".",
"as_dict",
"for",
"x",
"in",
"self",
".",
"children",
"]",
"return",
"{",
"'{0} {1}'",
".",
"format",
"(",
"self",
".",
"name",
",",
"self",
".",
"value",
")",
":",
"dicts",
"}... | Return all child objects in nested dict. | [
"Return",
"all",
"child",
"objects",
"in",
"nested",
"dict",
"."
] | 4ecd1cd2e1f11ffb633d188a578a004712eaae16 | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L195-L198 |
1,121 | peakwinter/python-nginx | nginx.py | Container.as_strings | def as_strings(self):
"""Return the entire Container as nginx config strings."""
ret = []
container_title = (INDENT * self._depth)
container_title += '{0}{1} {{\n'.format(
self.name, (' {0}'.format(self.value) if self.value else '')
)
ret.append(container_titl... | python | def as_strings(self):
"""Return the entire Container as nginx config strings."""
ret = []
container_title = (INDENT * self._depth)
container_title += '{0}{1} {{\n'.format(
self.name, (' {0}'.format(self.value) if self.value else '')
)
ret.append(container_titl... | [
"def",
"as_strings",
"(",
"self",
")",
":",
"ret",
"=",
"[",
"]",
"container_title",
"=",
"(",
"INDENT",
"*",
"self",
".",
"_depth",
")",
"container_title",
"+=",
"'{0}{1} {{\\n'",
".",
"format",
"(",
"self",
".",
"name",
",",
"(",
"' {0}'",
".",
"form... | Return the entire Container as nginx config strings. | [
"Return",
"the",
"entire",
"Container",
"as",
"nginx",
"config",
"strings",
"."
] | 4ecd1cd2e1f11ffb633d188a578a004712eaae16 | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L201-L227 |
1,122 | peakwinter/python-nginx | nginx.py | Key.as_strings | def as_strings(self):
"""Return key as nginx config string."""
if self.value == '' or self.value is None:
return '{0};\n'.format(self.name)
if '"' not in self.value and (';' in self.value or '#' in self.value):
return '{0} "{1}";\n'.format(self.name, self.value)
r... | python | def as_strings(self):
"""Return key as nginx config string."""
if self.value == '' or self.value is None:
return '{0};\n'.format(self.name)
if '"' not in self.value and (';' in self.value or '#' in self.value):
return '{0} "{1}";\n'.format(self.name, self.value)
r... | [
"def",
"as_strings",
"(",
"self",
")",
":",
"if",
"self",
".",
"value",
"==",
"''",
"or",
"self",
".",
"value",
"is",
"None",
":",
"return",
"'{0};\\n'",
".",
"format",
"(",
"self",
".",
"name",
")",
"if",
"'\"'",
"not",
"in",
"self",
".",
"value",... | Return key as nginx config string. | [
"Return",
"key",
"as",
"nginx",
"config",
"string",
"."
] | 4ecd1cd2e1f11ffb633d188a578a004712eaae16 | https://github.com/peakwinter/python-nginx/blob/4ecd1cd2e1f11ffb633d188a578a004712eaae16/nginx.py#L390-L396 |
1,123 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | convert_aws_args | def convert_aws_args(aws_args):
"""Convert old style options into arguments to boto3.session.Session."""
if not isinstance(aws_args, dict):
raise errors.InvalidConfiguration(
'Elastic DocManager config option "aws" must be a dict'
)
old_session_kwargs = dict(
region="regi... | python | def convert_aws_args(aws_args):
"""Convert old style options into arguments to boto3.session.Session."""
if not isinstance(aws_args, dict):
raise errors.InvalidConfiguration(
'Elastic DocManager config option "aws" must be a dict'
)
old_session_kwargs = dict(
region="regi... | [
"def",
"convert_aws_args",
"(",
"aws_args",
")",
":",
"if",
"not",
"isinstance",
"(",
"aws_args",
",",
"dict",
")",
":",
"raise",
"errors",
".",
"InvalidConfiguration",
"(",
"'Elastic DocManager config option \"aws\" must be a dict'",
")",
"old_session_kwargs",
"=",
"... | Convert old style options into arguments to boto3.session.Session. | [
"Convert",
"old",
"style",
"options",
"into",
"arguments",
"to",
"boto3",
".",
"session",
".",
"Session",
"."
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L82-L99 |
1,124 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | DocManager._index_and_mapping | def _index_and_mapping(self, namespace):
"""Helper method for getting the index and type from a namespace."""
index, doc_type = namespace.split(".", 1)
return index.lower(), doc_type | python | def _index_and_mapping(self, namespace):
"""Helper method for getting the index and type from a namespace."""
index, doc_type = namespace.split(".", 1)
return index.lower(), doc_type | [
"def",
"_index_and_mapping",
"(",
"self",
",",
"namespace",
")",
":",
"index",
",",
"doc_type",
"=",
"namespace",
".",
"split",
"(",
"\".\"",
",",
"1",
")",
"return",
"index",
".",
"lower",
"(",
")",
",",
"doc_type"
] | Helper method for getting the index and type from a namespace. | [
"Helper",
"method",
"for",
"getting",
"the",
"index",
"and",
"type",
"from",
"a",
"namespace",
"."
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L226-L229 |
1,125 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | DocManager._stream_search | def _stream_search(self, *args, **kwargs):
"""Helper method for iterating over ES search results."""
for hit in scan(
self.elastic, query=kwargs.pop("body", None), scroll="10m", **kwargs
):
hit["_source"]["_id"] = hit["_id"]
yield hit["_source"] | python | def _stream_search(self, *args, **kwargs):
"""Helper method for iterating over ES search results."""
for hit in scan(
self.elastic, query=kwargs.pop("body", None), scroll="10m", **kwargs
):
hit["_source"]["_id"] = hit["_id"]
yield hit["_source"] | [
"def",
"_stream_search",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"hit",
"in",
"scan",
"(",
"self",
".",
"elastic",
",",
"query",
"=",
"kwargs",
".",
"pop",
"(",
"\"body\"",
",",
"None",
")",
",",
"scroll",
"=",
"\... | Helper method for iterating over ES search results. | [
"Helper",
"method",
"for",
"iterating",
"over",
"ES",
"search",
"results",
"."
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L458-L464 |
1,126 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | DocManager.search | def search(self, start_ts, end_ts):
"""Query Elasticsearch for documents in a time range.
This method is used to find documents that may be in conflict during
a rollback event in MongoDB.
"""
return self._stream_search(
index=self.meta_index_name,
body={"... | python | def search(self, start_ts, end_ts):
"""Query Elasticsearch for documents in a time range.
This method is used to find documents that may be in conflict during
a rollback event in MongoDB.
"""
return self._stream_search(
index=self.meta_index_name,
body={"... | [
"def",
"search",
"(",
"self",
",",
"start_ts",
",",
"end_ts",
")",
":",
"return",
"self",
".",
"_stream_search",
"(",
"index",
"=",
"self",
".",
"meta_index_name",
",",
"body",
"=",
"{",
"\"query\"",
":",
"{",
"\"range\"",
":",
"{",
"\"_ts\"",
":",
"{"... | Query Elasticsearch for documents in a time range.
This method is used to find documents that may be in conflict during
a rollback event in MongoDB. | [
"Query",
"Elasticsearch",
"for",
"documents",
"in",
"a",
"time",
"range",
"."
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L466-L475 |
1,127 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | DocManager.commit | def commit(self):
"""Send buffered requests and refresh all indexes."""
self.send_buffered_operations()
retry_until_ok(self.elastic.indices.refresh, index="") | python | def commit(self):
"""Send buffered requests and refresh all indexes."""
self.send_buffered_operations()
retry_until_ok(self.elastic.indices.refresh, index="") | [
"def",
"commit",
"(",
"self",
")",
":",
"self",
".",
"send_buffered_operations",
"(",
")",
"retry_until_ok",
"(",
"self",
".",
"elastic",
".",
"indices",
".",
"refresh",
",",
"index",
"=",
"\"\"",
")"
] | Send buffered requests and refresh all indexes. | [
"Send",
"buffered",
"requests",
"and",
"refresh",
"all",
"indexes",
"."
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L507-L510 |
1,128 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.add_upsert | def add_upsert(self, action, meta_action, doc_source, update_spec):
"""
Function which stores sources for "insert" actions
and decide if for "update" action has to add docs to
get source buffer
"""
# Whenever update_spec is provided to this method
# it means that... | python | def add_upsert(self, action, meta_action, doc_source, update_spec):
"""
Function which stores sources for "insert" actions
and decide if for "update" action has to add docs to
get source buffer
"""
# Whenever update_spec is provided to this method
# it means that... | [
"def",
"add_upsert",
"(",
"self",
",",
"action",
",",
"meta_action",
",",
"doc_source",
",",
"update_spec",
")",
":",
"# Whenever update_spec is provided to this method",
"# it means that doc source needs to be retrieved",
"# from Elasticsearch. It means also that source",
"# is no... | Function which stores sources for "insert" actions
and decide if for "update" action has to add docs to
get source buffer | [
"Function",
"which",
"stores",
"sources",
"for",
"insert",
"actions",
"and",
"decide",
"if",
"for",
"update",
"action",
"has",
"to",
"add",
"docs",
"to",
"get",
"source",
"buffer"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L559-L585 |
1,129 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.add_doc_to_update | def add_doc_to_update(self, action, update_spec, action_buffer_index):
"""
Prepare document for update based on Elasticsearch response.
Set flag if document needs to be retrieved from Elasticsearch
"""
doc = {
"_index": action["_index"],
"_type": action["... | python | def add_doc_to_update(self, action, update_spec, action_buffer_index):
"""
Prepare document for update based on Elasticsearch response.
Set flag if document needs to be retrieved from Elasticsearch
"""
doc = {
"_index": action["_index"],
"_type": action["... | [
"def",
"add_doc_to_update",
"(",
"self",
",",
"action",
",",
"update_spec",
",",
"action_buffer_index",
")",
":",
"doc",
"=",
"{",
"\"_index\"",
":",
"action",
"[",
"\"_index\"",
"]",
",",
"\"_type\"",
":",
"action",
"[",
"\"_type\"",
"]",
",",
"\"_id\"",
... | Prepare document for update based on Elasticsearch response.
Set flag if document needs to be retrieved from Elasticsearch | [
"Prepare",
"document",
"for",
"update",
"based",
"on",
"Elasticsearch",
"response",
".",
"Set",
"flag",
"if",
"document",
"needs",
"to",
"be",
"retrieved",
"from",
"Elasticsearch"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L587-L601 |
1,130 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.get_docs_sources_from_ES | def get_docs_sources_from_ES(self):
"""Get document sources using MGET elasticsearch API"""
docs = [doc for doc, _, _, get_from_ES in self.doc_to_update if get_from_ES]
if docs:
documents = self.docman.elastic.mget(body={"docs": docs}, realtime=True)
return iter(documents... | python | def get_docs_sources_from_ES(self):
"""Get document sources using MGET elasticsearch API"""
docs = [doc for doc, _, _, get_from_ES in self.doc_to_update if get_from_ES]
if docs:
documents = self.docman.elastic.mget(body={"docs": docs}, realtime=True)
return iter(documents... | [
"def",
"get_docs_sources_from_ES",
"(",
"self",
")",
":",
"docs",
"=",
"[",
"doc",
"for",
"doc",
",",
"_",
",",
"_",
",",
"get_from_ES",
"in",
"self",
".",
"doc_to_update",
"if",
"get_from_ES",
"]",
"if",
"docs",
":",
"documents",
"=",
"self",
".",
"do... | Get document sources using MGET elasticsearch API | [
"Get",
"document",
"sources",
"using",
"MGET",
"elasticsearch",
"API"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L620-L627 |
1,131 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.update_sources | def update_sources(self):
"""Update local sources based on response from Elasticsearch"""
ES_documents = self.get_docs_sources_from_ES()
for doc, update_spec, action_buffer_index, get_from_ES in self.doc_to_update:
if get_from_ES:
# Update source based on response fr... | python | def update_sources(self):
"""Update local sources based on response from Elasticsearch"""
ES_documents = self.get_docs_sources_from_ES()
for doc, update_spec, action_buffer_index, get_from_ES in self.doc_to_update:
if get_from_ES:
# Update source based on response fr... | [
"def",
"update_sources",
"(",
"self",
")",
":",
"ES_documents",
"=",
"self",
".",
"get_docs_sources_from_ES",
"(",
")",
"for",
"doc",
",",
"update_spec",
",",
"action_buffer_index",
",",
"get_from_ES",
"in",
"self",
".",
"doc_to_update",
":",
"if",
"get_from_ES"... | Update local sources based on response from Elasticsearch | [
"Update",
"local",
"sources",
"based",
"on",
"response",
"from",
"Elasticsearch"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L630-L683 |
1,132 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.add_to_sources | def add_to_sources(self, action, doc_source):
"""Store sources locally"""
mapping = self.sources.setdefault(action["_index"], {}).setdefault(
action["_type"], {}
)
mapping[action["_id"]] = doc_source | python | def add_to_sources(self, action, doc_source):
"""Store sources locally"""
mapping = self.sources.setdefault(action["_index"], {}).setdefault(
action["_type"], {}
)
mapping[action["_id"]] = doc_source | [
"def",
"add_to_sources",
"(",
"self",
",",
"action",
",",
"doc_source",
")",
":",
"mapping",
"=",
"self",
".",
"sources",
".",
"setdefault",
"(",
"action",
"[",
"\"_index\"",
"]",
",",
"{",
"}",
")",
".",
"setdefault",
"(",
"action",
"[",
"\"_type\"",
... | Store sources locally | [
"Store",
"sources",
"locally"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L690-L695 |
1,133 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.get_from_sources | def get_from_sources(self, index, doc_type, document_id):
"""Get source stored locally"""
return self.sources.get(index, {}).get(doc_type, {}).get(document_id, {}) | python | def get_from_sources(self, index, doc_type, document_id):
"""Get source stored locally"""
return self.sources.get(index, {}).get(doc_type, {}).get(document_id, {}) | [
"def",
"get_from_sources",
"(",
"self",
",",
"index",
",",
"doc_type",
",",
"document_id",
")",
":",
"return",
"self",
".",
"sources",
".",
"get",
"(",
"index",
",",
"{",
"}",
")",
".",
"get",
"(",
"doc_type",
",",
"{",
"}",
")",
".",
"get",
"(",
... | Get source stored locally | [
"Get",
"source",
"stored",
"locally"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L697-L699 |
1,134 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.clean_up | def clean_up(self):
"""Do clean-up before returning buffer"""
self.action_buffer = []
self.sources = {}
self.doc_to_get = {}
self.doc_to_update = [] | python | def clean_up(self):
"""Do clean-up before returning buffer"""
self.action_buffer = []
self.sources = {}
self.doc_to_get = {}
self.doc_to_update = [] | [
"def",
"clean_up",
"(",
"self",
")",
":",
"self",
".",
"action_buffer",
"=",
"[",
"]",
"self",
".",
"sources",
"=",
"{",
"}",
"self",
".",
"doc_to_get",
"=",
"{",
"}",
"self",
".",
"doc_to_update",
"=",
"[",
"]"
] | Do clean-up before returning buffer | [
"Do",
"clean",
"-",
"up",
"before",
"returning",
"buffer"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L705-L710 |
1,135 | yougov/elastic2-doc-manager | mongo_connector/doc_managers/elastic2_doc_manager.py | BulkBuffer.get_buffer | def get_buffer(self):
"""Get buffer which needs to be bulked to elasticsearch"""
# Get sources for documents which are in Elasticsearch
# and they are not in local buffer
if self.doc_to_update:
self.update_sources()
ES_buffer = self.action_buffer
self.clean_... | python | def get_buffer(self):
"""Get buffer which needs to be bulked to elasticsearch"""
# Get sources for documents which are in Elasticsearch
# and they are not in local buffer
if self.doc_to_update:
self.update_sources()
ES_buffer = self.action_buffer
self.clean_... | [
"def",
"get_buffer",
"(",
"self",
")",
":",
"# Get sources for documents which are in Elasticsearch",
"# and they are not in local buffer",
"if",
"self",
".",
"doc_to_update",
":",
"self",
".",
"update_sources",
"(",
")",
"ES_buffer",
"=",
"self",
".",
"action_buffer",
... | Get buffer which needs to be bulked to elasticsearch | [
"Get",
"buffer",
"which",
"needs",
"to",
"be",
"bulked",
"to",
"elasticsearch"
] | ad92138d1fd6656bb2e71cb5cc840f9ba0109c49 | https://github.com/yougov/elastic2-doc-manager/blob/ad92138d1fd6656bb2e71cb5cc840f9ba0109c49/mongo_connector/doc_managers/elastic2_doc_manager.py#L712-L722 |
1,136 | citruz/beacontools | beacontools/scanner.py | Monitor.run | def run(self):
"""Continously scan for BLE advertisements."""
self.socket = self.bluez.hci_open_dev(self.bt_device_id)
filtr = self.bluez.hci_filter_new()
self.bluez.hci_filter_all_events(filtr)
self.bluez.hci_filter_set_ptype(filtr, self.bluez.HCI_EVENT_PKT)
self.socket... | python | def run(self):
"""Continously scan for BLE advertisements."""
self.socket = self.bluez.hci_open_dev(self.bt_device_id)
filtr = self.bluez.hci_filter_new()
self.bluez.hci_filter_all_events(filtr)
self.bluez.hci_filter_set_ptype(filtr, self.bluez.HCI_EVENT_PKT)
self.socket... | [
"def",
"run",
"(",
"self",
")",
":",
"self",
".",
"socket",
"=",
"self",
".",
"bluez",
".",
"hci_open_dev",
"(",
"self",
".",
"bt_device_id",
")",
"filtr",
"=",
"self",
".",
"bluez",
".",
"hci_filter_new",
"(",
")",
"self",
".",
"bluez",
".",
"hci_fi... | Continously scan for BLE advertisements. | [
"Continously",
"scan",
"for",
"BLE",
"advertisements",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L89-L108 |
1,137 | citruz/beacontools | beacontools/scanner.py | Monitor.set_scan_parameters | def set_scan_parameters(self, scan_type=ScanType.ACTIVE, interval_ms=10, window_ms=10,
address_type=BluetoothAddressType.RANDOM, filter_type=ScanFilter.ALL):
""""sets the le scan parameters
Args:
scan_type: ScanType.(PASSIVE|ACTIVE)
interval: ms (as f... | python | def set_scan_parameters(self, scan_type=ScanType.ACTIVE, interval_ms=10, window_ms=10,
address_type=BluetoothAddressType.RANDOM, filter_type=ScanFilter.ALL):
""""sets the le scan parameters
Args:
scan_type: ScanType.(PASSIVE|ACTIVE)
interval: ms (as f... | [
"def",
"set_scan_parameters",
"(",
"self",
",",
"scan_type",
"=",
"ScanType",
".",
"ACTIVE",
",",
"interval_ms",
"=",
"10",
",",
"window_ms",
"=",
"10",
",",
"address_type",
"=",
"BluetoothAddressType",
".",
"RANDOM",
",",
"filter_type",
"=",
"ScanFilter",
"."... | sets the le scan parameters
Args:
scan_type: ScanType.(PASSIVE|ACTIVE)
interval: ms (as float) between scans (valid range 2.5ms - 10240ms)
..note:: when interval and window are equal, the scan
runs continuos
window: ms (as float) scan dura... | [
"sets",
"the",
"le",
"scan",
"parameters"
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L110-L151 |
1,138 | citruz/beacontools | beacontools/scanner.py | Monitor.toggle_scan | def toggle_scan(self, enable, filter_duplicates=False):
"""Enables or disables BLE scanning
Args:
enable: boolean value to enable (True) or disable (False) scanner
filter_duplicates: boolean value to enable/disable filter, that
omits duplicated packets"""
... | python | def toggle_scan(self, enable, filter_duplicates=False):
"""Enables or disables BLE scanning
Args:
enable: boolean value to enable (True) or disable (False) scanner
filter_duplicates: boolean value to enable/disable filter, that
omits duplicated packets"""
... | [
"def",
"toggle_scan",
"(",
"self",
",",
"enable",
",",
"filter_duplicates",
"=",
"False",
")",
":",
"command",
"=",
"struct",
".",
"pack",
"(",
"\">BB\"",
",",
"enable",
",",
"filter_duplicates",
")",
"self",
".",
"bluez",
".",
"hci_send_cmd",
"(",
"self",... | Enables or disables BLE scanning
Args:
enable: boolean value to enable (True) or disable (False) scanner
filter_duplicates: boolean value to enable/disable filter, that
omits duplicated packets | [
"Enables",
"or",
"disables",
"BLE",
"scanning"
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L153-L161 |
1,139 | citruz/beacontools | beacontools/scanner.py | Monitor.process_packet | def process_packet(self, pkt):
"""Parse the packet and call callback if one of the filters matches."""
# check if this could be a valid packet before parsing
# this reduces the CPU load significantly
if not ( \
((self.mode & ScannerMode.MODE_IBEACON) and (pkt[19:23] == b"\x4... | python | def process_packet(self, pkt):
"""Parse the packet and call callback if one of the filters matches."""
# check if this could be a valid packet before parsing
# this reduces the CPU load significantly
if not ( \
((self.mode & ScannerMode.MODE_IBEACON) and (pkt[19:23] == b"\x4... | [
"def",
"process_packet",
"(",
"self",
",",
"pkt",
")",
":",
"# check if this could be a valid packet before parsing",
"# this reduces the CPU load significantly",
"if",
"not",
"(",
"(",
"(",
"self",
".",
"mode",
"&",
"ScannerMode",
".",
"MODE_IBEACON",
")",
"and",
"("... | Parse the packet and call callback if one of the filters matches. | [
"Parse",
"the",
"packet",
"and",
"call",
"callback",
"if",
"one",
"of",
"the",
"filters",
"matches",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L163-L213 |
1,140 | citruz/beacontools | beacontools/scanner.py | Monitor.save_bt_addr | def save_bt_addr(self, packet, bt_addr):
"""Add to the list of mappings."""
if isinstance(packet, EddystoneUIDFrame):
# remove out old mapping
new_mappings = [m for m in self.eddystone_mappings if m[0] != bt_addr]
new_mappings.append((bt_addr, packet.properties))
... | python | def save_bt_addr(self, packet, bt_addr):
"""Add to the list of mappings."""
if isinstance(packet, EddystoneUIDFrame):
# remove out old mapping
new_mappings = [m for m in self.eddystone_mappings if m[0] != bt_addr]
new_mappings.append((bt_addr, packet.properties))
... | [
"def",
"save_bt_addr",
"(",
"self",
",",
"packet",
",",
"bt_addr",
")",
":",
"if",
"isinstance",
"(",
"packet",
",",
"EddystoneUIDFrame",
")",
":",
"# remove out old mapping",
"new_mappings",
"=",
"[",
"m",
"for",
"m",
"in",
"self",
".",
"eddystone_mappings",
... | Add to the list of mappings. | [
"Add",
"to",
"the",
"list",
"of",
"mappings",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L215-L221 |
1,141 | citruz/beacontools | beacontools/scanner.py | Monitor.get_properties | def get_properties(self, packet, bt_addr):
"""Get properties of beacon depending on type."""
if is_one_of(packet, [EddystoneTLMFrame, EddystoneURLFrame, \
EddystoneEncryptedTLMFrame, EddystoneEIDFrame]):
# here we retrieve the namespace and instance which corres... | python | def get_properties(self, packet, bt_addr):
"""Get properties of beacon depending on type."""
if is_one_of(packet, [EddystoneTLMFrame, EddystoneURLFrame, \
EddystoneEncryptedTLMFrame, EddystoneEIDFrame]):
# here we retrieve the namespace and instance which corres... | [
"def",
"get_properties",
"(",
"self",
",",
"packet",
",",
"bt_addr",
")",
":",
"if",
"is_one_of",
"(",
"packet",
",",
"[",
"EddystoneTLMFrame",
",",
"EddystoneURLFrame",
",",
"EddystoneEncryptedTLMFrame",
",",
"EddystoneEIDFrame",
"]",
")",
":",
"# here we retriev... | Get properties of beacon depending on type. | [
"Get",
"properties",
"of",
"beacon",
"depending",
"on",
"type",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L223-L231 |
1,142 | citruz/beacontools | beacontools/scanner.py | Monitor.terminate | def terminate(self):
"""Signal runner to stop and join thread."""
self.toggle_scan(False)
self.keep_going = False
self.join() | python | def terminate(self):
"""Signal runner to stop and join thread."""
self.toggle_scan(False)
self.keep_going = False
self.join() | [
"def",
"terminate",
"(",
"self",
")",
":",
"self",
".",
"toggle_scan",
"(",
"False",
")",
"self",
".",
"keep_going",
"=",
"False",
"self",
".",
"join",
"(",
")"
] | Signal runner to stop and join thread. | [
"Signal",
"runner",
"to",
"stop",
"and",
"join",
"thread",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/scanner.py#L240-L244 |
1,143 | citruz/beacontools | beacontools/utils.py | data_to_uuid | def data_to_uuid(data):
"""Convert an array of binary data to the iBeacon uuid format."""
string = data_to_hexstring(data)
return string[0:8]+'-'+string[8:12]+'-'+string[12:16]+'-'+string[16:20]+'-'+string[20:32] | python | def data_to_uuid(data):
"""Convert an array of binary data to the iBeacon uuid format."""
string = data_to_hexstring(data)
return string[0:8]+'-'+string[8:12]+'-'+string[12:16]+'-'+string[16:20]+'-'+string[20:32] | [
"def",
"data_to_uuid",
"(",
"data",
")",
":",
"string",
"=",
"data_to_hexstring",
"(",
"data",
")",
"return",
"string",
"[",
"0",
":",
"8",
"]",
"+",
"'-'",
"+",
"string",
"[",
"8",
":",
"12",
"]",
"+",
"'-'",
"+",
"string",
"[",
"12",
":",
"16",... | Convert an array of binary data to the iBeacon uuid format. | [
"Convert",
"an",
"array",
"of",
"binary",
"data",
"to",
"the",
"iBeacon",
"uuid",
"format",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/utils.py#L24-L27 |
1,144 | citruz/beacontools | beacontools/utils.py | bt_addr_to_string | def bt_addr_to_string(addr):
"""Convert a binary string to the hex representation."""
addr_str = array.array('B', addr)
addr_str.reverse()
hex_str = hexlify(addr_str.tostring()).decode('ascii')
# insert ":" seperator between the bytes
return ':'.join(a+b for a, b in zip(hex_str[::2], hex_str[1::... | python | def bt_addr_to_string(addr):
"""Convert a binary string to the hex representation."""
addr_str = array.array('B', addr)
addr_str.reverse()
hex_str = hexlify(addr_str.tostring()).decode('ascii')
# insert ":" seperator between the bytes
return ':'.join(a+b for a, b in zip(hex_str[::2], hex_str[1::... | [
"def",
"bt_addr_to_string",
"(",
"addr",
")",
":",
"addr_str",
"=",
"array",
".",
"array",
"(",
"'B'",
",",
"addr",
")",
"addr_str",
".",
"reverse",
"(",
")",
"hex_str",
"=",
"hexlify",
"(",
"addr_str",
".",
"tostring",
"(",
")",
")",
".",
"decode",
... | Convert a binary string to the hex representation. | [
"Convert",
"a",
"binary",
"string",
"to",
"the",
"hex",
"representation",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/utils.py#L35-L41 |
1,145 | citruz/beacontools | beacontools/utils.py | is_one_of | def is_one_of(obj, types):
"""Return true iff obj is an instance of one of the types."""
for type_ in types:
if isinstance(obj, type_):
return True
return False | python | def is_one_of(obj, types):
"""Return true iff obj is an instance of one of the types."""
for type_ in types:
if isinstance(obj, type_):
return True
return False | [
"def",
"is_one_of",
"(",
"obj",
",",
"types",
")",
":",
"for",
"type_",
"in",
"types",
":",
"if",
"isinstance",
"(",
"obj",
",",
"type_",
")",
":",
"return",
"True",
"return",
"False"
] | Return true iff obj is an instance of one of the types. | [
"Return",
"true",
"iff",
"obj",
"is",
"an",
"instance",
"of",
"one",
"of",
"the",
"types",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/utils.py#L44-L49 |
1,146 | citruz/beacontools | beacontools/utils.py | is_packet_type | def is_packet_type(cls):
"""Check if class is one the packet types."""
from .packet_types import EddystoneUIDFrame, EddystoneURLFrame, \
EddystoneEncryptedTLMFrame, EddystoneTLMFrame, \
EddystoneEIDFrame, IBeaconAdvertisement, \
... | python | def is_packet_type(cls):
"""Check if class is one the packet types."""
from .packet_types import EddystoneUIDFrame, EddystoneURLFrame, \
EddystoneEncryptedTLMFrame, EddystoneTLMFrame, \
EddystoneEIDFrame, IBeaconAdvertisement, \
... | [
"def",
"is_packet_type",
"(",
"cls",
")",
":",
"from",
".",
"packet_types",
"import",
"EddystoneUIDFrame",
",",
"EddystoneURLFrame",
",",
"EddystoneEncryptedTLMFrame",
",",
"EddystoneTLMFrame",
",",
"EddystoneEIDFrame",
",",
"IBeaconAdvertisement",
",",
"EstimoteTelemetry... | Check if class is one the packet types. | [
"Check",
"if",
"class",
"is",
"one",
"the",
"packet",
"types",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/utils.py#L52-L60 |
1,147 | citruz/beacontools | beacontools/utils.py | bin_to_int | def bin_to_int(string):
"""Convert a one element byte string to signed int for python 2 support."""
if isinstance(string, str):
return struct.unpack("b", string)[0]
else:
return struct.unpack("b", bytes([string]))[0] | python | def bin_to_int(string):
"""Convert a one element byte string to signed int for python 2 support."""
if isinstance(string, str):
return struct.unpack("b", string)[0]
else:
return struct.unpack("b", bytes([string]))[0] | [
"def",
"bin_to_int",
"(",
"string",
")",
":",
"if",
"isinstance",
"(",
"string",
",",
"str",
")",
":",
"return",
"struct",
".",
"unpack",
"(",
"\"b\"",
",",
"string",
")",
"[",
"0",
"]",
"else",
":",
"return",
"struct",
".",
"unpack",
"(",
"\"b\"",
... | Convert a one element byte string to signed int for python 2 support. | [
"Convert",
"a",
"one",
"element",
"byte",
"string",
"to",
"signed",
"int",
"for",
"python",
"2",
"support",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/utils.py#L71-L76 |
1,148 | citruz/beacontools | beacontools/utils.py | get_mode | def get_mode(device_filter):
"""Determine which beacons the scanner should look for."""
from .device_filters import IBeaconFilter, EddystoneFilter, BtAddrFilter, EstimoteFilter
if device_filter is None or len(device_filter) == 0:
return ScannerMode.MODE_ALL
mode = ScannerMode.MODE_NONE
for ... | python | def get_mode(device_filter):
"""Determine which beacons the scanner should look for."""
from .device_filters import IBeaconFilter, EddystoneFilter, BtAddrFilter, EstimoteFilter
if device_filter is None or len(device_filter) == 0:
return ScannerMode.MODE_ALL
mode = ScannerMode.MODE_NONE
for ... | [
"def",
"get_mode",
"(",
"device_filter",
")",
":",
"from",
".",
"device_filters",
"import",
"IBeaconFilter",
",",
"EddystoneFilter",
",",
"BtAddrFilter",
",",
"EstimoteFilter",
"if",
"device_filter",
"is",
"None",
"or",
"len",
"(",
"device_filter",
")",
"==",
"0... | Determine which beacons the scanner should look for. | [
"Determine",
"which",
"beacons",
"the",
"scanner",
"should",
"look",
"for",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/utils.py#L79-L97 |
1,149 | citruz/beacontools | beacontools/device_filters.py | DeviceFilter.matches | def matches(self, filter_props):
"""Check if the filter matches the supplied properties."""
if filter_props is None:
return False
found_one = False
for key, value in filter_props.items():
if key in self.properties and value != self.properties[key]:
... | python | def matches(self, filter_props):
"""Check if the filter matches the supplied properties."""
if filter_props is None:
return False
found_one = False
for key, value in filter_props.items():
if key in self.properties and value != self.properties[key]:
... | [
"def",
"matches",
"(",
"self",
",",
"filter_props",
")",
":",
"if",
"filter_props",
"is",
"None",
":",
"return",
"False",
"found_one",
"=",
"False",
"for",
"key",
",",
"value",
"in",
"filter_props",
".",
"items",
"(",
")",
":",
"if",
"key",
"in",
"self... | Check if the filter matches the supplied properties. | [
"Check",
"if",
"the",
"filter",
"matches",
"the",
"supplied",
"properties",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/device_filters.py#L13-L25 |
1,150 | citruz/beacontools | beacontools/parser.py | parse_packet | def parse_packet(packet):
"""Parse a beacon advertisement packet."""
frame = parse_ltv_packet(packet)
if frame is None:
frame = parse_ibeacon_packet(packet)
return frame | python | def parse_packet(packet):
"""Parse a beacon advertisement packet."""
frame = parse_ltv_packet(packet)
if frame is None:
frame = parse_ibeacon_packet(packet)
return frame | [
"def",
"parse_packet",
"(",
"packet",
")",
":",
"frame",
"=",
"parse_ltv_packet",
"(",
"packet",
")",
"if",
"frame",
"is",
"None",
":",
"frame",
"=",
"parse_ibeacon_packet",
"(",
"packet",
")",
"return",
"frame"
] | Parse a beacon advertisement packet. | [
"Parse",
"a",
"beacon",
"advertisement",
"packet",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/parser.py#L14-L19 |
1,151 | citruz/beacontools | beacontools/parser.py | parse_ltv_packet | def parse_ltv_packet(packet):
"""Parse a tag-length-value style beacon packet."""
try:
frame = LTVFrame.parse(packet)
for ltv in frame:
if ltv['type'] == SERVICE_DATA_TYPE:
data = ltv['value']
if data["service_identifier"] == EDDYSTONE_UUID:
... | python | def parse_ltv_packet(packet):
"""Parse a tag-length-value style beacon packet."""
try:
frame = LTVFrame.parse(packet)
for ltv in frame:
if ltv['type'] == SERVICE_DATA_TYPE:
data = ltv['value']
if data["service_identifier"] == EDDYSTONE_UUID:
... | [
"def",
"parse_ltv_packet",
"(",
"packet",
")",
":",
"try",
":",
"frame",
"=",
"LTVFrame",
".",
"parse",
"(",
"packet",
")",
"for",
"ltv",
"in",
"frame",
":",
"if",
"ltv",
"[",
"'type'",
"]",
"==",
"SERVICE_DATA_TYPE",
":",
"data",
"=",
"ltv",
"[",
"'... | Parse a tag-length-value style beacon packet. | [
"Parse",
"a",
"tag",
"-",
"length",
"-",
"value",
"style",
"beacon",
"packet",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/parser.py#L21-L38 |
1,152 | citruz/beacontools | beacontools/parser.py | parse_eddystone_service_data | def parse_eddystone_service_data(data):
"""Parse Eddystone service data."""
if data['frame_type'] == EDDYSTONE_UID_FRAME:
return EddystoneUIDFrame(data['frame'])
elif data['frame_type'] == EDDYSTONE_TLM_FRAME:
if data['frame']['tlm_version'] == EDDYSTONE_TLM_ENCRYPTED:
return Ed... | python | def parse_eddystone_service_data(data):
"""Parse Eddystone service data."""
if data['frame_type'] == EDDYSTONE_UID_FRAME:
return EddystoneUIDFrame(data['frame'])
elif data['frame_type'] == EDDYSTONE_TLM_FRAME:
if data['frame']['tlm_version'] == EDDYSTONE_TLM_ENCRYPTED:
return Ed... | [
"def",
"parse_eddystone_service_data",
"(",
"data",
")",
":",
"if",
"data",
"[",
"'frame_type'",
"]",
"==",
"EDDYSTONE_UID_FRAME",
":",
"return",
"EddystoneUIDFrame",
"(",
"data",
"[",
"'frame'",
"]",
")",
"elif",
"data",
"[",
"'frame_type'",
"]",
"==",
"EDDYS... | Parse Eddystone service data. | [
"Parse",
"Eddystone",
"service",
"data",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/parser.py#L40-L57 |
1,153 | citruz/beacontools | beacontools/parser.py | parse_estimote_service_data | def parse_estimote_service_data(data):
"""Parse Estimote service data."""
if data['frame_type'] & 0xF == ESTIMOTE_TELEMETRY_FRAME:
protocol_version = (data['frame_type'] & 0xF0) >> 4
if data['frame']['subframe_type'] == ESTIMOTE_TELEMETRY_SUBFRAME_A:
return EstimoteTelemetryFrameA(da... | python | def parse_estimote_service_data(data):
"""Parse Estimote service data."""
if data['frame_type'] & 0xF == ESTIMOTE_TELEMETRY_FRAME:
protocol_version = (data['frame_type'] & 0xF0) >> 4
if data['frame']['subframe_type'] == ESTIMOTE_TELEMETRY_SUBFRAME_A:
return EstimoteTelemetryFrameA(da... | [
"def",
"parse_estimote_service_data",
"(",
"data",
")",
":",
"if",
"data",
"[",
"'frame_type'",
"]",
"&",
"0xF",
"==",
"ESTIMOTE_TELEMETRY_FRAME",
":",
"protocol_version",
"=",
"(",
"data",
"[",
"'frame_type'",
"]",
"&",
"0xF0",
")",
">>",
"4",
"if",
"data",... | Parse Estimote service data. | [
"Parse",
"Estimote",
"service",
"data",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/parser.py#L59-L67 |
1,154 | citruz/beacontools | beacontools/packet_types/estimote.py | EstimoteTelemetryFrameA.parse_motion_state | def parse_motion_state(val):
"""Convert motion state byte to seconds."""
number = val & 0b00111111
unit = (val & 0b11000000) >> 6
if unit == 1:
number *= 60 # minutes
elif unit == 2:
number *= 60 * 60 # hours
elif unit == 3 and number < 32:
... | python | def parse_motion_state(val):
"""Convert motion state byte to seconds."""
number = val & 0b00111111
unit = (val & 0b11000000) >> 6
if unit == 1:
number *= 60 # minutes
elif unit == 2:
number *= 60 * 60 # hours
elif unit == 3 and number < 32:
... | [
"def",
"parse_motion_state",
"(",
"val",
")",
":",
"number",
"=",
"val",
"&",
"0b00111111",
"unit",
"=",
"(",
"val",
"&",
"0b11000000",
")",
">>",
"6",
"if",
"unit",
"==",
"1",
":",
"number",
"*=",
"60",
"# minutes",
"elif",
"unit",
"==",
"2",
":",
... | Convert motion state byte to seconds. | [
"Convert",
"motion",
"state",
"byte",
"to",
"seconds",
"."
] | 15a83e9750d0a4393f8a36868e07f6d9458253fe | https://github.com/citruz/beacontools/blob/15a83e9750d0a4393f8a36868e07f6d9458253fe/beacontools/packet_types/estimote.py#L46-L59 |
1,155 | Polyconseil/zbarlight | docs/conf.py | _Zbarlight.monkey_patch | def monkey_patch(cls):
"""Monkey path zbarlight C extension on Read The Docs"""
on_read_the_docs = os.environ.get('READTHEDOCS', False)
if on_read_the_docs:
sys.modules['zbarlight._zbarlight'] = cls | python | def monkey_patch(cls):
"""Monkey path zbarlight C extension on Read The Docs"""
on_read_the_docs = os.environ.get('READTHEDOCS', False)
if on_read_the_docs:
sys.modules['zbarlight._zbarlight'] = cls | [
"def",
"monkey_patch",
"(",
"cls",
")",
":",
"on_read_the_docs",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'READTHEDOCS'",
",",
"False",
")",
"if",
"on_read_the_docs",
":",
"sys",
".",
"modules",
"[",
"'zbarlight._zbarlight'",
"]",
"=",
"cls"
] | Monkey path zbarlight C extension on Read The Docs | [
"Monkey",
"path",
"zbarlight",
"C",
"extension",
"on",
"Read",
"The",
"Docs"
] | 97f46696516683af863d87935074e772e89b4292 | https://github.com/Polyconseil/zbarlight/blob/97f46696516683af863d87935074e772e89b4292/docs/conf.py#L23-L27 |
1,156 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | MVLSBFormat.set_pixel | def set_pixel(framebuf, x, y, color):
"""Set a given pixel to a color."""
index = (y >> 3) * framebuf.stride + x
offset = y & 0x07
framebuf.buf[index] = (framebuf.buf[index] & ~(0x01 << offset)) | ((color != 0) << offset) | python | def set_pixel(framebuf, x, y, color):
"""Set a given pixel to a color."""
index = (y >> 3) * framebuf.stride + x
offset = y & 0x07
framebuf.buf[index] = (framebuf.buf[index] & ~(0x01 << offset)) | ((color != 0) << offset) | [
"def",
"set_pixel",
"(",
"framebuf",
",",
"x",
",",
"y",
",",
"color",
")",
":",
"index",
"=",
"(",
"y",
">>",
"3",
")",
"*",
"framebuf",
".",
"stride",
"+",
"x",
"offset",
"=",
"y",
"&",
"0x07",
"framebuf",
".",
"buf",
"[",
"index",
"]",
"=",
... | Set a given pixel to a color. | [
"Set",
"a",
"given",
"pixel",
"to",
"a",
"color",
"."
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L96-L100 |
1,157 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | MVLSBFormat.get_pixel | def get_pixel(framebuf, x, y):
"""Get the color of a given pixel"""
index = (y >> 3) * framebuf.stride + x
offset = y & 0x07
return (framebuf.buf[index] >> offset) & 0x01 | python | def get_pixel(framebuf, x, y):
"""Get the color of a given pixel"""
index = (y >> 3) * framebuf.stride + x
offset = y & 0x07
return (framebuf.buf[index] >> offset) & 0x01 | [
"def",
"get_pixel",
"(",
"framebuf",
",",
"x",
",",
"y",
")",
":",
"index",
"=",
"(",
"y",
">>",
"3",
")",
"*",
"framebuf",
".",
"stride",
"+",
"x",
"offset",
"=",
"y",
"&",
"0x07",
"return",
"(",
"framebuf",
".",
"buf",
"[",
"index",
"]",
">>"... | Get the color of a given pixel | [
"Get",
"the",
"color",
"of",
"a",
"given",
"pixel"
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L103-L107 |
1,158 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.pixel | def pixel(self, x, y, color=None):
"""If ``color`` is not given, get the color value of the specified pixel. If ``color`` is
given, set the specified pixel to the given color."""
if self.rotation == 1:
x, y = y, x
x = self.width - x - 1
if self.rotation == 2:
... | python | def pixel(self, x, y, color=None):
"""If ``color`` is not given, get the color value of the specified pixel. If ``color`` is
given, set the specified pixel to the given color."""
if self.rotation == 1:
x, y = y, x
x = self.width - x - 1
if self.rotation == 2:
... | [
"def",
"pixel",
"(",
"self",
",",
"x",
",",
"y",
",",
"color",
"=",
"None",
")",
":",
"if",
"self",
".",
"rotation",
"==",
"1",
":",
"x",
",",
"y",
"=",
"y",
",",
"x",
"x",
"=",
"self",
".",
"width",
"-",
"x",
"-",
"1",
"if",
"self",
".",... | If ``color`` is not given, get the color value of the specified pixel. If ``color`` is
given, set the specified pixel to the given color. | [
"If",
"color",
"is",
"not",
"given",
"get",
"the",
"color",
"value",
"of",
"the",
"specified",
"pixel",
".",
"If",
"color",
"is",
"given",
"set",
"the",
"specified",
"pixel",
"to",
"the",
"given",
"color",
"."
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L189-L207 |
1,159 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.hline | def hline(self, x, y, width, color):
"""Draw a horizontal line up to a given length."""
self.rect(x, y, width, 1, color, fill=True) | python | def hline(self, x, y, width, color):
"""Draw a horizontal line up to a given length."""
self.rect(x, y, width, 1, color, fill=True) | [
"def",
"hline",
"(",
"self",
",",
"x",
",",
"y",
",",
"width",
",",
"color",
")",
":",
"self",
".",
"rect",
"(",
"x",
",",
"y",
",",
"width",
",",
"1",
",",
"color",
",",
"fill",
"=",
"True",
")"
] | Draw a horizontal line up to a given length. | [
"Draw",
"a",
"horizontal",
"line",
"up",
"to",
"a",
"given",
"length",
"."
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L209-L211 |
1,160 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.vline | def vline(self, x, y, height, color):
"""Draw a vertical line up to a given length."""
self.rect(x, y, 1, height, color, fill=True) | python | def vline(self, x, y, height, color):
"""Draw a vertical line up to a given length."""
self.rect(x, y, 1, height, color, fill=True) | [
"def",
"vline",
"(",
"self",
",",
"x",
",",
"y",
",",
"height",
",",
"color",
")",
":",
"self",
".",
"rect",
"(",
"x",
",",
"y",
",",
"1",
",",
"height",
",",
"color",
",",
"fill",
"=",
"True",
")"
] | Draw a vertical line up to a given length. | [
"Draw",
"a",
"vertical",
"line",
"up",
"to",
"a",
"given",
"length",
"."
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L213-L215 |
1,161 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.rect | def rect(self, x, y, width, height, color, *, fill=False):
"""Draw a rectangle at the given location, size and color. The ```rect``` method draws only
a 1 pixel outline."""
# pylint: disable=too-many-arguments
if self.rotation == 1:
x, y = y, x
width, height = hei... | python | def rect(self, x, y, width, height, color, *, fill=False):
"""Draw a rectangle at the given location, size and color. The ```rect``` method draws only
a 1 pixel outline."""
# pylint: disable=too-many-arguments
if self.rotation == 1:
x, y = y, x
width, height = hei... | [
"def",
"rect",
"(",
"self",
",",
"x",
",",
"y",
",",
"width",
",",
"height",
",",
"color",
",",
"*",
",",
"fill",
"=",
"False",
")",
":",
"# pylint: disable=too-many-arguments",
"if",
"self",
".",
"rotation",
"==",
"1",
":",
"x",
",",
"y",
"=",
"y"... | Draw a rectangle at the given location, size and color. The ```rect``` method draws only
a 1 pixel outline. | [
"Draw",
"a",
"rectangle",
"at",
"the",
"given",
"location",
"size",
"and",
"color",
".",
"The",
"rect",
"method",
"draws",
"only",
"a",
"1",
"pixel",
"outline",
"."
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L217-L247 |
1,162 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.line | def line(self, x_0, y_0, x_1, y_1, color):
# pylint: disable=too-many-arguments
"""Bresenham's line algorithm"""
d_x = abs(x_1 - x_0)
d_y = abs(y_1 - y_0)
x, y = x_0, y_0
s_x = -1 if x_0 > x_1 else 1
s_y = -1 if y_0 > y_1 else 1
if d_x > d_y:
e... | python | def line(self, x_0, y_0, x_1, y_1, color):
# pylint: disable=too-many-arguments
"""Bresenham's line algorithm"""
d_x = abs(x_1 - x_0)
d_y = abs(y_1 - y_0)
x, y = x_0, y_0
s_x = -1 if x_0 > x_1 else 1
s_y = -1 if y_0 > y_1 else 1
if d_x > d_y:
e... | [
"def",
"line",
"(",
"self",
",",
"x_0",
",",
"y_0",
",",
"x_1",
",",
"y_1",
",",
"color",
")",
":",
"# pylint: disable=too-many-arguments",
"d_x",
"=",
"abs",
"(",
"x_1",
"-",
"x_0",
")",
"d_y",
"=",
"abs",
"(",
"y_1",
"-",
"y_0",
")",
"x",
",",
... | Bresenham's line algorithm | [
"Bresenham",
"s",
"line",
"algorithm"
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L249-L275 |
1,163 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.scroll | def scroll(self, delta_x, delta_y):
"""shifts framebuf in x and y direction"""
if delta_x < 0:
shift_x = 0
xend = self.width + delta_x
dt_x = 1
else:
shift_x = self.width - 1
xend = delta_x - 1
dt_x = -1
if delta_y <... | python | def scroll(self, delta_x, delta_y):
"""shifts framebuf in x and y direction"""
if delta_x < 0:
shift_x = 0
xend = self.width + delta_x
dt_x = 1
else:
shift_x = self.width - 1
xend = delta_x - 1
dt_x = -1
if delta_y <... | [
"def",
"scroll",
"(",
"self",
",",
"delta_x",
",",
"delta_y",
")",
":",
"if",
"delta_x",
"<",
"0",
":",
"shift_x",
"=",
"0",
"xend",
"=",
"self",
".",
"width",
"+",
"delta_x",
"dt_x",
"=",
"1",
"else",
":",
"shift_x",
"=",
"self",
".",
"width",
"... | shifts framebuf in x and y direction | [
"shifts",
"framebuf",
"in",
"x",
"and",
"y",
"direction"
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L281-L305 |
1,164 | adafruit/Adafruit_CircuitPython_framebuf | adafruit_framebuf.py | FrameBuffer.text | def text(self, string, x, y, color, *,
font_name="font5x8.bin"):
"""text is not yet implemented"""
if not self._font or self._font.font_name != font_name:
# load the font!
self._font = BitmapFont()
w = self._font.font_width
for i, char in enumerate(st... | python | def text(self, string, x, y, color, *,
font_name="font5x8.bin"):
"""text is not yet implemented"""
if not self._font or self._font.font_name != font_name:
# load the font!
self._font = BitmapFont()
w = self._font.font_width
for i, char in enumerate(st... | [
"def",
"text",
"(",
"self",
",",
"string",
",",
"x",
",",
"y",
",",
"color",
",",
"*",
",",
"font_name",
"=",
"\"font5x8.bin\"",
")",
":",
"if",
"not",
"self",
".",
"_font",
"or",
"self",
".",
"_font",
".",
"font_name",
"!=",
"font_name",
":",
"# l... | text is not yet implemented | [
"text",
"is",
"not",
"yet",
"implemented"
] | b9f62c4b71efa963150f9c5a0284b61c7add9d02 | https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/b9f62c4b71efa963150f9c5a0284b61c7add9d02/adafruit_framebuf.py#L307-L317 |
1,165 | loanzen/falcon-auth | falcon_auth/backends.py | AuthBackend.parse_auth_token_from_request | def parse_auth_token_from_request(self, auth_header):
"""
Parses and returns Auth token from the request header. Raises
`falcon.HTTPUnauthoried exception` with proper error message
"""
if not auth_header:
raise falcon.HTTPUnauthorized(
description='Mis... | python | def parse_auth_token_from_request(self, auth_header):
"""
Parses and returns Auth token from the request header. Raises
`falcon.HTTPUnauthoried exception` with proper error message
"""
if not auth_header:
raise falcon.HTTPUnauthorized(
description='Mis... | [
"def",
"parse_auth_token_from_request",
"(",
"self",
",",
"auth_header",
")",
":",
"if",
"not",
"auth_header",
":",
"raise",
"falcon",
".",
"HTTPUnauthorized",
"(",
"description",
"=",
"'Missing Authorization Header'",
")",
"parts",
"=",
"auth_header",
".",
"split",... | Parses and returns Auth token from the request header. Raises
`falcon.HTTPUnauthoried exception` with proper error message | [
"Parses",
"and",
"returns",
"Auth",
"token",
"from",
"the",
"request",
"header",
".",
"Raises",
"falcon",
".",
"HTTPUnauthoried",
"exception",
"with",
"proper",
"error",
"message"
] | b9063163fff8044a8579a6047a85f28f3b214fdf | https://github.com/loanzen/falcon-auth/blob/b9063163fff8044a8579a6047a85f28f3b214fdf/falcon_auth/backends.py#L52-L75 |
1,166 | loanzen/falcon-auth | falcon_auth/backends.py | JWTAuthBackend.authenticate | def authenticate(self, req, resp, resource):
"""
Extract auth token from request `authorization` header, decode jwt token,
verify configured claims and return either a ``user``
object if successful else raise an `falcon.HTTPUnauthoried exception`
"""
payload = self._decod... | python | def authenticate(self, req, resp, resource):
"""
Extract auth token from request `authorization` header, decode jwt token,
verify configured claims and return either a ``user``
object if successful else raise an `falcon.HTTPUnauthoried exception`
"""
payload = self._decod... | [
"def",
"authenticate",
"(",
"self",
",",
"req",
",",
"resp",
",",
"resource",
")",
":",
"payload",
"=",
"self",
".",
"_decode_jwt_token",
"(",
"req",
")",
"user",
"=",
"self",
".",
"user_loader",
"(",
"payload",
")",
"if",
"not",
"user",
":",
"raise",
... | Extract auth token from request `authorization` header, decode jwt token,
verify configured claims and return either a ``user``
object if successful else raise an `falcon.HTTPUnauthoried exception` | [
"Extract",
"auth",
"token",
"from",
"request",
"authorization",
"header",
"decode",
"jwt",
"token",
"verify",
"configured",
"claims",
"and",
"return",
"either",
"a",
"user",
"object",
"if",
"successful",
"else",
"raise",
"an",
"falcon",
".",
"HTTPUnauthoried",
"... | b9063163fff8044a8579a6047a85f28f3b214fdf | https://github.com/loanzen/falcon-auth/blob/b9063163fff8044a8579a6047a85f28f3b214fdf/falcon_auth/backends.py#L213-L225 |
1,167 | loanzen/falcon-auth | falcon_auth/backends.py | JWTAuthBackend.get_auth_token | def get_auth_token(self, user_payload):
"""
Create a JWT authentication token from ``user_payload``
Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token
"""
now = datetime.utcnow()
payload... | python | def get_auth_token(self, user_payload):
"""
Create a JWT authentication token from ``user_payload``
Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token
"""
now = datetime.utcnow()
payload... | [
"def",
"get_auth_token",
"(",
"self",
",",
"user_payload",
")",
":",
"now",
"=",
"datetime",
".",
"utcnow",
"(",
")",
"payload",
"=",
"{",
"'user'",
":",
"user_payload",
"}",
"if",
"'iat'",
"in",
"self",
".",
"verify_claims",
":",
"payload",
"[",
"'iat'"... | Create a JWT authentication token from ``user_payload``
Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token | [
"Create",
"a",
"JWT",
"authentication",
"token",
"from",
"user_payload"
] | b9063163fff8044a8579a6047a85f28f3b214fdf | https://github.com/loanzen/falcon-auth/blob/b9063163fff8044a8579a6047a85f28f3b214fdf/falcon_auth/backends.py#L227-L258 |
1,168 | loanzen/falcon-auth | falcon_auth/backends.py | TokenAuthBackend.get_auth_token | def get_auth_token(self, user_payload):
"""
Extracts token from the `user_payload`
"""
token = user_payload.get('token') or None
if not token:
raise ValueError('`user_payload` must provide api token')
return '{auth_header_prefix} {token}'.format(
... | python | def get_auth_token(self, user_payload):
"""
Extracts token from the `user_payload`
"""
token = user_payload.get('token') or None
if not token:
raise ValueError('`user_payload` must provide api token')
return '{auth_header_prefix} {token}'.format(
... | [
"def",
"get_auth_token",
"(",
"self",
",",
"user_payload",
")",
":",
"token",
"=",
"user_payload",
".",
"get",
"(",
"'token'",
")",
"or",
"None",
"if",
"not",
"token",
":",
"raise",
"ValueError",
"(",
"'`user_payload` must provide api token'",
")",
"return",
"... | Extracts token from the `user_payload` | [
"Extracts",
"token",
"from",
"the",
"user_payload"
] | b9063163fff8044a8579a6047a85f28f3b214fdf | https://github.com/loanzen/falcon-auth/blob/b9063163fff8044a8579a6047a85f28f3b214fdf/falcon_auth/backends.py#L379-L388 |
1,169 | loanzen/falcon-auth | falcon_auth/backends.py | HawkAuthBackend.parse_auth_token_from_request | def parse_auth_token_from_request(self, auth_header):
"""
Parses and returns the Hawk Authorization header if it is present and well-formed.
Raises `falcon.HTTPUnauthoried exception` with proper error message
"""
if not auth_header:
raise falcon.HTTPUnauthorized(
... | python | def parse_auth_token_from_request(self, auth_header):
"""
Parses and returns the Hawk Authorization header if it is present and well-formed.
Raises `falcon.HTTPUnauthoried exception` with proper error message
"""
if not auth_header:
raise falcon.HTTPUnauthorized(
... | [
"def",
"parse_auth_token_from_request",
"(",
"self",
",",
"auth_header",
")",
":",
"if",
"not",
"auth_header",
":",
"raise",
"falcon",
".",
"HTTPUnauthorized",
"(",
"description",
"=",
"'Missing Authorization Header'",
")",
"try",
":",
"auth_header_prefix",
",",
"_"... | Parses and returns the Hawk Authorization header if it is present and well-formed.
Raises `falcon.HTTPUnauthoried exception` with proper error message | [
"Parses",
"and",
"returns",
"the",
"Hawk",
"Authorization",
"header",
"if",
"it",
"is",
"present",
"and",
"well",
"-",
"formed",
".",
"Raises",
"falcon",
".",
"HTTPUnauthoried",
"exception",
"with",
"proper",
"error",
"message"
] | b9063163fff8044a8579a6047a85f28f3b214fdf | https://github.com/loanzen/falcon-auth/blob/b9063163fff8044a8579a6047a85f28f3b214fdf/falcon_auth/backends.py#L442-L462 |
1,170 | gmarull/qtmodern | qtmodern/styles.py | _apply_base_theme | def _apply_base_theme(app):
""" Apply base theme to the application.
Args:
app (QApplication): QApplication instance.
"""
if QT_VERSION < (5,):
app.setStyle('plastique')
else:
app.setStyle('Fusion')
with open(_STYLESHEET) as stylesheet:
app.setStyleShee... | python | def _apply_base_theme(app):
""" Apply base theme to the application.
Args:
app (QApplication): QApplication instance.
"""
if QT_VERSION < (5,):
app.setStyle('plastique')
else:
app.setStyle('Fusion')
with open(_STYLESHEET) as stylesheet:
app.setStyleShee... | [
"def",
"_apply_base_theme",
"(",
"app",
")",
":",
"if",
"QT_VERSION",
"<",
"(",
"5",
",",
")",
":",
"app",
".",
"setStyle",
"(",
"'plastique'",
")",
"else",
":",
"app",
".",
"setStyle",
"(",
"'Fusion'",
")",
"with",
"open",
"(",
"_STYLESHEET",
")",
"... | Apply base theme to the application.
Args:
app (QApplication): QApplication instance. | [
"Apply",
"base",
"theme",
"to",
"the",
"application",
"."
] | b58b24c5bcfa0b81c7b1af5a7dfdc0fae660ce0f | https://github.com/gmarull/qtmodern/blob/b58b24c5bcfa0b81c7b1af5a7dfdc0fae660ce0f/qtmodern/styles.py#L11-L24 |
1,171 | gmarull/qtmodern | qtmodern/styles.py | dark | def dark(app):
""" Apply Dark Theme to the Qt application instance.
Args:
app (QApplication): QApplication instance.
"""
_apply_base_theme(app)
darkPalette = QPalette()
# base
darkPalette.setColor(QPalette.WindowText, QColor(180, 180, 180))
darkPalette.setColor(QPalet... | python | def dark(app):
""" Apply Dark Theme to the Qt application instance.
Args:
app (QApplication): QApplication instance.
"""
_apply_base_theme(app)
darkPalette = QPalette()
# base
darkPalette.setColor(QPalette.WindowText, QColor(180, 180, 180))
darkPalette.setColor(QPalet... | [
"def",
"dark",
"(",
"app",
")",
":",
"_apply_base_theme",
"(",
"app",
")",
"darkPalette",
"=",
"QPalette",
"(",
")",
"# base",
"darkPalette",
".",
"setColor",
"(",
"QPalette",
".",
"WindowText",
",",
"QColor",
"(",
"180",
",",
"180",
",",
"180",
")",
"... | Apply Dark Theme to the Qt application instance.
Args:
app (QApplication): QApplication instance. | [
"Apply",
"Dark",
"Theme",
"to",
"the",
"Qt",
"application",
"instance",
"."
] | b58b24c5bcfa0b81c7b1af5a7dfdc0fae660ce0f | https://github.com/gmarull/qtmodern/blob/b58b24c5bcfa0b81c7b1af5a7dfdc0fae660ce0f/qtmodern/styles.py#L27-L69 |
1,172 | matthias-k/cyipopt | doc/source/sphinxext/inheritance_diagram.py | inheritance_diagram_directive | def inheritance_diagram_directive(name, arguments, options, content, lineno,
content_offset, block_text, state,
state_machine):
"""
Run when the inheritance_diagram directive is first encountered.
"""
node = inheritance_diagram()
c... | python | def inheritance_diagram_directive(name, arguments, options, content, lineno,
content_offset, block_text, state,
state_machine):
"""
Run when the inheritance_diagram directive is first encountered.
"""
node = inheritance_diagram()
c... | [
"def",
"inheritance_diagram_directive",
"(",
"name",
",",
"arguments",
",",
"options",
",",
"content",
",",
"lineno",
",",
"content_offset",
",",
"block_text",
",",
"state",
",",
"state_machine",
")",
":",
"node",
"=",
"inheritance_diagram",
"(",
")",
"class_nam... | Run when the inheritance_diagram directive is first encountered. | [
"Run",
"when",
"the",
"inheritance_diagram",
"directive",
"is",
"first",
"encountered",
"."
] | ed03f54de2e0b8c8ba4c0aa18ab9ab6c8846bc19 | https://github.com/matthias-k/cyipopt/blob/ed03f54de2e0b8c8ba4c0aa18ab9ab6c8846bc19/doc/source/sphinxext/inheritance_diagram.py#L293-L320 |
1,173 | matthias-k/cyipopt | doc/source/sphinxext/inheritance_diagram.py | InheritanceGraph.run_dot | def run_dot(self, args, name, parts=0, urls={},
graph_options={}, node_options={}, edge_options={}):
"""
Run graphviz 'dot' over this graph, returning whatever 'dot'
writes to stdout.
*args* will be passed along as commandline arguments.
*name* is the name of th... | python | def run_dot(self, args, name, parts=0, urls={},
graph_options={}, node_options={}, edge_options={}):
"""
Run graphviz 'dot' over this graph, returning whatever 'dot'
writes to stdout.
*args* will be passed along as commandline arguments.
*name* is the name of th... | [
"def",
"run_dot",
"(",
"self",
",",
"args",
",",
"name",
",",
"parts",
"=",
"0",
",",
"urls",
"=",
"{",
"}",
",",
"graph_options",
"=",
"{",
"}",
",",
"node_options",
"=",
"{",
"}",
",",
"edge_options",
"=",
"{",
"}",
")",
":",
"try",
":",
"dot... | Run graphviz 'dot' over this graph, returning whatever 'dot'
writes to stdout.
*args* will be passed along as commandline arguments.
*name* is the name of the graph
*urls* is a dictionary mapping class names to http urls
Raises DotException for any of the many os and
... | [
"Run",
"graphviz",
"dot",
"over",
"this",
"graph",
"returning",
"whatever",
"dot",
"writes",
"to",
"stdout",
"."
] | ed03f54de2e0b8c8ba4c0aa18ab9ab6c8846bc19 | https://github.com/matthias-k/cyipopt/blob/ed03f54de2e0b8c8ba4c0aa18ab9ab6c8846bc19/doc/source/sphinxext/inheritance_diagram.py#L251-L284 |
1,174 | schapman1974/tinymongo | setup.py | parse_md_to_rst | def parse_md_to_rst(file):
"""Read Markdown file and convert to ReStructured Text."""
try:
from m2r import parse_from_file
return parse_from_file(file).replace(
"artwork/", "http://198.27.119.65/"
)
except ImportError:
# m2r may not be installed in user environmen... | python | def parse_md_to_rst(file):
"""Read Markdown file and convert to ReStructured Text."""
try:
from m2r import parse_from_file
return parse_from_file(file).replace(
"artwork/", "http://198.27.119.65/"
)
except ImportError:
# m2r may not be installed in user environmen... | [
"def",
"parse_md_to_rst",
"(",
"file",
")",
":",
"try",
":",
"from",
"m2r",
"import",
"parse_from_file",
"return",
"parse_from_file",
"(",
"file",
")",
".",
"replace",
"(",
"\"artwork/\"",
",",
"\"http://198.27.119.65/\"",
")",
"except",
"ImportError",
":",
"# m... | Read Markdown file and convert to ReStructured Text. | [
"Read",
"Markdown",
"file",
"and",
"convert",
"to",
"ReStructured",
"Text",
"."
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/setup.py#L14-L23 |
1,175 | schapman1974/tinymongo | tinymongo/results.py | DeleteResult.deleted_count | def deleted_count(self):
"""The number of documents deleted."""
if isinstance(self.raw_result, list):
return len(self.raw_result)
else:
return self.raw_result | python | def deleted_count(self):
"""The number of documents deleted."""
if isinstance(self.raw_result, list):
return len(self.raw_result)
else:
return self.raw_result | [
"def",
"deleted_count",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"raw_result",
",",
"list",
")",
":",
"return",
"len",
"(",
"self",
".",
"raw_result",
")",
"else",
":",
"return",
"self",
".",
"raw_result"
] | The number of documents deleted. | [
"The",
"number",
"of",
"documents",
"deleted",
"."
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/results.py#L107-L112 |
1,176 | schapman1974/tinymongo | tinymongo/tinymongo.py | generate_id | def generate_id():
"""Generate new UUID"""
# TODO: Use six.string_type to Py3 compat
try:
return unicode(uuid1()).replace(u"-", u"")
except NameError:
return str(uuid1()).replace(u"-", u"") | python | def generate_id():
"""Generate new UUID"""
# TODO: Use six.string_type to Py3 compat
try:
return unicode(uuid1()).replace(u"-", u"")
except NameError:
return str(uuid1()).replace(u"-", u"") | [
"def",
"generate_id",
"(",
")",
":",
"# TODO: Use six.string_type to Py3 compat",
"try",
":",
"return",
"unicode",
"(",
"uuid1",
"(",
")",
")",
".",
"replace",
"(",
"u\"-\"",
",",
"u\"\"",
")",
"except",
"NameError",
":",
"return",
"str",
"(",
"uuid1",
"(",
... | Generate new UUID | [
"Generate",
"new",
"UUID"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L806-L812 |
1,177 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.insert | def insert(self, docs, *args, **kwargs):
"""Backwards compatibility with insert"""
if isinstance(docs, list):
return self.insert_many(docs, *args, **kwargs)
else:
return self.insert_one(docs, *args, **kwargs) | python | def insert(self, docs, *args, **kwargs):
"""Backwards compatibility with insert"""
if isinstance(docs, list):
return self.insert_many(docs, *args, **kwargs)
else:
return self.insert_one(docs, *args, **kwargs) | [
"def",
"insert",
"(",
"self",
",",
"docs",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"docs",
",",
"list",
")",
":",
"return",
"self",
".",
"insert_many",
"(",
"docs",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
... | Backwards compatibility with insert | [
"Backwards",
"compatibility",
"with",
"insert"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L170-L175 |
1,178 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.update | def update(self, query, doc, *args, **kwargs):
"""BAckwards compatibility with update"""
if isinstance(doc, list):
return [
self.update_one(query, item, *args, **kwargs)
for item in doc
]
else:
return self.update_one(query, doc,... | python | def update(self, query, doc, *args, **kwargs):
"""BAckwards compatibility with update"""
if isinstance(doc, list):
return [
self.update_one(query, item, *args, **kwargs)
for item in doc
]
else:
return self.update_one(query, doc,... | [
"def",
"update",
"(",
"self",
",",
"query",
",",
"doc",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"doc",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"update_one",
"(",
"query",
",",
"item",
",",
"*",
"... | BAckwards compatibility with update | [
"BAckwards",
"compatibility",
"with",
"update"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L406-L414 |
1,179 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.update_one | def update_one(self, query, doc):
"""
Updates one element of the collection
:param query: dictionary representing the mongo query
:param doc: dictionary representing the item to be updated
:return: UpdateResult
"""
if self.table is None:
self.build_ta... | python | def update_one(self, query, doc):
"""
Updates one element of the collection
:param query: dictionary representing the mongo query
:param doc: dictionary representing the item to be updated
:return: UpdateResult
"""
if self.table is None:
self.build_ta... | [
"def",
"update_one",
"(",
"self",
",",
"query",
",",
"doc",
")",
":",
"if",
"self",
".",
"table",
"is",
"None",
":",
"self",
".",
"build_table",
"(",
")",
"if",
"u\"$set\"",
"in",
"doc",
":",
"doc",
"=",
"doc",
"[",
"u\"$set\"",
"]",
"allcond",
"="... | Updates one element of the collection
:param query: dictionary representing the mongo query
:param doc: dictionary representing the item to be updated
:return: UpdateResult | [
"Updates",
"one",
"element",
"of",
"the",
"collection"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L416-L439 |
1,180 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.find | def find(self, filter=None, sort=None, skip=None, limit=None,
*args, **kwargs):
"""
Finds all matching results
:param query: dictionary representing the mongo query
:return: cursor containing the search results
"""
if self.table is None:
self.bui... | python | def find(self, filter=None, sort=None, skip=None, limit=None,
*args, **kwargs):
"""
Finds all matching results
:param query: dictionary representing the mongo query
:return: cursor containing the search results
"""
if self.table is None:
self.bui... | [
"def",
"find",
"(",
"self",
",",
"filter",
"=",
"None",
",",
"sort",
"=",
"None",
",",
"skip",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"table",
"is",
"None",
":",
"self",
... | Finds all matching results
:param query: dictionary representing the mongo query
:return: cursor containing the search results | [
"Finds",
"all",
"matching",
"results"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L441-L469 |
1,181 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.find_one | def find_one(self, filter=None):
"""
Finds one matching query element
:param query: dictionary representing the mongo query
:return: the resulting document (if found)
"""
if self.table is None:
self.build_table()
allcond = self.parse_query(filter)
... | python | def find_one(self, filter=None):
"""
Finds one matching query element
:param query: dictionary representing the mongo query
:return: the resulting document (if found)
"""
if self.table is None:
self.build_table()
allcond = self.parse_query(filter)
... | [
"def",
"find_one",
"(",
"self",
",",
"filter",
"=",
"None",
")",
":",
"if",
"self",
".",
"table",
"is",
"None",
":",
"self",
".",
"build_table",
"(",
")",
"allcond",
"=",
"self",
".",
"parse_query",
"(",
"filter",
")",
"return",
"self",
".",
"table",... | Finds one matching query element
:param query: dictionary representing the mongo query
:return: the resulting document (if found) | [
"Finds",
"one",
"matching",
"query",
"element"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L471-L484 |
1,182 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.remove | def remove(self, spec_or_id, multi=True, *args, **kwargs):
"""Backwards compatibility with remove"""
if multi:
return self.delete_many(spec_or_id)
return self.delete_one(spec_or_id) | python | def remove(self, spec_or_id, multi=True, *args, **kwargs):
"""Backwards compatibility with remove"""
if multi:
return self.delete_many(spec_or_id)
return self.delete_one(spec_or_id) | [
"def",
"remove",
"(",
"self",
",",
"spec_or_id",
",",
"multi",
"=",
"True",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"multi",
":",
"return",
"self",
".",
"delete_many",
"(",
"spec_or_id",
")",
"return",
"self",
".",
"delete_one",
"(... | Backwards compatibility with remove | [
"Backwards",
"compatibility",
"with",
"remove"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L486-L490 |
1,183 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.delete_one | def delete_one(self, query):
"""
Deletes one document from the collection
:param query: dictionary representing the mongo query
:return: DeleteResult
"""
item = self.find_one(query)
result = self.table.remove(where(u'_id') == item[u'_id'])
return DeleteR... | python | def delete_one(self, query):
"""
Deletes one document from the collection
:param query: dictionary representing the mongo query
:return: DeleteResult
"""
item = self.find_one(query)
result = self.table.remove(where(u'_id') == item[u'_id'])
return DeleteR... | [
"def",
"delete_one",
"(",
"self",
",",
"query",
")",
":",
"item",
"=",
"self",
".",
"find_one",
"(",
"query",
")",
"result",
"=",
"self",
".",
"table",
".",
"remove",
"(",
"where",
"(",
"u'_id'",
")",
"==",
"item",
"[",
"u'_id'",
"]",
")",
"return"... | Deletes one document from the collection
:param query: dictionary representing the mongo query
:return: DeleteResult | [
"Deletes",
"one",
"document",
"from",
"the",
"collection"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L492-L502 |
1,184 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCollection.delete_many | def delete_many(self, query):
"""
Removes all items matching the mongo query
:param query: dictionary representing the mongo query
:return: DeleteResult
"""
items = self.find(query)
result = [
self.table.remove(where(u'_id') == item[u'_id'])
... | python | def delete_many(self, query):
"""
Removes all items matching the mongo query
:param query: dictionary representing the mongo query
:return: DeleteResult
"""
items = self.find(query)
result = [
self.table.remove(where(u'_id') == item[u'_id'])
... | [
"def",
"delete_many",
"(",
"self",
",",
"query",
")",
":",
"items",
"=",
"self",
".",
"find",
"(",
"query",
")",
"result",
"=",
"[",
"self",
".",
"table",
".",
"remove",
"(",
"where",
"(",
"u'_id'",
")",
"==",
"item",
"[",
"u'_id'",
"]",
")",
"fo... | Removes all items matching the mongo query
:param query: dictionary representing the mongo query
:return: DeleteResult | [
"Removes",
"all",
"items",
"matching",
"the",
"mongo",
"query"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L504-L521 |
1,185 | schapman1974/tinymongo | tinymongo/tinymongo.py | TinyMongoCursor.paginate | def paginate(self, skip, limit):
"""Paginate list of records"""
if not self.count() or not limit:
return
skip = skip or 0
pages = int(ceil(self.count() / float(limit)))
limits = {}
last = 0
for i in range(pages):
current = limit * i
... | python | def paginate(self, skip, limit):
"""Paginate list of records"""
if not self.count() or not limit:
return
skip = skip or 0
pages = int(ceil(self.count() / float(limit)))
limits = {}
last = 0
for i in range(pages):
current = limit * i
... | [
"def",
"paginate",
"(",
"self",
",",
"skip",
",",
"limit",
")",
":",
"if",
"not",
"self",
".",
"count",
"(",
")",
"or",
"not",
"limit",
":",
"return",
"skip",
"=",
"skip",
"or",
"0",
"pages",
"=",
"int",
"(",
"ceil",
"(",
"self",
".",
"count",
... | Paginate list of records | [
"Paginate",
"list",
"of",
"records"
] | 993048059dc0aa789d879b69feb79a0f237a60b3 | https://github.com/schapman1974/tinymongo/blob/993048059dc0aa789d879b69feb79a0f237a60b3/tinymongo/tinymongo.py#L548-L564 |
1,186 | TracyWebTech/django-revproxy | revproxy/utils.py | should_stream | def should_stream(proxy_response):
"""Function to verify if the proxy_response must be converted into
a stream.This will be done by checking the proxy_response content-length
and verify if its length is bigger than one stipulated
by MIN_STREAMING_LENGTH.
:param proxy_response: An Instance of urllib... | python | def should_stream(proxy_response):
"""Function to verify if the proxy_response must be converted into
a stream.This will be done by checking the proxy_response content-length
and verify if its length is bigger than one stipulated
by MIN_STREAMING_LENGTH.
:param proxy_response: An Instance of urllib... | [
"def",
"should_stream",
"(",
"proxy_response",
")",
":",
"content_type",
"=",
"proxy_response",
".",
"headers",
".",
"get",
"(",
"'Content-Type'",
")",
"if",
"is_html_content_type",
"(",
"content_type",
")",
":",
"return",
"False",
"try",
":",
"content_length",
... | Function to verify if the proxy_response must be converted into
a stream.This will be done by checking the proxy_response content-length
and verify if its length is bigger than one stipulated
by MIN_STREAMING_LENGTH.
:param proxy_response: An Instance of urllib3.response.HTTPResponse
:returns: A bo... | [
"Function",
"to",
"verify",
"if",
"the",
"proxy_response",
"must",
"be",
"converted",
"into",
"a",
"stream",
".",
"This",
"will",
"be",
"done",
"by",
"checking",
"the",
"proxy_response",
"content",
"-",
"length",
"and",
"verify",
"if",
"its",
"length",
"is",... | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L60-L83 |
1,187 | TracyWebTech/django-revproxy | revproxy/utils.py | get_charset | def get_charset(content_type):
"""Function used to retrieve the charset from a content-type.If there is no
charset in the content type then the charset defined on DEFAULT_CHARSET
will be returned
:param content_type: A string containing a Content-Type header
:returns: A string cont... | python | def get_charset(content_type):
"""Function used to retrieve the charset from a content-type.If there is no
charset in the content type then the charset defined on DEFAULT_CHARSET
will be returned
:param content_type: A string containing a Content-Type header
:returns: A string cont... | [
"def",
"get_charset",
"(",
"content_type",
")",
":",
"if",
"not",
"content_type",
":",
"return",
"DEFAULT_CHARSET",
"matched",
"=",
"_get_charset_re",
".",
"search",
"(",
"content_type",
")",
"if",
"matched",
":",
"# Extract the charset and strip its double quotes",
"... | Function used to retrieve the charset from a content-type.If there is no
charset in the content type then the charset defined on DEFAULT_CHARSET
will be returned
:param content_type: A string containing a Content-Type header
:returns: A string containing the charset | [
"Function",
"used",
"to",
"retrieve",
"the",
"charset",
"from",
"a",
"content",
"-",
"type",
".",
"If",
"there",
"is",
"no",
"charset",
"in",
"the",
"content",
"type",
"then",
"the",
"charset",
"defined",
"on",
"DEFAULT_CHARSET",
"will",
"be",
"returned"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L86-L101 |
1,188 | TracyWebTech/django-revproxy | revproxy/utils.py | required_header | def required_header(header):
"""Function that verify if the header parameter is a essential header
:param header: A string represented a header
:returns: A boolean value that represent if the header is required
"""
if header in IGNORE_HEADERS:
return False
if header.startswith('... | python | def required_header(header):
"""Function that verify if the header parameter is a essential header
:param header: A string represented a header
:returns: A boolean value that represent if the header is required
"""
if header in IGNORE_HEADERS:
return False
if header.startswith('... | [
"def",
"required_header",
"(",
"header",
")",
":",
"if",
"header",
"in",
"IGNORE_HEADERS",
":",
"return",
"False",
"if",
"header",
".",
"startswith",
"(",
"'HTTP_'",
")",
"or",
"header",
"==",
"'CONTENT_TYPE'",
":",
"return",
"True",
"return",
"False"
] | Function that verify if the header parameter is a essential header
:param header: A string represented a header
:returns: A boolean value that represent if the header is required | [
"Function",
"that",
"verify",
"if",
"the",
"header",
"parameter",
"is",
"a",
"essential",
"header"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L104-L116 |
1,189 | TracyWebTech/django-revproxy | revproxy/utils.py | normalize_request_headers | def normalize_request_headers(request):
r"""Function used to transform header, replacing 'HTTP\_' to ''
and replace '_' to '-'
:param request: A HttpRequest that will be transformed
:returns: A dictionary with the normalized headers
"""
norm_headers = {}
for header, value in request... | python | def normalize_request_headers(request):
r"""Function used to transform header, replacing 'HTTP\_' to ''
and replace '_' to '-'
:param request: A HttpRequest that will be transformed
:returns: A dictionary with the normalized headers
"""
norm_headers = {}
for header, value in request... | [
"def",
"normalize_request_headers",
"(",
"request",
")",
":",
"norm_headers",
"=",
"{",
"}",
"for",
"header",
",",
"value",
"in",
"request",
".",
"META",
".",
"items",
"(",
")",
":",
"if",
"required_header",
"(",
"header",
")",
":",
"norm_header",
"=",
"... | r"""Function used to transform header, replacing 'HTTP\_' to ''
and replace '_' to '-'
:param request: A HttpRequest that will be transformed
:returns: A dictionary with the normalized headers | [
"r",
"Function",
"used",
"to",
"transform",
"header",
"replacing",
"HTTP",
"\\",
"_",
"to",
"and",
"replace",
"_",
"to",
"-"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L130-L143 |
1,190 | TracyWebTech/django-revproxy | revproxy/utils.py | encode_items | def encode_items(items):
"""Function that encode all elements in the list of items passed as
a parameter
:param items: A list of tuple
:returns: A list of tuple with all items encoded in 'utf-8'
"""
encoded = []
for key, values in items:
for value in values:
encode... | python | def encode_items(items):
"""Function that encode all elements in the list of items passed as
a parameter
:param items: A list of tuple
:returns: A list of tuple with all items encoded in 'utf-8'
"""
encoded = []
for key, values in items:
for value in values:
encode... | [
"def",
"encode_items",
"(",
"items",
")",
":",
"encoded",
"=",
"[",
"]",
"for",
"key",
",",
"values",
"in",
"items",
":",
"for",
"value",
"in",
"values",
":",
"encoded",
".",
"append",
"(",
"(",
"key",
".",
"encode",
"(",
"'utf-8'",
")",
",",
"valu... | Function that encode all elements in the list of items passed as
a parameter
:param items: A list of tuple
:returns: A list of tuple with all items encoded in 'utf-8' | [
"Function",
"that",
"encode",
"all",
"elements",
"in",
"the",
"list",
"of",
"items",
"passed",
"as",
"a",
"parameter"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L146-L157 |
1,191 | TracyWebTech/django-revproxy | revproxy/utils.py | cookie_from_string | def cookie_from_string(cookie_string, strict_cookies=False):
"""Parser for HTTP header set-cookie
The return from this function will be used as parameters for
django's response.set_cookie method. Because set_cookie doesn't
have parameter comment, this cookie attribute will be ignored.
:param cooki... | python | def cookie_from_string(cookie_string, strict_cookies=False):
"""Parser for HTTP header set-cookie
The return from this function will be used as parameters for
django's response.set_cookie method. Because set_cookie doesn't
have parameter comment, this cookie attribute will be ignored.
:param cooki... | [
"def",
"cookie_from_string",
"(",
"cookie_string",
",",
"strict_cookies",
"=",
"False",
")",
":",
"if",
"strict_cookies",
":",
"cookies",
"=",
"SimpleCookie",
"(",
"COOKIE_PREFIX",
"+",
"cookie_string",
")",
"if",
"not",
"cookies",
".",
"keys",
"(",
")",
":",
... | Parser for HTTP header set-cookie
The return from this function will be used as parameters for
django's response.set_cookie method. Because set_cookie doesn't
have parameter comment, this cookie attribute will be ignored.
:param cookie_string: A string representing a valid cookie
:param strict_co... | [
"Parser",
"for",
"HTTP",
"header",
"set",
"-",
"cookie",
"The",
"return",
"from",
"this",
"function",
"will",
"be",
"used",
"as",
"parameters",
"for",
"django",
"s",
"response",
".",
"set_cookie",
"method",
".",
"Because",
"set_cookie",
"doesn",
"t",
"have",... | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L163-L228 |
1,192 | TracyWebTech/django-revproxy | revproxy/utils.py | unquote | def unquote(value):
"""Remove wrapping quotes from a string.
:param value: A string that might be wrapped in double quotes, such
as a HTTP cookie value.
:returns: Beginning and ending quotes removed and escaped quotes (``\"``)
unescaped
"""
if len(value) > 1 and valu... | python | def unquote(value):
"""Remove wrapping quotes from a string.
:param value: A string that might be wrapped in double quotes, such
as a HTTP cookie value.
:returns: Beginning and ending quotes removed and escaped quotes (``\"``)
unescaped
"""
if len(value) > 1 and valu... | [
"def",
"unquote",
"(",
"value",
")",
":",
"if",
"len",
"(",
"value",
")",
">",
"1",
"and",
"value",
"[",
"0",
"]",
"==",
"'\"'",
"and",
"value",
"[",
"-",
"1",
"]",
"==",
"'\"'",
":",
"value",
"=",
"value",
"[",
"1",
":",
"-",
"1",
"]",
"."... | Remove wrapping quotes from a string.
:param value: A string that might be wrapped in double quotes, such
as a HTTP cookie value.
:returns: Beginning and ending quotes removed and escaped quotes (``\"``)
unescaped | [
"Remove",
"wrapping",
"quotes",
"from",
"a",
"string",
"."
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/utils.py#L231-L241 |
1,193 | TracyWebTech/django-revproxy | revproxy/transformer.py | asbool | def asbool(value):
"""Function used to convert certain string values into an appropriated
boolean value.If value is not a string the built-in python
bool function will be used to convert the passed parameter
:param value: an object to be converted to a boolean value
:returns: A boolean value... | python | def asbool(value):
"""Function used to convert certain string values into an appropriated
boolean value.If value is not a string the built-in python
bool function will be used to convert the passed parameter
:param value: an object to be converted to a boolean value
:returns: A boolean value... | [
"def",
"asbool",
"(",
"value",
")",
":",
"is_string",
"=",
"isinstance",
"(",
"value",
",",
"string_types",
")",
"if",
"is_string",
":",
"value",
"=",
"value",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"if",
"value",
"in",
"(",
"'true'",
",",
... | Function used to convert certain string values into an appropriated
boolean value.If value is not a string the built-in python
bool function will be used to convert the passed parameter
:param value: an object to be converted to a boolean value
:returns: A boolean value | [
"Function",
"used",
"to",
"convert",
"certain",
"string",
"values",
"into",
"an",
"appropriated",
"boolean",
"value",
".",
"If",
"value",
"is",
"not",
"a",
"string",
"the",
"built",
"-",
"in",
"python",
"bool",
"function",
"will",
"be",
"used",
"to",
"conv... | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/transformer.py#L30-L50 |
1,194 | TracyWebTech/django-revproxy | revproxy/transformer.py | DiazoTransformer.should_transform | def should_transform(self):
"""Determine if we should transform the response
:returns: A boolean value
"""
if not HAS_DIAZO:
self.log.info("HAS_DIAZO: false")
return False
if asbool(self.request.META.get(DIAZO_OFF_REQUEST_HEADER)):
self.log... | python | def should_transform(self):
"""Determine if we should transform the response
:returns: A boolean value
"""
if not HAS_DIAZO:
self.log.info("HAS_DIAZO: false")
return False
if asbool(self.request.META.get(DIAZO_OFF_REQUEST_HEADER)):
self.log... | [
"def",
"should_transform",
"(",
"self",
")",
":",
"if",
"not",
"HAS_DIAZO",
":",
"self",
".",
"log",
".",
"info",
"(",
"\"HAS_DIAZO: false\"",
")",
"return",
"False",
"if",
"asbool",
"(",
"self",
".",
"request",
".",
"META",
".",
"get",
"(",
"DIAZO_OFF_R... | Determine if we should transform the response
:returns: A boolean value | [
"Determine",
"if",
"we",
"should",
"transform",
"the",
"response"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/transformer.py#L62-L110 |
1,195 | TracyWebTech/django-revproxy | revproxy/transformer.py | DiazoTransformer.transform | def transform(self, rules, theme_template, is_html5, context_data=None):
"""Method used to make a transformation on the content of
the http response based on the rules and theme_templates
passed as paremters
:param rules: A file with a set of diazo rules to make a
... | python | def transform(self, rules, theme_template, is_html5, context_data=None):
"""Method used to make a transformation on the content of
the http response based on the rules and theme_templates
passed as paremters
:param rules: A file with a set of diazo rules to make a
... | [
"def",
"transform",
"(",
"self",
",",
"rules",
",",
"theme_template",
",",
"is_html5",
",",
"context_data",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"should_transform",
"(",
")",
":",
"self",
".",
"log",
".",
"info",
"(",
"\"Don't need to be transf... | Method used to make a transformation on the content of
the http response based on the rules and theme_templates
passed as paremters
:param rules: A file with a set of diazo rules to make a
transformation over the original response content
:param theme_template: ... | [
"Method",
"used",
"to",
"make",
"a",
"transformation",
"on",
"the",
"content",
"of",
"the",
"http",
"response",
"based",
"on",
"the",
"rules",
"and",
"theme_templates",
"passed",
"as",
"paremters"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/transformer.py#L112-L161 |
1,196 | TracyWebTech/django-revproxy | revproxy/transformer.py | DiazoTransformer.set_html5_doctype | def set_html5_doctype(self):
"""Method used to transform a doctype in to a properly html5 doctype
"""
doctype = b'<!DOCTYPE html>\n'
content = doctype_re.subn(doctype, self.response.content, 1)[0]
self.response.content = content | python | def set_html5_doctype(self):
"""Method used to transform a doctype in to a properly html5 doctype
"""
doctype = b'<!DOCTYPE html>\n'
content = doctype_re.subn(doctype, self.response.content, 1)[0]
self.response.content = content | [
"def",
"set_html5_doctype",
"(",
"self",
")",
":",
"doctype",
"=",
"b'<!DOCTYPE html>\\n'",
"content",
"=",
"doctype_re",
".",
"subn",
"(",
"doctype",
",",
"self",
".",
"response",
".",
"content",
",",
"1",
")",
"[",
"0",
"]",
"self",
".",
"response",
".... | Method used to transform a doctype in to a properly html5 doctype | [
"Method",
"used",
"to",
"transform",
"a",
"doctype",
"in",
"to",
"a",
"properly",
"html5",
"doctype"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/transformer.py#L170-L175 |
1,197 | TracyWebTech/django-revproxy | revproxy/connection.py | _output | def _output(self, s):
"""Host header should always be first"""
if s.lower().startswith(b'host: '):
self._buffer.insert(1, s)
else:
self._buffer.append(s) | python | def _output(self, s):
"""Host header should always be first"""
if s.lower().startswith(b'host: '):
self._buffer.insert(1, s)
else:
self._buffer.append(s) | [
"def",
"_output",
"(",
"self",
",",
"s",
")",
":",
"if",
"s",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"b'host: '",
")",
":",
"self",
".",
"_buffer",
".",
"insert",
"(",
"1",
",",
"s",
")",
"else",
":",
"self",
".",
"_buffer",
".",
"appe... | Host header should always be first | [
"Host",
"header",
"should",
"always",
"be",
"first"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/connection.py#L6-L12 |
1,198 | TracyWebTech/django-revproxy | revproxy/response.py | get_django_response | def get_django_response(proxy_response, strict_cookies=False):
"""This method is used to create an appropriate response based on the
Content-Length of the proxy_response. If the content is bigger than
MIN_STREAMING_LENGTH, which is found on utils.py,
than django.http.StreamingHttpResponse will be create... | python | def get_django_response(proxy_response, strict_cookies=False):
"""This method is used to create an appropriate response based on the
Content-Length of the proxy_response. If the content is bigger than
MIN_STREAMING_LENGTH, which is found on utils.py,
than django.http.StreamingHttpResponse will be create... | [
"def",
"get_django_response",
"(",
"proxy_response",
",",
"strict_cookies",
"=",
"False",
")",
":",
"status",
"=",
"proxy_response",
".",
"status",
"headers",
"=",
"proxy_response",
".",
"headers",
"logger",
".",
"debug",
"(",
"'Proxy response headers: %s'",
",",
... | This method is used to create an appropriate response based on the
Content-Length of the proxy_response. If the content is bigger than
MIN_STREAMING_LENGTH, which is found on utils.py,
than django.http.StreamingHttpResponse will be created,
else a django.http.HTTPResponse will be created instead
:p... | [
"This",
"method",
"is",
"used",
"to",
"create",
"an",
"appropriate",
"response",
"based",
"on",
"the",
"Content",
"-",
"Length",
"of",
"the",
"proxy_response",
".",
"If",
"the",
"content",
"is",
"bigger",
"than",
"MIN_STREAMING_LENGTH",
"which",
"is",
"found",... | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/response.py#L13-L61 |
1,199 | TracyWebTech/django-revproxy | revproxy/views.py | ProxyView.get_request_headers | def get_request_headers(self):
"""Return request headers that will be sent to upstream.
The header REMOTE_USER is set to the current user
if AuthenticationMiddleware is enabled and
the view's add_remote_user property is True.
.. versionadded:: 0.9.8
"""
request... | python | def get_request_headers(self):
"""Return request headers that will be sent to upstream.
The header REMOTE_USER is set to the current user
if AuthenticationMiddleware is enabled and
the view's add_remote_user property is True.
.. versionadded:: 0.9.8
"""
request... | [
"def",
"get_request_headers",
"(",
"self",
")",
":",
"request_headers",
"=",
"self",
".",
"get_proxy_request_headers",
"(",
"self",
".",
"request",
")",
"if",
"(",
"self",
".",
"add_remote_user",
"and",
"hasattr",
"(",
"self",
".",
"request",
",",
"'user'",
... | Return request headers that will be sent to upstream.
The header REMOTE_USER is set to the current user
if AuthenticationMiddleware is enabled and
the view's add_remote_user property is True.
.. versionadded:: 0.9.8 | [
"Return",
"request",
"headers",
"that",
"will",
"be",
"sent",
"to",
"upstream",
"."
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/views.py#L117-L134 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.