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 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
25,900 | rgalanakis/goless | write_benchresults.py | stdout_to_results | def stdout_to_results(s):
"""Turns the multi-line output of a benchmark process into
a sequence of BenchmarkResult instances."""
results = s.strip().split('\n')
return [BenchmarkResult(*r.split()) for r in results] | python | def stdout_to_results(s):
results = s.strip().split('\n')
return [BenchmarkResult(*r.split()) for r in results] | [
"def",
"stdout_to_results",
"(",
"s",
")",
":",
"results",
"=",
"s",
".",
"strip",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
"return",
"[",
"BenchmarkResult",
"(",
"*",
"r",
".",
"split",
"(",
")",
")",
"for",
"r",
"in",
"results",
"]"
] | Turns the multi-line output of a benchmark process into
a sequence of BenchmarkResult instances. | [
"Turns",
"the",
"multi",
"-",
"line",
"output",
"of",
"a",
"benchmark",
"process",
"into",
"a",
"sequence",
"of",
"BenchmarkResult",
"instances",
"."
] | 286cd69482ae5a56c899a0c0d5d895772d96e83d | https://github.com/rgalanakis/goless/blob/286cd69482ae5a56c899a0c0d5d895772d96e83d/write_benchresults.py#L37-L41 |
25,901 | rgalanakis/goless | write_benchresults.py | benchmark_process_and_backend | def benchmark_process_and_backend(exe, backend):
"""Returns BenchmarkResults for a given executable and backend."""
env = dict(os.environ)
env['GOLESS_BACKEND'] = backend
args = [exe, '-m', 'benchmark']
return get_benchproc_results(args, env=env) | python | def benchmark_process_and_backend(exe, backend):
env = dict(os.environ)
env['GOLESS_BACKEND'] = backend
args = [exe, '-m', 'benchmark']
return get_benchproc_results(args, env=env) | [
"def",
"benchmark_process_and_backend",
"(",
"exe",
",",
"backend",
")",
":",
"env",
"=",
"dict",
"(",
"os",
".",
"environ",
")",
"env",
"[",
"'GOLESS_BACKEND'",
"]",
"=",
"backend",
"args",
"=",
"[",
"exe",
",",
"'-m'",
",",
"'benchmark'",
"]",
"return"... | Returns BenchmarkResults for a given executable and backend. | [
"Returns",
"BenchmarkResults",
"for",
"a",
"given",
"executable",
"and",
"backend",
"."
] | 286cd69482ae5a56c899a0c0d5d895772d96e83d | https://github.com/rgalanakis/goless/blob/286cd69482ae5a56c899a0c0d5d895772d96e83d/write_benchresults.py#L58-L63 |
25,902 | rgalanakis/goless | write_benchresults.py | insert_seperator_results | def insert_seperator_results(results):
"""Given a sequence of BenchmarkResults,
return a new sequence where a "seperator" BenchmarkResult has been placed
between differing benchmarks to provide a visual difference."""
sepbench = BenchmarkResult(*[' ' * w for w in COLUMN_WIDTHS])
last_bm = None
for r in results:
if last_bm is None:
last_bm = r.benchmark
elif last_bm != r.benchmark:
yield sepbench
last_bm = r.benchmark
yield r | python | def insert_seperator_results(results):
sepbench = BenchmarkResult(*[' ' * w for w in COLUMN_WIDTHS])
last_bm = None
for r in results:
if last_bm is None:
last_bm = r.benchmark
elif last_bm != r.benchmark:
yield sepbench
last_bm = r.benchmark
yield r | [
"def",
"insert_seperator_results",
"(",
"results",
")",
":",
"sepbench",
"=",
"BenchmarkResult",
"(",
"*",
"[",
"' '",
"*",
"w",
"for",
"w",
"in",
"COLUMN_WIDTHS",
"]",
")",
"last_bm",
"=",
"None",
"for",
"r",
"in",
"results",
":",
"if",
"last_bm",
"is",... | Given a sequence of BenchmarkResults,
return a new sequence where a "seperator" BenchmarkResult has been placed
between differing benchmarks to provide a visual difference. | [
"Given",
"a",
"sequence",
"of",
"BenchmarkResults",
"return",
"a",
"new",
"sequence",
"where",
"a",
"seperator",
"BenchmarkResult",
"has",
"been",
"placed",
"between",
"differing",
"benchmarks",
"to",
"provide",
"a",
"visual",
"difference",
"."
] | 286cd69482ae5a56c899a0c0d5d895772d96e83d | https://github.com/rgalanakis/goless/blob/286cd69482ae5a56c899a0c0d5d895772d96e83d/write_benchresults.py#L86-L98 |
25,903 | zeldamods/byml-v2 | byml/byml.py | Byml.parse | def parse(self) -> typing.Union[list, dict, None]:
"""Parse the BYML and get the root node with all children."""
root_node_offset = self._read_u32(12)
if root_node_offset == 0:
return None
node_type = self._data[root_node_offset]
if not _is_container_type(node_type):
raise ValueError("Invalid root node: expected array or dict, got type 0x%x" % node_type)
return self._parse_node(node_type, 12) | python | def parse(self) -> typing.Union[list, dict, None]:
root_node_offset = self._read_u32(12)
if root_node_offset == 0:
return None
node_type = self._data[root_node_offset]
if not _is_container_type(node_type):
raise ValueError("Invalid root node: expected array or dict, got type 0x%x" % node_type)
return self._parse_node(node_type, 12) | [
"def",
"parse",
"(",
"self",
")",
"->",
"typing",
".",
"Union",
"[",
"list",
",",
"dict",
",",
"None",
"]",
":",
"root_node_offset",
"=",
"self",
".",
"_read_u32",
"(",
"12",
")",
"if",
"root_node_offset",
"==",
"0",
":",
"return",
"None",
"node_type",... | Parse the BYML and get the root node with all children. | [
"Parse",
"the",
"BYML",
"and",
"get",
"the",
"root",
"node",
"with",
"all",
"children",
"."
] | 508c590e5036e160068c0b5968b6b8feeca3b58c | https://github.com/zeldamods/byml-v2/blob/508c590e5036e160068c0b5968b6b8feeca3b58c/byml/byml.py#L82-L91 |
25,904 | InterSIS/django-rest-serializer-field-permissions | rest_framework_serializer_field_permissions/fields.py | PermissionMixin.check_permission | def check_permission(self, request):
"""
Check this field's permissions to determine whether or not it may be
shown.
"""
return all((permission.has_permission(request) for permission in self.permission_classes)) | python | def check_permission(self, request):
return all((permission.has_permission(request) for permission in self.permission_classes)) | [
"def",
"check_permission",
"(",
"self",
",",
"request",
")",
":",
"return",
"all",
"(",
"(",
"permission",
".",
"has_permission",
"(",
"request",
")",
"for",
"permission",
"in",
"self",
".",
"permission_classes",
")",
")"
] | Check this field's permissions to determine whether or not it may be
shown. | [
"Check",
"this",
"field",
"s",
"permissions",
"to",
"determine",
"whether",
"or",
"not",
"it",
"may",
"be",
"shown",
"."
] | 6406312a1c3c7d9242246ecec3393a8bf1d25609 | https://github.com/InterSIS/django-rest-serializer-field-permissions/blob/6406312a1c3c7d9242246ecec3393a8bf1d25609/rest_framework_serializer_field_permissions/fields.py#L29-L34 |
25,905 | sesh/piprot | piprot/providers/github.py | build_github_url | def build_github_url(
repo,
branch=None,
path='requirements.txt',
token=None
):
"""
Builds a URL to a file inside a Github repository.
"""
repo = re.sub(r"^http(s)?://github.com/", "", repo).strip('/')
# args come is as 'None' instead of not being provided
if not path:
path = 'requirements.txt'
if not branch:
branch = get_default_branch(repo)
url = 'https://raw.githubusercontent.com/{}/{}/{}'.format(
repo, branch, path
)
if token:
url = '{}?token={}'.format(url, token)
return url | python | def build_github_url(
repo,
branch=None,
path='requirements.txt',
token=None
):
repo = re.sub(r"^http(s)?://github.com/", "", repo).strip('/')
# args come is as 'None' instead of not being provided
if not path:
path = 'requirements.txt'
if not branch:
branch = get_default_branch(repo)
url = 'https://raw.githubusercontent.com/{}/{}/{}'.format(
repo, branch, path
)
if token:
url = '{}?token={}'.format(url, token)
return url | [
"def",
"build_github_url",
"(",
"repo",
",",
"branch",
"=",
"None",
",",
"path",
"=",
"'requirements.txt'",
",",
"token",
"=",
"None",
")",
":",
"repo",
"=",
"re",
".",
"sub",
"(",
"r\"^http(s)?://github.com/\"",
",",
"\"\"",
",",
"repo",
")",
".",
"stri... | Builds a URL to a file inside a Github repository. | [
"Builds",
"a",
"URL",
"to",
"a",
"file",
"inside",
"a",
"Github",
"repository",
"."
] | b9d61495123b26160fad647a0230d387d92b0841 | https://github.com/sesh/piprot/blob/b9d61495123b26160fad647a0230d387d92b0841/piprot/providers/github.py#L12-L38 |
25,906 | sesh/piprot | piprot/providers/github.py | get_default_branch | def get_default_branch(repo):
"""returns the name of the default branch of the repo"""
url = "{}/repos/{}".format(GITHUB_API_BASE, repo)
response = requests.get(url)
if response.status_code == 200:
api_response = json.loads(response.text)
return api_response['default_branch']
else:
return 'master' | python | def get_default_branch(repo):
url = "{}/repos/{}".format(GITHUB_API_BASE, repo)
response = requests.get(url)
if response.status_code == 200:
api_response = json.loads(response.text)
return api_response['default_branch']
else:
return 'master' | [
"def",
"get_default_branch",
"(",
"repo",
")",
":",
"url",
"=",
"\"{}/repos/{}\"",
".",
"format",
"(",
"GITHUB_API_BASE",
",",
"repo",
")",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
")",
"if",
"response",
".",
"status_code",
"==",
"200",
":",
... | returns the name of the default branch of the repo | [
"returns",
"the",
"name",
"of",
"the",
"default",
"branch",
"of",
"the",
"repo"
] | b9d61495123b26160fad647a0230d387d92b0841 | https://github.com/sesh/piprot/blob/b9d61495123b26160fad647a0230d387d92b0841/piprot/providers/github.py#L41-L49 |
25,907 | sesh/piprot | piprot/providers/github.py | get_requirements_file_from_url | def get_requirements_file_from_url(url):
"""fetches the requiremets from the url"""
response = requests.get(url)
if response.status_code == 200:
return StringIO(response.text)
else:
return StringIO("") | python | def get_requirements_file_from_url(url):
response = requests.get(url)
if response.status_code == 200:
return StringIO(response.text)
else:
return StringIO("") | [
"def",
"get_requirements_file_from_url",
"(",
"url",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
")",
"if",
"response",
".",
"status_code",
"==",
"200",
":",
"return",
"StringIO",
"(",
"response",
".",
"text",
")",
"else",
":",
"return",... | fetches the requiremets from the url | [
"fetches",
"the",
"requiremets",
"from",
"the",
"url"
] | b9d61495123b26160fad647a0230d387d92b0841 | https://github.com/sesh/piprot/blob/b9d61495123b26160fad647a0230d387d92b0841/piprot/providers/github.py#L52-L59 |
25,908 | dmort27/panphon | panphon/permissive.py | PermissiveFeatureTable.longest_one_seg_prefix | def longest_one_seg_prefix(self, word):
"""Return longest IPA Unicode prefix of `word`
Args:
word (unicode): word as IPA string
Returns:
unicode: longest single-segment prefix of `word`
"""
match = self.seg_regex.match(word)
if match:
return match.group(0)
else:
return '' | python | def longest_one_seg_prefix(self, word):
match = self.seg_regex.match(word)
if match:
return match.group(0)
else:
return '' | [
"def",
"longest_one_seg_prefix",
"(",
"self",
",",
"word",
")",
":",
"match",
"=",
"self",
".",
"seg_regex",
".",
"match",
"(",
"word",
")",
"if",
"match",
":",
"return",
"match",
".",
"group",
"(",
"0",
")",
"else",
":",
"return",
"''"
] | Return longest IPA Unicode prefix of `word`
Args:
word (unicode): word as IPA string
Returns:
unicode: longest single-segment prefix of `word` | [
"Return",
"longest",
"IPA",
"Unicode",
"prefix",
"of",
"word"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/permissive.py#L144-L157 |
25,909 | dmort27/panphon | panphon/permissive.py | PermissiveFeatureTable.filter_segs | def filter_segs(self, segs):
"""Given list of strings, return only those which are valid segments.
Args:
segs (list): list of unicode values
Returns:
list: values in `segs` that are valid segments (according to the
definititions of bases and diacritics/modifiers known to the
object
"""
def whole_seg(seg):
m = self.seg_regex.match(seg)
if m and m.group(0) == seg:
return True
else:
return False
return list(filter(whole_seg, segs)) | python | def filter_segs(self, segs):
def whole_seg(seg):
m = self.seg_regex.match(seg)
if m and m.group(0) == seg:
return True
else:
return False
return list(filter(whole_seg, segs)) | [
"def",
"filter_segs",
"(",
"self",
",",
"segs",
")",
":",
"def",
"whole_seg",
"(",
"seg",
")",
":",
"m",
"=",
"self",
".",
"seg_regex",
".",
"match",
"(",
"seg",
")",
"if",
"m",
"and",
"m",
".",
"group",
"(",
"0",
")",
"==",
"seg",
":",
"return... | Given list of strings, return only those which are valid segments.
Args:
segs (list): list of unicode values
Returns:
list: values in `segs` that are valid segments (according to the
definititions of bases and diacritics/modifiers known to the
object | [
"Given",
"list",
"of",
"strings",
"return",
"only",
"those",
"which",
"are",
"valid",
"segments",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/permissive.py#L174-L191 |
25,910 | dmort27/panphon | panphon/bin/validate_ipa.py | Validator.validate_line | def validate_line(self, line):
"""Validate Unicode IPA string relative to panphon.
line -- String of IPA characters. Can contain whitespace and limited
punctuation.
"""
line0 = line
pos = 0
while line:
seg_m = self.ft.seg_regex.match(line)
wsp_m = self.ws_punc_regex.match(line)
if seg_m:
length = len(seg_m.group(0))
line = line[length:]
pos += length
elif wsp_m:
length = len(wsp_m.group(0))
line = line[length:]
pos += length
else:
msg = 'IPA not valid at position {} in "{}".'.format(pos, line0.strip())
# msg = msg.decode('utf-8')
print(msg, file=sys.stderr)
line = line[1:]
pos += 1 | python | def validate_line(self, line):
line0 = line
pos = 0
while line:
seg_m = self.ft.seg_regex.match(line)
wsp_m = self.ws_punc_regex.match(line)
if seg_m:
length = len(seg_m.group(0))
line = line[length:]
pos += length
elif wsp_m:
length = len(wsp_m.group(0))
line = line[length:]
pos += length
else:
msg = 'IPA not valid at position {} in "{}".'.format(pos, line0.strip())
# msg = msg.decode('utf-8')
print(msg, file=sys.stderr)
line = line[1:]
pos += 1 | [
"def",
"validate_line",
"(",
"self",
",",
"line",
")",
":",
"line0",
"=",
"line",
"pos",
"=",
"0",
"while",
"line",
":",
"seg_m",
"=",
"self",
".",
"ft",
".",
"seg_regex",
".",
"match",
"(",
"line",
")",
"wsp_m",
"=",
"self",
".",
"ws_punc_regex",
... | Validate Unicode IPA string relative to panphon.
line -- String of IPA characters. Can contain whitespace and limited
punctuation. | [
"Validate",
"Unicode",
"IPA",
"string",
"relative",
"to",
"panphon",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/bin/validate_ipa.py#L26-L50 |
25,911 | dmort27/panphon | panphon/_panphon.py | segment_text | def segment_text(text, seg_regex=SEG_REGEX):
"""Return an iterator of segments in the text.
Args:
text (unicode): string of IPA Unicode text
seg_regex (_regex.Pattern): compiled regex defining a segment (base +
modifiers)
Return:
generator: segments in the input text
"""
for m in seg_regex.finditer(text):
yield m.group(0) | python | def segment_text(text, seg_regex=SEG_REGEX):
for m in seg_regex.finditer(text):
yield m.group(0) | [
"def",
"segment_text",
"(",
"text",
",",
"seg_regex",
"=",
"SEG_REGEX",
")",
":",
"for",
"m",
"in",
"seg_regex",
".",
"finditer",
"(",
"text",
")",
":",
"yield",
"m",
".",
"group",
"(",
"0",
")"
] | Return an iterator of segments in the text.
Args:
text (unicode): string of IPA Unicode text
seg_regex (_regex.Pattern): compiled regex defining a segment (base +
modifiers)
Return:
generator: segments in the input text | [
"Return",
"an",
"iterator",
"of",
"segments",
"in",
"the",
"text",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L33-L45 |
25,912 | dmort27/panphon | panphon/_panphon.py | FeatureTable.fts_match | def fts_match(self, features, segment):
"""Answer question "are `ft_mask`'s features a subset of ft_seg?"
This is like `FeatureTable.match` except that it checks whether a
segment is valid and returns None if it is not.
Args:
features (set): pattern defined as set of (value, feature) tuples
segment (set): segment defined as a set of (value, feature) tuples
Returns:
bool: True iff all features in `ft_mask` are also in `ft_seg`; None
if segment is not valid
"""
features = set(features)
if self.seg_known(segment):
return features <= self.fts(segment)
else:
return None | python | def fts_match(self, features, segment):
features = set(features)
if self.seg_known(segment):
return features <= self.fts(segment)
else:
return None | [
"def",
"fts_match",
"(",
"self",
",",
"features",
",",
"segment",
")",
":",
"features",
"=",
"set",
"(",
"features",
")",
"if",
"self",
".",
"seg_known",
"(",
"segment",
")",
":",
"return",
"features",
"<=",
"self",
".",
"fts",
"(",
"segment",
")",
"... | Answer question "are `ft_mask`'s features a subset of ft_seg?"
This is like `FeatureTable.match` except that it checks whether a
segment is valid and returns None if it is not.
Args:
features (set): pattern defined as set of (value, feature) tuples
segment (set): segment defined as a set of (value, feature) tuples
Returns:
bool: True iff all features in `ft_mask` are also in `ft_seg`; None
if segment is not valid | [
"Answer",
"question",
"are",
"ft_mask",
"s",
"features",
"a",
"subset",
"of",
"ft_seg?"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L189-L207 |
25,913 | dmort27/panphon | panphon/_panphon.py | FeatureTable.longest_one_seg_prefix | def longest_one_seg_prefix(self, word):
"""Return longest Unicode IPA prefix of a word
Args:
word (unicode): input word as Unicode IPA string
Returns:
unicode: longest single-segment prefix of `word` in database
"""
for i in range(self.longest_seg, 0, -1):
if word[:i] in self.seg_dict:
return word[:i]
return '' | python | def longest_one_seg_prefix(self, word):
for i in range(self.longest_seg, 0, -1):
if word[:i] in self.seg_dict:
return word[:i]
return '' | [
"def",
"longest_one_seg_prefix",
"(",
"self",
",",
"word",
")",
":",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"longest_seg",
",",
"0",
",",
"-",
"1",
")",
":",
"if",
"word",
"[",
":",
"i",
"]",
"in",
"self",
".",
"seg_dict",
":",
"return",
"w... | Return longest Unicode IPA prefix of a word
Args:
word (unicode): input word as Unicode IPA string
Returns:
unicode: longest single-segment prefix of `word` in database | [
"Return",
"longest",
"Unicode",
"IPA",
"prefix",
"of",
"a",
"word"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L209-L221 |
25,914 | dmort27/panphon | panphon/_panphon.py | FeatureTable.validate_word | def validate_word(self, word):
"""Returns True if `word` consists exhaustively of valid IPA segments
Args:
word (unicode): input word as Unicode IPA string
Returns:
bool: True if `word` can be divided exhaustively into IPA segments
that exist in the database
"""
while word:
match = self.seg_regex.match(word)
if match:
word = word[len(match.group(0)):]
else:
# print('{}\t->\t{}\t'.format(orig, word).encode('utf-8'), file=sys.stderr)
return False
return True | python | def validate_word(self, word):
while word:
match = self.seg_regex.match(word)
if match:
word = word[len(match.group(0)):]
else:
# print('{}\t->\t{}\t'.format(orig, word).encode('utf-8'), file=sys.stderr)
return False
return True | [
"def",
"validate_word",
"(",
"self",
",",
"word",
")",
":",
"while",
"word",
":",
"match",
"=",
"self",
".",
"seg_regex",
".",
"match",
"(",
"word",
")",
"if",
"match",
":",
"word",
"=",
"word",
"[",
"len",
"(",
"match",
".",
"group",
"(",
"0",
"... | Returns True if `word` consists exhaustively of valid IPA segments
Args:
word (unicode): input word as Unicode IPA string
Returns:
bool: True if `word` can be divided exhaustively into IPA segments
that exist in the database | [
"Returns",
"True",
"if",
"word",
"consists",
"exhaustively",
"of",
"valid",
"IPA",
"segments"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L223-L241 |
25,915 | dmort27/panphon | panphon/_panphon.py | FeatureTable.segs | def segs(self, word):
"""Returns a list of segments from a word
Args:
word (unicode): input word as Unicode IPA string
Returns:
list: list of strings corresponding to segments found in `word`
"""
return [m.group('all') for m in self.seg_regex.finditer(word)] | python | def segs(self, word):
return [m.group('all') for m in self.seg_regex.finditer(word)] | [
"def",
"segs",
"(",
"self",
",",
"word",
")",
":",
"return",
"[",
"m",
".",
"group",
"(",
"'all'",
")",
"for",
"m",
"in",
"self",
".",
"seg_regex",
".",
"finditer",
"(",
"word",
")",
"]"
] | Returns a list of segments from a word
Args:
word (unicode): input word as Unicode IPA string
Returns:
list: list of strings corresponding to segments found in `word` | [
"Returns",
"a",
"list",
"of",
"segments",
"from",
"a",
"word"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L243-L252 |
25,916 | dmort27/panphon | panphon/_panphon.py | FeatureTable.word_fts | def word_fts(self, word):
"""Return featural analysis of `word`
Args:
word (unicode): one or more IPA segments
Returns:
list: list of lists (value, feature) tuples where each inner list
corresponds to a segment in `word`
"""
return list(map(self.fts, self.segs(word))) | python | def word_fts(self, word):
return list(map(self.fts, self.segs(word))) | [
"def",
"word_fts",
"(",
"self",
",",
"word",
")",
":",
"return",
"list",
"(",
"map",
"(",
"self",
".",
"fts",
",",
"self",
".",
"segs",
"(",
"word",
")",
")",
")"
] | Return featural analysis of `word`
Args:
word (unicode): one or more IPA segments
Returns:
list: list of lists (value, feature) tuples where each inner list
corresponds to a segment in `word` | [
"Return",
"featural",
"analysis",
"of",
"word"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L254-L264 |
25,917 | dmort27/panphon | panphon/_panphon.py | FeatureTable.filter_string | def filter_string(self, word):
"""Return a string like the input but containing only legal IPA segments
Args:
word (unicode): input string to be filtered
Returns:
unicode: string identical to `word` but with invalid IPA segments
absent
"""
segs = [m.group(0) for m in self.seg_regex.finditer(word)]
return ''.join(segs) | python | def filter_string(self, word):
segs = [m.group(0) for m in self.seg_regex.finditer(word)]
return ''.join(segs) | [
"def",
"filter_string",
"(",
"self",
",",
"word",
")",
":",
"segs",
"=",
"[",
"m",
".",
"group",
"(",
"0",
")",
"for",
"m",
"in",
"self",
".",
"seg_regex",
".",
"finditer",
"(",
"word",
")",
"]",
"return",
"''",
".",
"join",
"(",
"segs",
")"
] | Return a string like the input but containing only legal IPA segments
Args:
word (unicode): input string to be filtered
Returns:
unicode: string identical to `word` but with invalid IPA segments
absent | [
"Return",
"a",
"string",
"like",
"the",
"input",
"but",
"containing",
"only",
"legal",
"IPA",
"segments"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L325-L337 |
25,918 | dmort27/panphon | panphon/_panphon.py | FeatureTable.fts_intersection | def fts_intersection(self, segs):
"""Return the features shared by `segs`
Args:
segs (list): list of Unicode IPA segments
Returns:
set: set of (value, feature) tuples shared by the valid segments in
`segs`
"""
fts_vecs = [self.fts(s) for s in self.filter_segs(segs)]
return reduce(lambda a, b: a & b, fts_vecs) | python | def fts_intersection(self, segs):
fts_vecs = [self.fts(s) for s in self.filter_segs(segs)]
return reduce(lambda a, b: a & b, fts_vecs) | [
"def",
"fts_intersection",
"(",
"self",
",",
"segs",
")",
":",
"fts_vecs",
"=",
"[",
"self",
".",
"fts",
"(",
"s",
")",
"for",
"s",
"in",
"self",
".",
"filter_segs",
"(",
"segs",
")",
"]",
"return",
"reduce",
"(",
"lambda",
"a",
",",
"b",
":",
"a... | Return the features shared by `segs`
Args:
segs (list): list of Unicode IPA segments
Returns:
set: set of (value, feature) tuples shared by the valid segments in
`segs` | [
"Return",
"the",
"features",
"shared",
"by",
"segs"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L339-L350 |
25,919 | dmort27/panphon | panphon/_panphon.py | FeatureTable.fts_match_any | def fts_match_any(self, fts, inv):
"""Return `True` if any segment in `inv` matches the features in `fts`
Args:
fts (list): a collection of (value, feature) tuples
inv (list): a collection of IPA segments represented as Unicode
strings
Returns:
bool: `True` if any segment in `inv` matches the features in `fts`
"""
return any([self.fts_match(fts, s) for s in inv]) | python | def fts_match_any(self, fts, inv):
return any([self.fts_match(fts, s) for s in inv]) | [
"def",
"fts_match_any",
"(",
"self",
",",
"fts",
",",
"inv",
")",
":",
"return",
"any",
"(",
"[",
"self",
".",
"fts_match",
"(",
"fts",
",",
"s",
")",
"for",
"s",
"in",
"inv",
"]",
")"
] | Return `True` if any segment in `inv` matches the features in `fts`
Args:
fts (list): a collection of (value, feature) tuples
inv (list): a collection of IPA segments represented as Unicode
strings
Returns:
bool: `True` if any segment in `inv` matches the features in `fts` | [
"Return",
"True",
"if",
"any",
"segment",
"in",
"inv",
"matches",
"the",
"features",
"in",
"fts"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L352-L363 |
25,920 | dmort27/panphon | panphon/_panphon.py | FeatureTable.fts_match_all | def fts_match_all(self, fts, inv):
"""Return `True` if all segments in `inv` matches the features in fts
Args:
fts (list): a collection of (value, feature) tuples
inv (list): a collection of IPA segments represented as Unicode
strings
Returns:
bool: `True` if all segments in `inv` matches the features in `fts`
"""
return all([self.fts_match(fts, s) for s in inv]) | python | def fts_match_all(self, fts, inv):
return all([self.fts_match(fts, s) for s in inv]) | [
"def",
"fts_match_all",
"(",
"self",
",",
"fts",
",",
"inv",
")",
":",
"return",
"all",
"(",
"[",
"self",
".",
"fts_match",
"(",
"fts",
",",
"s",
")",
"for",
"s",
"in",
"inv",
"]",
")"
] | Return `True` if all segments in `inv` matches the features in fts
Args:
fts (list): a collection of (value, feature) tuples
inv (list): a collection of IPA segments represented as Unicode
strings
Returns:
bool: `True` if all segments in `inv` matches the features in `fts` | [
"Return",
"True",
"if",
"all",
"segments",
"in",
"inv",
"matches",
"the",
"features",
"in",
"fts"
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L365-L376 |
25,921 | dmort27/panphon | panphon/_panphon.py | FeatureTable.fts_contrast2 | def fts_contrast2(self, fs, ft_name, inv):
"""Return `True` if there is a segment in `inv` that contrasts in feature
`ft_name`.
Args:
fs (list): feature specifications used to filter `inv`.
ft_name (str): name of the feature where contrast must be present.
inv (list): collection of segments represented as Unicode segments.
Returns:
bool: `True` if two segments in `inv` are identical in features except
for feature `ft_name`
"""
inv_fts = [self.fts(x) for x in inv if set(fs) <= self.fts(x)]
for a in inv_fts:
for b in inv_fts:
if a != b:
diff = a ^ b
if len(diff) == 2:
if all([nm == ft_name for (_, nm) in diff]):
return True
return False | python | def fts_contrast2(self, fs, ft_name, inv):
inv_fts = [self.fts(x) for x in inv if set(fs) <= self.fts(x)]
for a in inv_fts:
for b in inv_fts:
if a != b:
diff = a ^ b
if len(diff) == 2:
if all([nm == ft_name for (_, nm) in diff]):
return True
return False | [
"def",
"fts_contrast2",
"(",
"self",
",",
"fs",
",",
"ft_name",
",",
"inv",
")",
":",
"inv_fts",
"=",
"[",
"self",
".",
"fts",
"(",
"x",
")",
"for",
"x",
"in",
"inv",
"if",
"set",
"(",
"fs",
")",
"<=",
"self",
".",
"fts",
"(",
"x",
")",
"]",
... | Return `True` if there is a segment in `inv` that contrasts in feature
`ft_name`.
Args:
fs (list): feature specifications used to filter `inv`.
ft_name (str): name of the feature where contrast must be present.
inv (list): collection of segments represented as Unicode segments.
Returns:
bool: `True` if two segments in `inv` are identical in features except
for feature `ft_name` | [
"Return",
"True",
"if",
"there",
"is",
"a",
"segment",
"in",
"inv",
"that",
"contrasts",
"in",
"feature",
"ft_name",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L378-L399 |
25,922 | dmort27/panphon | panphon/_panphon.py | FeatureTable.fts_count | def fts_count(self, fts, inv):
"""Return the count of segments in an inventory matching a given
feature mask.
Args:
fts (set): feature mask given as a set of (value, feature) tuples
inv (set): inventory of segments (as Unicode IPA strings)
Returns:
int: number of segments in `inv` that match feature mask `fts`
"""
return len(list(filter(lambda s: self.fts_match(fts, s), inv))) | python | def fts_count(self, fts, inv):
return len(list(filter(lambda s: self.fts_match(fts, s), inv))) | [
"def",
"fts_count",
"(",
"self",
",",
"fts",
",",
"inv",
")",
":",
"return",
"len",
"(",
"list",
"(",
"filter",
"(",
"lambda",
"s",
":",
"self",
".",
"fts_match",
"(",
"fts",
",",
"s",
")",
",",
"inv",
")",
")",
")"
] | Return the count of segments in an inventory matching a given
feature mask.
Args:
fts (set): feature mask given as a set of (value, feature) tuples
inv (set): inventory of segments (as Unicode IPA strings)
Returns:
int: number of segments in `inv` that match feature mask `fts` | [
"Return",
"the",
"count",
"of",
"segments",
"in",
"an",
"inventory",
"matching",
"a",
"given",
"feature",
"mask",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L401-L412 |
25,923 | dmort27/panphon | panphon/_panphon.py | FeatureTable.match_pattern | def match_pattern(self, pat, word):
"""Implements fixed-width pattern matching.
Matches just in case pattern is the same length (in segments) as the
word and each of the segments in the pattern is a featural subset of the
corresponding segment in the word. Matches return the corresponding list
of feature sets; failed matches return None.
Args:
pat (list): pattern consisting of a sequence of sets of (value,
feature) tuples
word (unicode): a Unicode IPA string consisting of zero or more
segments
Returns:
list: corresponding list of feature sets or, if there is no match,
None
"""
segs = self.word_fts(word)
if len(pat) != len(segs):
return None
else:
if all([set(p) <= s for (p, s) in zip(pat, segs)]):
return segs | python | def match_pattern(self, pat, word):
segs = self.word_fts(word)
if len(pat) != len(segs):
return None
else:
if all([set(p) <= s for (p, s) in zip(pat, segs)]):
return segs | [
"def",
"match_pattern",
"(",
"self",
",",
"pat",
",",
"word",
")",
":",
"segs",
"=",
"self",
".",
"word_fts",
"(",
"word",
")",
"if",
"len",
"(",
"pat",
")",
"!=",
"len",
"(",
"segs",
")",
":",
"return",
"None",
"else",
":",
"if",
"all",
"(",
"... | Implements fixed-width pattern matching.
Matches just in case pattern is the same length (in segments) as the
word and each of the segments in the pattern is a featural subset of the
corresponding segment in the word. Matches return the corresponding list
of feature sets; failed matches return None.
Args:
pat (list): pattern consisting of a sequence of sets of (value,
feature) tuples
word (unicode): a Unicode IPA string consisting of zero or more
segments
Returns:
list: corresponding list of feature sets or, if there is no match,
None | [
"Implements",
"fixed",
"-",
"width",
"pattern",
"matching",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L414-L437 |
25,924 | dmort27/panphon | panphon/_panphon.py | FeatureTable.compile_regex_from_str | def compile_regex_from_str(self, ft_str):
"""Given a string describing features masks for a sequence of segments,
return a regex matching the corresponding strings.
Args:
ft_str (str): feature masks, each enclosed in square brackets, in
which the features are delimited by any standard delimiter.
Returns:
Pattern: regular expression pattern equivalent to `ft_str`
"""
sequence = []
for m in re.finditer(r'\[([^]]+)\]', ft_str):
ft_mask = fts(m.group(1))
segs = self.all_segs_matching_fts(ft_mask)
sub_pat = '({})'.format('|'.join(segs))
sequence.append(sub_pat)
pattern = ''.join(sequence)
regex = re.compile(pattern)
return regex | python | def compile_regex_from_str(self, ft_str):
sequence = []
for m in re.finditer(r'\[([^]]+)\]', ft_str):
ft_mask = fts(m.group(1))
segs = self.all_segs_matching_fts(ft_mask)
sub_pat = '({})'.format('|'.join(segs))
sequence.append(sub_pat)
pattern = ''.join(sequence)
regex = re.compile(pattern)
return regex | [
"def",
"compile_regex_from_str",
"(",
"self",
",",
"ft_str",
")",
":",
"sequence",
"=",
"[",
"]",
"for",
"m",
"in",
"re",
".",
"finditer",
"(",
"r'\\[([^]]+)\\]'",
",",
"ft_str",
")",
":",
"ft_mask",
"=",
"fts",
"(",
"m",
".",
"group",
"(",
"1",
")",... | Given a string describing features masks for a sequence of segments,
return a regex matching the corresponding strings.
Args:
ft_str (str): feature masks, each enclosed in square brackets, in
which the features are delimited by any standard delimiter.
Returns:
Pattern: regular expression pattern equivalent to `ft_str` | [
"Given",
"a",
"string",
"describing",
"features",
"masks",
"for",
"a",
"sequence",
"of",
"segments",
"return",
"a",
"regex",
"matching",
"the",
"corresponding",
"strings",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L476-L496 |
25,925 | dmort27/panphon | panphon/_panphon.py | FeatureTable.segment_to_vector | def segment_to_vector(self, seg):
"""Given a Unicode IPA segment, return a list of feature specificiations
in cannonical order.
Args:
seg (unicode): IPA consonant or vowel
Returns:
list: feature specifications ('+'/'-'/'0') in the order from
`FeatureTable.names`
"""
ft_dict = {ft: val for (val, ft) in self.fts(seg)}
return [ft_dict[name] for name in self.names] | python | def segment_to_vector(self, seg):
ft_dict = {ft: val for (val, ft) in self.fts(seg)}
return [ft_dict[name] for name in self.names] | [
"def",
"segment_to_vector",
"(",
"self",
",",
"seg",
")",
":",
"ft_dict",
"=",
"{",
"ft",
":",
"val",
"for",
"(",
"val",
",",
"ft",
")",
"in",
"self",
".",
"fts",
"(",
"seg",
")",
"}",
"return",
"[",
"ft_dict",
"[",
"name",
"]",
"for",
"name",
... | Given a Unicode IPA segment, return a list of feature specificiations
in cannonical order.
Args:
seg (unicode): IPA consonant or vowel
Returns:
list: feature specifications ('+'/'-'/'0') in the order from
`FeatureTable.names` | [
"Given",
"a",
"Unicode",
"IPA",
"segment",
"return",
"a",
"list",
"of",
"feature",
"specificiations",
"in",
"cannonical",
"order",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L498-L510 |
25,926 | dmort27/panphon | panphon/_panphon.py | FeatureTable.word_to_vector_list | def word_to_vector_list(self, word, numeric=False, xsampa=False):
"""Return a list of feature vectors, given a Unicode IPA word.
Args:
word (unicode): string in IPA
numeric (bool): if True, return features as numeric values instead
of strings
Returns:
list: a list of lists of '+'/'-'/'0' or 1/-1/0
"""
if xsampa:
word = self.xsampa.convert(word)
tensor = list(map(self.segment_to_vector, self.segs(word)))
if numeric:
return self.tensor_to_numeric(tensor)
else:
return tensor | python | def word_to_vector_list(self, word, numeric=False, xsampa=False):
if xsampa:
word = self.xsampa.convert(word)
tensor = list(map(self.segment_to_vector, self.segs(word)))
if numeric:
return self.tensor_to_numeric(tensor)
else:
return tensor | [
"def",
"word_to_vector_list",
"(",
"self",
",",
"word",
",",
"numeric",
"=",
"False",
",",
"xsampa",
"=",
"False",
")",
":",
"if",
"xsampa",
":",
"word",
"=",
"self",
".",
"xsampa",
".",
"convert",
"(",
"word",
")",
"tensor",
"=",
"list",
"(",
"map",... | Return a list of feature vectors, given a Unicode IPA word.
Args:
word (unicode): string in IPA
numeric (bool): if True, return features as numeric values instead
of strings
Returns:
list: a list of lists of '+'/'-'/'0' or 1/-1/0 | [
"Return",
"a",
"list",
"of",
"feature",
"vectors",
"given",
"a",
"Unicode",
"IPA",
"word",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/_panphon.py#L516-L533 |
25,927 | ivanlei/threatbutt | threatbutt/threatbutt.py | ThreatButt.clown_strike_ioc | def clown_strike_ioc(self, ioc):
"""Performs Clown Strike lookup on an IoC.
Args:
ioc - An IoC.
"""
r = requests.get('http://threatbutt.io/api', data='ioc={0}'.format(ioc))
self._output(r.text) | python | def clown_strike_ioc(self, ioc):
r = requests.get('http://threatbutt.io/api', data='ioc={0}'.format(ioc))
self._output(r.text) | [
"def",
"clown_strike_ioc",
"(",
"self",
",",
"ioc",
")",
":",
"r",
"=",
"requests",
".",
"get",
"(",
"'http://threatbutt.io/api'",
",",
"data",
"=",
"'ioc={0}'",
".",
"format",
"(",
"ioc",
")",
")",
"self",
".",
"_output",
"(",
"r",
".",
"text",
")"
] | Performs Clown Strike lookup on an IoC.
Args:
ioc - An IoC. | [
"Performs",
"Clown",
"Strike",
"lookup",
"on",
"an",
"IoC",
"."
] | faff507a4bebfa585d3044427111418c257c34ec | https://github.com/ivanlei/threatbutt/blob/faff507a4bebfa585d3044427111418c257c34ec/threatbutt/threatbutt.py#L20-L27 |
25,928 | ivanlei/threatbutt | threatbutt/threatbutt.py | ThreatButt.bespoke_md5 | def bespoke_md5(self, md5):
"""Performs Bespoke MD5 lookup on an MD5.
Args:
md5 - A hash.
"""
r = requests.post('http://threatbutt.io/api/md5/{0}'.format(md5))
self._output(r.text) | python | def bespoke_md5(self, md5):
r = requests.post('http://threatbutt.io/api/md5/{0}'.format(md5))
self._output(r.text) | [
"def",
"bespoke_md5",
"(",
"self",
",",
"md5",
")",
":",
"r",
"=",
"requests",
".",
"post",
"(",
"'http://threatbutt.io/api/md5/{0}'",
".",
"format",
"(",
"md5",
")",
")",
"self",
".",
"_output",
"(",
"r",
".",
"text",
")"
] | Performs Bespoke MD5 lookup on an MD5.
Args:
md5 - A hash. | [
"Performs",
"Bespoke",
"MD5",
"lookup",
"on",
"an",
"MD5",
"."
] | faff507a4bebfa585d3044427111418c257c34ec | https://github.com/ivanlei/threatbutt/blob/faff507a4bebfa585d3044427111418c257c34ec/threatbutt/threatbutt.py#L29-L36 |
25,929 | dmort27/panphon | panphon/sonority.py | Sonority.sonority_from_fts | def sonority_from_fts(self, seg):
"""Given a segment as features, returns the sonority on a scale of 1
to 9.
Args:
seg (list): collection of (value, feature) pairs representing
a segment (vowel or consonant)
Returns:
int: sonority of `seg` between 1 and 9
"""
def match(m):
return self.fm.match(fts(m), seg)
minusHi = BoolTree(match('-hi'), 9, 8)
minusNas = BoolTree(match('-nas'), 6, 5)
plusVoi1 = BoolTree(match('+voi'), 4, 3)
plusVoi2 = BoolTree(match('+voi'), 2, 1)
plusCont = BoolTree(match('+cont'), plusVoi1, plusVoi2)
plusSon = BoolTree(match('+son'), minusNas, plusCont)
minusCons = BoolTree(match('-cons'), 7, plusSon)
plusSyl = BoolTree(match('+syl'), minusHi, minusCons)
return plusSyl.get_value() | python | def sonority_from_fts(self, seg):
def match(m):
return self.fm.match(fts(m), seg)
minusHi = BoolTree(match('-hi'), 9, 8)
minusNas = BoolTree(match('-nas'), 6, 5)
plusVoi1 = BoolTree(match('+voi'), 4, 3)
plusVoi2 = BoolTree(match('+voi'), 2, 1)
plusCont = BoolTree(match('+cont'), plusVoi1, plusVoi2)
plusSon = BoolTree(match('+son'), minusNas, plusCont)
minusCons = BoolTree(match('-cons'), 7, plusSon)
plusSyl = BoolTree(match('+syl'), minusHi, minusCons)
return plusSyl.get_value() | [
"def",
"sonority_from_fts",
"(",
"self",
",",
"seg",
")",
":",
"def",
"match",
"(",
"m",
")",
":",
"return",
"self",
".",
"fm",
".",
"match",
"(",
"fts",
"(",
"m",
")",
",",
"seg",
")",
"minusHi",
"=",
"BoolTree",
"(",
"match",
"(",
"'-hi'",
")",... | Given a segment as features, returns the sonority on a scale of 1
to 9.
Args:
seg (list): collection of (value, feature) pairs representing
a segment (vowel or consonant)
Returns:
int: sonority of `seg` between 1 and 9 | [
"Given",
"a",
"segment",
"as",
"features",
"returns",
"the",
"sonority",
"on",
"a",
"scale",
"of",
"1",
"to",
"9",
"."
] | 17eaa482e3edb211f3a8138137d76e4b9246d201 | https://github.com/dmort27/panphon/blob/17eaa482e3edb211f3a8138137d76e4b9246d201/panphon/sonority.py#L50-L73 |
25,930 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.from_dict | def from_dict(cls, d):
"""Create cache hierarchy from dictionary."""
main_memory = MainMemory()
caches = {}
referred_caches = set()
# First pass, create all named caches and collect references
for name, conf in d.items():
caches[name] = Cache(name=name,
**{k: v for k, v in conf.items()
if k not in ['store_to', 'load_from', 'victims_to']})
if 'store_to' in conf:
referred_caches.add(conf['store_to'])
if 'load_from' in conf:
referred_caches.add(conf['load_from'])
if 'victims_to' in conf:
referred_caches.add(conf['victims_to'])
# Second pass, connect caches
for name, conf in d.items():
if 'store_to' in conf and conf['store_to'] is not None:
caches[name].set_store_to(caches[conf['store_to']])
if 'load_from' in conf and conf['load_from'] is not None:
caches[name].set_load_from(caches[conf['load_from']])
if 'victims_to' in conf and conf['victims_to'] is not None:
caches[name].set_victims_to(caches[conf['victims_to']])
# Find first level (not target of any load_from or store_to)
first_level = set(d.keys()) - referred_caches
assert len(first_level) == 1, "Unable to find first cache level."
first_level = caches[list(first_level)[0]]
# Find last level caches (has no load_from or store_to target)
last_level_load = c = first_level
while c is not None:
last_level_load = c
c = c.load_from
assert last_level_load is not None, "Unable to find last cache level."
last_level_store = c = first_level
while c is not None:
last_level_store = c
c = c.store_to
assert last_level_store is not None, "Unable to find last cache level."
# Set main memory connections
main_memory.load_to(last_level_load)
main_memory.store_from(last_level_store)
return cls(first_level, main_memory), caches, main_memory | python | def from_dict(cls, d):
main_memory = MainMemory()
caches = {}
referred_caches = set()
# First pass, create all named caches and collect references
for name, conf in d.items():
caches[name] = Cache(name=name,
**{k: v for k, v in conf.items()
if k not in ['store_to', 'load_from', 'victims_to']})
if 'store_to' in conf:
referred_caches.add(conf['store_to'])
if 'load_from' in conf:
referred_caches.add(conf['load_from'])
if 'victims_to' in conf:
referred_caches.add(conf['victims_to'])
# Second pass, connect caches
for name, conf in d.items():
if 'store_to' in conf and conf['store_to'] is not None:
caches[name].set_store_to(caches[conf['store_to']])
if 'load_from' in conf and conf['load_from'] is not None:
caches[name].set_load_from(caches[conf['load_from']])
if 'victims_to' in conf and conf['victims_to'] is not None:
caches[name].set_victims_to(caches[conf['victims_to']])
# Find first level (not target of any load_from or store_to)
first_level = set(d.keys()) - referred_caches
assert len(first_level) == 1, "Unable to find first cache level."
first_level = caches[list(first_level)[0]]
# Find last level caches (has no load_from or store_to target)
last_level_load = c = first_level
while c is not None:
last_level_load = c
c = c.load_from
assert last_level_load is not None, "Unable to find last cache level."
last_level_store = c = first_level
while c is not None:
last_level_store = c
c = c.store_to
assert last_level_store is not None, "Unable to find last cache level."
# Set main memory connections
main_memory.load_to(last_level_load)
main_memory.store_from(last_level_store)
return cls(first_level, main_memory), caches, main_memory | [
"def",
"from_dict",
"(",
"cls",
",",
"d",
")",
":",
"main_memory",
"=",
"MainMemory",
"(",
")",
"caches",
"=",
"{",
"}",
"referred_caches",
"=",
"set",
"(",
")",
"# First pass, create all named caches and collect references",
"for",
"name",
",",
"conf",
"in",
... | Create cache hierarchy from dictionary. | [
"Create",
"cache",
"hierarchy",
"from",
"dictionary",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L49-L98 |
25,931 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.load | def load(self, addr, length=1):
"""
Load one or more addresses.
:param addr: byte address of load location
:param length: All address from addr until addr+length (exclusive) are
loaded (default: 1)
"""
if addr is None:
return
elif not isinstance(addr, Iterable):
self.first_level.load(addr, length=length)
else:
self.first_level.iterload(addr, length=length) | python | def load(self, addr, length=1):
if addr is None:
return
elif not isinstance(addr, Iterable):
self.first_level.load(addr, length=length)
else:
self.first_level.iterload(addr, length=length) | [
"def",
"load",
"(",
"self",
",",
"addr",
",",
"length",
"=",
"1",
")",
":",
"if",
"addr",
"is",
"None",
":",
"return",
"elif",
"not",
"isinstance",
"(",
"addr",
",",
"Iterable",
")",
":",
"self",
".",
"first_level",
".",
"load",
"(",
"addr",
",",
... | Load one or more addresses.
:param addr: byte address of load location
:param length: All address from addr until addr+length (exclusive) are
loaded (default: 1) | [
"Load",
"one",
"or",
"more",
"addresses",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L116-L129 |
25,932 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.store | def store(self, addr, length=1, non_temporal=False):
"""
Store one or more adresses.
:param addr: byte address of store location
:param length: All address from addr until addr+length (exclusive) are
stored (default: 1)
:param non_temporal: if True, no write-allocate will be issued, but cacheline will be zeroed
"""
if non_temporal:
raise ValueError("non_temporal stores are not yet supported")
if addr is None:
return
elif not isinstance(addr, Iterable):
self.first_level.store(addr, length=length)
else:
self.first_level.iterstore(addr, length=length) | python | def store(self, addr, length=1, non_temporal=False):
if non_temporal:
raise ValueError("non_temporal stores are not yet supported")
if addr is None:
return
elif not isinstance(addr, Iterable):
self.first_level.store(addr, length=length)
else:
self.first_level.iterstore(addr, length=length) | [
"def",
"store",
"(",
"self",
",",
"addr",
",",
"length",
"=",
"1",
",",
"non_temporal",
"=",
"False",
")",
":",
"if",
"non_temporal",
":",
"raise",
"ValueError",
"(",
"\"non_temporal stores are not yet supported\"",
")",
"if",
"addr",
"is",
"None",
":",
"ret... | Store one or more adresses.
:param addr: byte address of store location
:param length: All address from addr until addr+length (exclusive) are
stored (default: 1)
:param non_temporal: if True, no write-allocate will be issued, but cacheline will be zeroed | [
"Store",
"one",
"or",
"more",
"adresses",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L131-L148 |
25,933 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.loadstore | def loadstore(self, addrs, length=1):
"""
Load and store address in order given.
:param addrs: iteratable of address tuples: [(loads, stores), ...]
:param length: will load and store all bytes between addr and
addr+length (for each address)
"""
if not isinstance(addrs, Iterable):
raise ValueError("addr must be iteratable")
self.first_level.loadstore(addrs, length=length) | python | def loadstore(self, addrs, length=1):
if not isinstance(addrs, Iterable):
raise ValueError("addr must be iteratable")
self.first_level.loadstore(addrs, length=length) | [
"def",
"loadstore",
"(",
"self",
",",
"addrs",
",",
"length",
"=",
"1",
")",
":",
"if",
"not",
"isinstance",
"(",
"addrs",
",",
"Iterable",
")",
":",
"raise",
"ValueError",
"(",
"\"addr must be iteratable\"",
")",
"self",
".",
"first_level",
".",
"loadstor... | Load and store address in order given.
:param addrs: iteratable of address tuples: [(loads, stores), ...]
:param length: will load and store all bytes between addr and
addr+length (for each address) | [
"Load",
"and",
"store",
"address",
"in",
"order",
"given",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L150-L161 |
25,934 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.print_stats | def print_stats(self, header=True, file=sys.stdout):
"""Pretty print stats table."""
if header:
print("CACHE {:*^18} {:*^18} {:*^18} {:*^18} {:*^18}".format(
"HIT", "MISS", "LOAD", "STORE", "EVICT"), file=file)
for s in self.stats():
print("{name:>5} {HIT_count:>6} ({HIT_byte:>8}B) {MISS_count:>6} ({MISS_byte:>8}B) "
"{LOAD_count:>6} ({LOAD_byte:>8}B) {STORE_count:>6} "
"({STORE_byte:>8}B) {EVICT_count:>6} ({EVICT_byte:>8}B)".format(
HIT_bytes=2342, **s),
file=file) | python | def print_stats(self, header=True, file=sys.stdout):
if header:
print("CACHE {:*^18} {:*^18} {:*^18} {:*^18} {:*^18}".format(
"HIT", "MISS", "LOAD", "STORE", "EVICT"), file=file)
for s in self.stats():
print("{name:>5} {HIT_count:>6} ({HIT_byte:>8}B) {MISS_count:>6} ({MISS_byte:>8}B) "
"{LOAD_count:>6} ({LOAD_byte:>8}B) {STORE_count:>6} "
"({STORE_byte:>8}B) {EVICT_count:>6} ({EVICT_byte:>8}B)".format(
HIT_bytes=2342, **s),
file=file) | [
"def",
"print_stats",
"(",
"self",
",",
"header",
"=",
"True",
",",
"file",
"=",
"sys",
".",
"stdout",
")",
":",
"if",
"header",
":",
"print",
"(",
"\"CACHE {:*^18} {:*^18} {:*^18} {:*^18} {:*^18}\"",
".",
"format",
"(",
"\"HIT\"",
",",
"\"MISS\"",
",",
"\"L... | Pretty print stats table. | [
"Pretty",
"print",
"stats",
"table",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L168-L178 |
25,935 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.levels | def levels(self, with_mem=True):
"""Return cache levels, optionally including main memory."""
p = self.first_level
while p is not None:
yield p
# FIXME bad hack to include victim caches, need a more general solution, probably
# involving recursive tree walking
if p.victims_to is not None and p.victims_to != p.load_from:
yield p.victims_to
if p.store_to is not None and p.store_to != p.load_from and p.store_to != p.victims_to:
yield p.store_to
p = p.load_from
if with_mem:
yield self.main_memory | python | def levels(self, with_mem=True):
p = self.first_level
while p is not None:
yield p
# FIXME bad hack to include victim caches, need a more general solution, probably
# involving recursive tree walking
if p.victims_to is not None and p.victims_to != p.load_from:
yield p.victims_to
if p.store_to is not None and p.store_to != p.load_from and p.store_to != p.victims_to:
yield p.store_to
p = p.load_from
if with_mem:
yield self.main_memory | [
"def",
"levels",
"(",
"self",
",",
"with_mem",
"=",
"True",
")",
":",
"p",
"=",
"self",
".",
"first_level",
"while",
"p",
"is",
"not",
"None",
":",
"yield",
"p",
"# FIXME bad hack to include victim caches, need a more general solution, probably",
"# involving recursiv... | Return cache levels, optionally including main memory. | [
"Return",
"cache",
"levels",
"optionally",
"including",
"main",
"memory",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L180-L194 |
25,936 | RRZE-HPC/pycachesim | cachesim/cache.py | CacheSimulator.count_invalid_entries | def count_invalid_entries(self):
"""Sum of all invalid entry counts from cache levels."""
return sum([c.count_invalid_entries() for c in self.levels(with_mem=False)]) | python | def count_invalid_entries(self):
return sum([c.count_invalid_entries() for c in self.levels(with_mem=False)]) | [
"def",
"count_invalid_entries",
"(",
"self",
")",
":",
"return",
"sum",
"(",
"[",
"c",
".",
"count_invalid_entries",
"(",
")",
"for",
"c",
"in",
"self",
".",
"levels",
"(",
"with_mem",
"=",
"False",
")",
"]",
")"
] | Sum of all invalid entry counts from cache levels. | [
"Sum",
"of",
"all",
"invalid",
"entry",
"counts",
"from",
"cache",
"levels",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L196-L198 |
25,937 | RRZE-HPC/pycachesim | cachesim/cache.py | Cache.set_load_from | def set_load_from(self, load_from):
"""Update load_from in Cache and backend."""
assert load_from is None or isinstance(load_from, Cache), \
"load_from needs to be None or a Cache object."
assert load_from is None or load_from.cl_size <= self.cl_size, \
"cl_size may only increase towards main memory."
self.load_from = load_from
self.backend.load_from = load_from.backend | python | def set_load_from(self, load_from):
assert load_from is None or isinstance(load_from, Cache), \
"load_from needs to be None or a Cache object."
assert load_from is None or load_from.cl_size <= self.cl_size, \
"cl_size may only increase towards main memory."
self.load_from = load_from
self.backend.load_from = load_from.backend | [
"def",
"set_load_from",
"(",
"self",
",",
"load_from",
")",
":",
"assert",
"load_from",
"is",
"None",
"or",
"isinstance",
"(",
"load_from",
",",
"Cache",
")",
",",
"\"load_from needs to be None or a Cache object.\"",
"assert",
"load_from",
"is",
"None",
"or",
"loa... | Update load_from in Cache and backend. | [
"Update",
"load_from",
"in",
"Cache",
"and",
"backend",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L338-L345 |
25,938 | RRZE-HPC/pycachesim | cachesim/cache.py | Cache.set_store_to | def set_store_to(self, store_to):
"""Update store_to in Cache and backend."""
assert store_to is None or isinstance(store_to, Cache), \
"store_to needs to be None or a Cache object."
assert store_to is None or store_to.cl_size <= self.cl_size, \
"cl_size may only increase towards main memory."
self.store_to = store_to
self.backend.store_to = store_to.backend | python | def set_store_to(self, store_to):
assert store_to is None or isinstance(store_to, Cache), \
"store_to needs to be None or a Cache object."
assert store_to is None or store_to.cl_size <= self.cl_size, \
"cl_size may only increase towards main memory."
self.store_to = store_to
self.backend.store_to = store_to.backend | [
"def",
"set_store_to",
"(",
"self",
",",
"store_to",
")",
":",
"assert",
"store_to",
"is",
"None",
"or",
"isinstance",
"(",
"store_to",
",",
"Cache",
")",
",",
"\"store_to needs to be None or a Cache object.\"",
"assert",
"store_to",
"is",
"None",
"or",
"store_to"... | Update store_to in Cache and backend. | [
"Update",
"store_to",
"in",
"Cache",
"and",
"backend",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L347-L354 |
25,939 | RRZE-HPC/pycachesim | cachesim/cache.py | Cache.set_victims_to | def set_victims_to(self, victims_to):
"""Update victims_to in Cache and backend."""
assert victims_to is None or isinstance(victims_to, Cache), \
"store_to needs to be None or a Cache object."
assert victims_to is None or victims_to.cl_size == self.cl_size, \
"cl_size may only increase towards main memory."
self.victims_to = victims_to
self.backend.victims_to = victims_to.backend | python | def set_victims_to(self, victims_to):
assert victims_to is None or isinstance(victims_to, Cache), \
"store_to needs to be None or a Cache object."
assert victims_to is None or victims_to.cl_size == self.cl_size, \
"cl_size may only increase towards main memory."
self.victims_to = victims_to
self.backend.victims_to = victims_to.backend | [
"def",
"set_victims_to",
"(",
"self",
",",
"victims_to",
")",
":",
"assert",
"victims_to",
"is",
"None",
"or",
"isinstance",
"(",
"victims_to",
",",
"Cache",
")",
",",
"\"store_to needs to be None or a Cache object.\"",
"assert",
"victims_to",
"is",
"None",
"or",
... | Update victims_to in Cache and backend. | [
"Update",
"victims_to",
"in",
"Cache",
"and",
"backend",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L356-L363 |
25,940 | RRZE-HPC/pycachesim | cachesim/cache.py | MainMemory.load_to | def load_to(self, last_level_load):
"""Set level where to load from."""
assert isinstance(last_level_load, Cache), \
"last_level needs to be a Cache object."
assert last_level_load.load_from is None, \
"last_level_load must be a last level cache (.load_from is None)."
self.last_level_load = last_level_load | python | def load_to(self, last_level_load):
assert isinstance(last_level_load, Cache), \
"last_level needs to be a Cache object."
assert last_level_load.load_from is None, \
"last_level_load must be a last level cache (.load_from is None)."
self.last_level_load = last_level_load | [
"def",
"load_to",
"(",
"self",
",",
"last_level_load",
")",
":",
"assert",
"isinstance",
"(",
"last_level_load",
",",
"Cache",
")",
",",
"\"last_level needs to be a Cache object.\"",
"assert",
"last_level_load",
".",
"load_from",
"is",
"None",
",",
"\"last_level_load ... | Set level where to load from. | [
"Set",
"level",
"where",
"to",
"load",
"from",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L441-L447 |
25,941 | RRZE-HPC/pycachesim | cachesim/cache.py | MainMemory.store_from | def store_from(self, last_level_store):
"""Set level where to store to."""
assert isinstance(last_level_store, Cache), \
"last_level needs to be a Cache object."
assert last_level_store.store_to is None, \
"last_level_store must be a last level cache (.store_to is None)."
self.last_level_store = last_level_store | python | def store_from(self, last_level_store):
assert isinstance(last_level_store, Cache), \
"last_level needs to be a Cache object."
assert last_level_store.store_to is None, \
"last_level_store must be a last level cache (.store_to is None)."
self.last_level_store = last_level_store | [
"def",
"store_from",
"(",
"self",
",",
"last_level_store",
")",
":",
"assert",
"isinstance",
"(",
"last_level_store",
",",
"Cache",
")",
",",
"\"last_level needs to be a Cache object.\"",
"assert",
"last_level_store",
".",
"store_to",
"is",
"None",
",",
"\"last_level_... | Set level where to store to. | [
"Set",
"level",
"where",
"to",
"store",
"to",
"."
] | 6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b | https://github.com/RRZE-HPC/pycachesim/blob/6dd084d29cf91ec19b016e0db9ccdfc8d1f63c5b/cachesim/cache.py#L449-L455 |
25,942 | datastore/datastore | datastore/core/key.py | Key.list | def list(self):
'''Returns the `list` representation of this Key.
Note that this method assumes the key is immutable.
'''
if not self._list:
self._list = map(Namespace, self._string.split('/'))
return self._list | python | def list(self):
'''Returns the `list` representation of this Key.
Note that this method assumes the key is immutable.
'''
if not self._list:
self._list = map(Namespace, self._string.split('/'))
return self._list | [
"def",
"list",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_list",
":",
"self",
".",
"_list",
"=",
"map",
"(",
"Namespace",
",",
"self",
".",
"_string",
".",
"split",
"(",
"'/'",
")",
")",
"return",
"self",
".",
"_list"
] | Returns the `list` representation of this Key.
Note that this method assumes the key is immutable. | [
"Returns",
"the",
"list",
"representation",
"of",
"this",
"Key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/key.py#L81-L88 |
25,943 | datastore/datastore | datastore/core/key.py | Key.instance | def instance(self, other):
'''Returns an instance Key, by appending a name to the namespace.'''
assert '/' not in str(other)
return Key(str(self) + ':' + str(other)) | python | def instance(self, other):
'''Returns an instance Key, by appending a name to the namespace.'''
assert '/' not in str(other)
return Key(str(self) + ':' + str(other)) | [
"def",
"instance",
"(",
"self",
",",
"other",
")",
":",
"assert",
"'/'",
"not",
"in",
"str",
"(",
"other",
")",
"return",
"Key",
"(",
"str",
"(",
"self",
")",
"+",
"':'",
"+",
"str",
"(",
"other",
")",
")"
] | Returns an instance Key, by appending a name to the namespace. | [
"Returns",
"an",
"instance",
"Key",
"by",
"appending",
"a",
"name",
"to",
"the",
"namespace",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/key.py#L115-L118 |
25,944 | datastore/datastore | datastore/core/key.py | Key.isAncestorOf | def isAncestorOf(self, other):
'''Returns whether this Key is an ancestor of `other`.
>>> john = Key('/Comedy/MontyPython/Actor:JohnCleese')
>>> Key('/Comedy').isAncestorOf(john)
True
'''
if isinstance(other, Key):
return other._string.startswith(self._string + '/')
raise TypeError('%s is not of type %s' % (other, Key)) | python | def isAncestorOf(self, other):
'''Returns whether this Key is an ancestor of `other`.
>>> john = Key('/Comedy/MontyPython/Actor:JohnCleese')
>>> Key('/Comedy').isAncestorOf(john)
True
'''
if isinstance(other, Key):
return other._string.startswith(self._string + '/')
raise TypeError('%s is not of type %s' % (other, Key)) | [
"def",
"isAncestorOf",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"Key",
")",
":",
"return",
"other",
".",
"_string",
".",
"startswith",
"(",
"self",
".",
"_string",
"+",
"'/'",
")",
"raise",
"TypeError",
"(",
"'%s is n... | Returns whether this Key is an ancestor of `other`.
>>> john = Key('/Comedy/MontyPython/Actor:JohnCleese')
>>> Key('/Comedy').isAncestorOf(john)
True | [
"Returns",
"whether",
"this",
"Key",
"is",
"an",
"ancestor",
"of",
"other",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/key.py#L147-L157 |
25,945 | datastore/datastore | datastore/core/key.py | Key.isDescendantOf | def isDescendantOf(self, other):
'''Returns whether this Key is a descendant of `other`.
>>> Key('/Comedy/MontyPython').isDescendantOf(Key('/Comedy'))
True
'''
if isinstance(other, Key):
return other.isAncestorOf(self)
raise TypeError('%s is not of type %s' % (other, Key)) | python | def isDescendantOf(self, other):
'''Returns whether this Key is a descendant of `other`.
>>> Key('/Comedy/MontyPython').isDescendantOf(Key('/Comedy'))
True
'''
if isinstance(other, Key):
return other.isAncestorOf(self)
raise TypeError('%s is not of type %s' % (other, Key)) | [
"def",
"isDescendantOf",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"Key",
")",
":",
"return",
"other",
".",
"isAncestorOf",
"(",
"self",
")",
"raise",
"TypeError",
"(",
"'%s is not of type %s'",
"%",
"(",
"other",
",",
"... | Returns whether this Key is a descendant of `other`.
>>> Key('/Comedy/MontyPython').isDescendantOf(Key('/Comedy'))
True | [
"Returns",
"whether",
"this",
"Key",
"is",
"a",
"descendant",
"of",
"other",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/key.py#L159-L168 |
25,946 | datastore/datastore | datastore/filesystem/__init__.py | ensure_directory_exists | def ensure_directory_exists(directory):
'''Ensures `directory` exists. May make `directory` and intermediate dirs.
Raises RuntimeError if `directory` is a file.
'''
if not os.path.exists(directory):
os.makedirs(directory)
elif os.path.isfile(directory):
raise RuntimeError('Path %s is a file, not a directory.' % directory) | python | def ensure_directory_exists(directory):
'''Ensures `directory` exists. May make `directory` and intermediate dirs.
Raises RuntimeError if `directory` is a file.
'''
if not os.path.exists(directory):
os.makedirs(directory)
elif os.path.isfile(directory):
raise RuntimeError('Path %s is a file, not a directory.' % directory) | [
"def",
"ensure_directory_exists",
"(",
"directory",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"directory",
")",
":",
"os",
".",
"makedirs",
"(",
"directory",
")",
"elif",
"os",
".",
"path",
".",
"isfile",
"(",
"directory",
")",
":",... | Ensures `directory` exists. May make `directory` and intermediate dirs.
Raises RuntimeError if `directory` is a file. | [
"Ensures",
"directory",
"exists",
".",
"May",
"make",
"directory",
"and",
"intermediate",
"dirs",
".",
"Raises",
"RuntimeError",
"if",
"directory",
"is",
"a",
"file",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L16-L23 |
25,947 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore.relative_path | def relative_path(self, key):
'''Returns the relative path for given `key`'''
key = str(key) # stringify
key = key.replace(':', '/') # turn namespace delimiters into slashes
key = key[1:] # remove first slash (absolute)
if not self.case_sensitive:
key = key.lower() # coerce to lowercase
return os.path.normpath(key) | python | def relative_path(self, key):
'''Returns the relative path for given `key`'''
key = str(key) # stringify
key = key.replace(':', '/') # turn namespace delimiters into slashes
key = key[1:] # remove first slash (absolute)
if not self.case_sensitive:
key = key.lower() # coerce to lowercase
return os.path.normpath(key) | [
"def",
"relative_path",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"str",
"(",
"key",
")",
"# stringify",
"key",
"=",
"key",
".",
"replace",
"(",
"':'",
",",
"'/'",
")",
"# turn namespace delimiters into slashes",
"key",
"=",
"key",
"[",
"1",
":",
... | Returns the relative path for given `key` | [
"Returns",
"the",
"relative",
"path",
"for",
"given",
"key"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L111-L118 |
25,948 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore.path | def path(self, key):
'''Returns the `path` for given `key`'''
return os.path.join(self.root_path, self.relative_path(key)) | python | def path(self, key):
'''Returns the `path` for given `key`'''
return os.path.join(self.root_path, self.relative_path(key)) | [
"def",
"path",
"(",
"self",
",",
"key",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"root_path",
",",
"self",
".",
"relative_path",
"(",
"key",
")",
")"
] | Returns the `path` for given `key` | [
"Returns",
"the",
"path",
"for",
"given",
"key"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L120-L122 |
25,949 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore.object_path | def object_path(self, key):
'''return the object path for `key`.'''
return os.path.join(self.root_path, self.relative_object_path(key)) | python | def object_path(self, key):
'''return the object path for `key`.'''
return os.path.join(self.root_path, self.relative_object_path(key)) | [
"def",
"object_path",
"(",
"self",
",",
"key",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"root_path",
",",
"self",
".",
"relative_object_path",
"(",
"key",
")",
")"
] | return the object path for `key`. | [
"return",
"the",
"object",
"path",
"for",
"key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L128-L130 |
25,950 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore._write_object | def _write_object(self, path, value):
'''write out `object` to file at `path`'''
ensure_directory_exists(os.path.dirname(path))
with open(path, 'w') as f:
f.write(value) | python | def _write_object(self, path, value):
'''write out `object` to file at `path`'''
ensure_directory_exists(os.path.dirname(path))
with open(path, 'w') as f:
f.write(value) | [
"def",
"_write_object",
"(",
"self",
",",
"path",
",",
"value",
")",
":",
"ensure_directory_exists",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
")",
"with",
"open",
"(",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"f",
".",
"write",
"("... | write out `object` to file at `path` | [
"write",
"out",
"object",
"to",
"file",
"at",
"path"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L135-L140 |
25,951 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore._read_object | def _read_object(self, path):
'''read in object from file at `path`'''
if not os.path.exists(path):
return None
if os.path.isdir(path):
raise RuntimeError('%s is a directory, not a file.' % path)
with open(path) as f:
file_contents = f.read()
return file_contents | python | def _read_object(self, path):
'''read in object from file at `path`'''
if not os.path.exists(path):
return None
if os.path.isdir(path):
raise RuntimeError('%s is a directory, not a file.' % path)
with open(path) as f:
file_contents = f.read()
return file_contents | [
"def",
"_read_object",
"(",
"self",
",",
"path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"return",
"None",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
":",
"raise",
"RuntimeError",
"(",
"'%s is a... | read in object from file at `path` | [
"read",
"in",
"object",
"from",
"file",
"at",
"path"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L142-L153 |
25,952 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore.get | def get(self, key):
'''Return the object named by key or None if it does not exist.
Args:
key: Key naming the object to retrieve
Returns:
object or None
'''
path = self.object_path(key)
return self._read_object(path) | python | def get(self, key):
'''Return the object named by key or None if it does not exist.
Args:
key: Key naming the object to retrieve
Returns:
object or None
'''
path = self.object_path(key)
return self._read_object(path) | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"path",
"=",
"self",
".",
"object_path",
"(",
"key",
")",
"return",
"self",
".",
"_read_object",
"(",
"path",
")"
] | Return the object named by key or None if it does not exist.
Args:
key: Key naming the object to retrieve
Returns:
object or None | [
"Return",
"the",
"object",
"named",
"by",
"key",
"or",
"None",
"if",
"it",
"does",
"not",
"exist",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L163-L173 |
25,953 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore.query | def query(self, query):
'''Returns an iterable of objects matching criteria expressed in `query`
FSDatastore.query queries all the `.obj` files within the directory
specified by the query.key.
Args:
query: Query object describing the objects to return.
Raturns:
Cursor with all objects matching criteria
'''
path = self.path(query.key)
if os.path.exists(path):
filenames = os.listdir(path)
filenames = list(set(filenames) - set(self.ignore_list))
filenames = map(lambda f: os.path.join(path, f), filenames)
iterable = self._read_object_gen(filenames)
else:
iterable = list()
return query(iterable) | python | def query(self, query):
'''Returns an iterable of objects matching criteria expressed in `query`
FSDatastore.query queries all the `.obj` files within the directory
specified by the query.key.
Args:
query: Query object describing the objects to return.
Raturns:
Cursor with all objects matching criteria
'''
path = self.path(query.key)
if os.path.exists(path):
filenames = os.listdir(path)
filenames = list(set(filenames) - set(self.ignore_list))
filenames = map(lambda f: os.path.join(path, f), filenames)
iterable = self._read_object_gen(filenames)
else:
iterable = list()
return query(iterable) | [
"def",
"query",
"(",
"self",
",",
"query",
")",
":",
"path",
"=",
"self",
".",
"path",
"(",
"query",
".",
"key",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"filenames",
"=",
"os",
".",
"listdir",
"(",
"path",
")",
"file... | Returns an iterable of objects matching criteria expressed in `query`
FSDatastore.query queries all the `.obj` files within the directory
specified by the query.key.
Args:
query: Query object describing the objects to return.
Raturns:
Cursor with all objects matching criteria | [
"Returns",
"an",
"iterable",
"of",
"objects",
"matching",
"criteria",
"expressed",
"in",
"query",
"FSDatastore",
".",
"query",
"queries",
"all",
"the",
".",
"obj",
"files",
"within",
"the",
"directory",
"specified",
"by",
"the",
"query",
".",
"key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L198-L219 |
25,954 | datastore/datastore | datastore/filesystem/__init__.py | FileSystemDatastore.contains | def contains(self, key):
'''Returns whether the object named by `key` exists.
Optimized to only check whether the file object exists.
Args:
key: Key naming the object to check.
Returns:
boalean whether the object exists
'''
path = self.object_path(key)
return os.path.exists(path) and os.path.isfile(path) | python | def contains(self, key):
'''Returns whether the object named by `key` exists.
Optimized to only check whether the file object exists.
Args:
key: Key naming the object to check.
Returns:
boalean whether the object exists
'''
path = self.object_path(key)
return os.path.exists(path) and os.path.isfile(path) | [
"def",
"contains",
"(",
"self",
",",
"key",
")",
":",
"path",
"=",
"self",
".",
"object_path",
"(",
"key",
")",
"return",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")"
] | Returns whether the object named by `key` exists.
Optimized to only check whether the file object exists.
Args:
key: Key naming the object to check.
Returns:
boalean whether the object exists | [
"Returns",
"whether",
"the",
"object",
"named",
"by",
"key",
"exists",
".",
"Optimized",
"to",
"only",
"check",
"whether",
"the",
"file",
"object",
"exists",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/filesystem/__init__.py#L221-L232 |
25,955 | datastore/datastore | datastore/core/basic.py | DictDatastore._collection | def _collection(self, key):
'''Returns the namespace collection for `key`.'''
collection = str(key.path)
if not collection in self._items:
self._items[collection] = dict()
return self._items[collection] | python | def _collection(self, key):
'''Returns the namespace collection for `key`.'''
collection = str(key.path)
if not collection in self._items:
self._items[collection] = dict()
return self._items[collection] | [
"def",
"_collection",
"(",
"self",
",",
"key",
")",
":",
"collection",
"=",
"str",
"(",
"key",
".",
"path",
")",
"if",
"not",
"collection",
"in",
"self",
".",
"_items",
":",
"self",
".",
"_items",
"[",
"collection",
"]",
"=",
"dict",
"(",
")",
"ret... | Returns the namespace collection for `key`. | [
"Returns",
"the",
"namespace",
"collection",
"for",
"key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L121-L126 |
25,956 | datastore/datastore | datastore/core/basic.py | DictDatastore.query | def query(self, query):
'''Returns an iterable of objects matching criteria expressed in `query`
Naively applies the query operations on the objects within the namespaced
collection corresponding to ``query.key.path``.
Args:
query: Query object describing the objects to return.
Raturns:
iterable cursor with all objects matching criteria
'''
# entire dataset already in memory, so ok to apply query naively
if str(query.key) in self._items:
return query(self._items[str(query.key)].values())
else:
return query([]) | python | def query(self, query):
'''Returns an iterable of objects matching criteria expressed in `query`
Naively applies the query operations on the objects within the namespaced
collection corresponding to ``query.key.path``.
Args:
query: Query object describing the objects to return.
Raturns:
iterable cursor with all objects matching criteria
'''
# entire dataset already in memory, so ok to apply query naively
if str(query.key) in self._items:
return query(self._items[str(query.key)].values())
else:
return query([]) | [
"def",
"query",
"(",
"self",
",",
"query",
")",
":",
"# entire dataset already in memory, so ok to apply query naively",
"if",
"str",
"(",
"query",
".",
"key",
")",
"in",
"self",
".",
"_items",
":",
"return",
"query",
"(",
"self",
".",
"_items",
"[",
"str",
... | Returns an iterable of objects matching criteria expressed in `query`
Naively applies the query operations on the objects within the namespaced
collection corresponding to ``query.key.path``.
Args:
query: Query object describing the objects to return.
Raturns:
iterable cursor with all objects matching criteria | [
"Returns",
"an",
"iterable",
"of",
"objects",
"matching",
"criteria",
"expressed",
"in",
"query"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L188-L205 |
25,957 | datastore/datastore | datastore/core/basic.py | InterfaceMappingDatastore.get | def get(self, key):
'''Return the object in `service` named by `key` or None.
Args:
key: Key naming the object to retrieve.
Returns:
object or None
'''
key = self._service_key(key)
return self._service_ops['get'](key) | python | def get(self, key):
'''Return the object in `service` named by `key` or None.
Args:
key: Key naming the object to retrieve.
Returns:
object or None
'''
key = self._service_key(key)
return self._service_ops['get'](key) | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"self",
".",
"_service_key",
"(",
"key",
")",
"return",
"self",
".",
"_service_ops",
"[",
"'get'",
"]",
"(",
"key",
")"
] | Return the object in `service` named by `key` or None.
Args:
key: Key naming the object to retrieve.
Returns:
object or None | [
"Return",
"the",
"object",
"in",
"service",
"named",
"by",
"key",
"or",
"None",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L244-L254 |
25,958 | datastore/datastore | datastore/core/basic.py | InterfaceMappingDatastore.put | def put(self, key, value):
'''Stores the object `value` named by `key` in `service`.
Args:
key: Key naming `value`.
value: the object to store.
'''
key = self._service_key(key)
self._service_ops['put'](key, value) | python | def put(self, key, value):
'''Stores the object `value` named by `key` in `service`.
Args:
key: Key naming `value`.
value: the object to store.
'''
key = self._service_key(key)
self._service_ops['put'](key, value) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"key",
"=",
"self",
".",
"_service_key",
"(",
"key",
")",
"self",
".",
"_service_ops",
"[",
"'put'",
"]",
"(",
"key",
",",
"value",
")"
] | Stores the object `value` named by `key` in `service`.
Args:
key: Key naming `value`.
value: the object to store. | [
"Stores",
"the",
"object",
"value",
"named",
"by",
"key",
"in",
"service",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L256-L264 |
25,959 | datastore/datastore | datastore/core/basic.py | InterfaceMappingDatastore.delete | def delete(self, key):
'''Removes the object named by `key` in `service`.
Args:
key: Key naming the object to remove.
'''
key = self._service_key(key)
self._service_ops['delete'](key) | python | def delete(self, key):
'''Removes the object named by `key` in `service`.
Args:
key: Key naming the object to remove.
'''
key = self._service_key(key)
self._service_ops['delete'](key) | [
"def",
"delete",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"self",
".",
"_service_key",
"(",
"key",
")",
"self",
".",
"_service_ops",
"[",
"'delete'",
"]",
"(",
"key",
")"
] | Removes the object named by `key` in `service`.
Args:
key: Key naming the object to remove. | [
"Removes",
"the",
"object",
"named",
"by",
"key",
"in",
"service",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L266-L273 |
25,960 | datastore/datastore | datastore/core/basic.py | CacheShimDatastore.get | def get(self, key):
'''Return the object named by key or None if it does not exist.
CacheShimDatastore first checks its ``cache_datastore``.
'''
value = self.cache_datastore.get(key)
return value if value is not None else self.child_datastore.get(key) | python | def get(self, key):
'''Return the object named by key or None if it does not exist.
CacheShimDatastore first checks its ``cache_datastore``.
'''
value = self.cache_datastore.get(key)
return value if value is not None else self.child_datastore.get(key) | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"value",
"=",
"self",
".",
"cache_datastore",
".",
"get",
"(",
"key",
")",
"return",
"value",
"if",
"value",
"is",
"not",
"None",
"else",
"self",
".",
"child_datastore",
".",
"get",
"(",
"key",
")"
] | Return the object named by key or None if it does not exist.
CacheShimDatastore first checks its ``cache_datastore``. | [
"Return",
"the",
"object",
"named",
"by",
"key",
"or",
"None",
"if",
"it",
"does",
"not",
"exist",
".",
"CacheShimDatastore",
"first",
"checks",
"its",
"cache_datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L377-L382 |
25,961 | datastore/datastore | datastore/core/basic.py | CacheShimDatastore.put | def put(self, key, value):
'''Stores the object `value` named by `key`self.
Writes to both ``cache_datastore`` and ``child_datastore``.
'''
self.cache_datastore.put(key, value)
self.child_datastore.put(key, value) | python | def put(self, key, value):
'''Stores the object `value` named by `key`self.
Writes to both ``cache_datastore`` and ``child_datastore``.
'''
self.cache_datastore.put(key, value)
self.child_datastore.put(key, value) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"self",
".",
"cache_datastore",
".",
"put",
"(",
"key",
",",
"value",
")",
"self",
".",
"child_datastore",
".",
"put",
"(",
"key",
",",
"value",
")"
] | Stores the object `value` named by `key`self.
Writes to both ``cache_datastore`` and ``child_datastore``. | [
"Stores",
"the",
"object",
"value",
"named",
"by",
"key",
"self",
".",
"Writes",
"to",
"both",
"cache_datastore",
"and",
"child_datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L384-L389 |
25,962 | datastore/datastore | datastore/core/basic.py | CacheShimDatastore.delete | def delete(self, key):
'''Removes the object named by `key`.
Writes to both ``cache_datastore`` and ``child_datastore``.
'''
self.cache_datastore.delete(key)
self.child_datastore.delete(key) | python | def delete(self, key):
'''Removes the object named by `key`.
Writes to both ``cache_datastore`` and ``child_datastore``.
'''
self.cache_datastore.delete(key)
self.child_datastore.delete(key) | [
"def",
"delete",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"cache_datastore",
".",
"delete",
"(",
"key",
")",
"self",
".",
"child_datastore",
".",
"delete",
"(",
"key",
")"
] | Removes the object named by `key`.
Writes to both ``cache_datastore`` and ``child_datastore``. | [
"Removes",
"the",
"object",
"named",
"by",
"key",
".",
"Writes",
"to",
"both",
"cache_datastore",
"and",
"child_datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L391-L396 |
25,963 | datastore/datastore | datastore/core/basic.py | CacheShimDatastore.contains | def contains(self, key):
'''Returns whether the object named by `key` exists.
First checks ``cache_datastore``.
'''
return self.cache_datastore.contains(key) \
or self.child_datastore.contains(key) | python | def contains(self, key):
'''Returns whether the object named by `key` exists.
First checks ``cache_datastore``.
'''
return self.cache_datastore.contains(key) \
or self.child_datastore.contains(key) | [
"def",
"contains",
"(",
"self",
",",
"key",
")",
":",
"return",
"self",
".",
"cache_datastore",
".",
"contains",
"(",
"key",
")",
"or",
"self",
".",
"child_datastore",
".",
"contains",
"(",
"key",
")"
] | Returns whether the object named by `key` exists.
First checks ``cache_datastore``. | [
"Returns",
"whether",
"the",
"object",
"named",
"by",
"key",
"exists",
".",
"First",
"checks",
"cache_datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L398-L403 |
25,964 | datastore/datastore | datastore/core/basic.py | LoggingDatastore.get | def get(self, key):
'''Return the object named by key or None if it does not exist.
LoggingDatastore logs the access.
'''
self.logger.info('%s: get %s' % (self, key))
value = super(LoggingDatastore, self).get(key)
self.logger.debug('%s: %s' % (self, value))
return value | python | def get(self, key):
'''Return the object named by key or None if it does not exist.
LoggingDatastore logs the access.
'''
self.logger.info('%s: get %s' % (self, key))
value = super(LoggingDatastore, self).get(key)
self.logger.debug('%s: %s' % (self, value))
return value | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'%s: get %s'",
"%",
"(",
"self",
",",
"key",
")",
")",
"value",
"=",
"super",
"(",
"LoggingDatastore",
",",
"self",
")",
".",
"get",
"(",
"key",
")",
"self... | Return the object named by key or None if it does not exist.
LoggingDatastore logs the access. | [
"Return",
"the",
"object",
"named",
"by",
"key",
"or",
"None",
"if",
"it",
"does",
"not",
"exist",
".",
"LoggingDatastore",
"logs",
"the",
"access",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L420-L427 |
25,965 | datastore/datastore | datastore/core/basic.py | LoggingDatastore.delete | def delete(self, key):
'''Removes the object named by `key`.
LoggingDatastore logs the access.
'''
self.logger.info('%s: delete %s' % (self, key))
super(LoggingDatastore, self).delete(key) | python | def delete(self, key):
'''Removes the object named by `key`.
LoggingDatastore logs the access.
'''
self.logger.info('%s: delete %s' % (self, key))
super(LoggingDatastore, self).delete(key) | [
"def",
"delete",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'%s: delete %s'",
"%",
"(",
"self",
",",
"key",
")",
")",
"super",
"(",
"LoggingDatastore",
",",
"self",
")",
".",
"delete",
"(",
"key",
")"
] | Removes the object named by `key`.
LoggingDatastore logs the access. | [
"Removes",
"the",
"object",
"named",
"by",
"key",
".",
"LoggingDatastore",
"logs",
"the",
"access",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L437-L442 |
25,966 | datastore/datastore | datastore/core/basic.py | LoggingDatastore.contains | def contains(self, key):
'''Returns whether the object named by `key` exists.
LoggingDatastore logs the access.
'''
self.logger.info('%s: contains %s' % (self, key))
return super(LoggingDatastore, self).contains(key) | python | def contains(self, key):
'''Returns whether the object named by `key` exists.
LoggingDatastore logs the access.
'''
self.logger.info('%s: contains %s' % (self, key))
return super(LoggingDatastore, self).contains(key) | [
"def",
"contains",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'%s: contains %s'",
"%",
"(",
"self",
",",
"key",
")",
")",
"return",
"super",
"(",
"LoggingDatastore",
",",
"self",
")",
".",
"contains",
"(",
"key",
")"... | Returns whether the object named by `key` exists.
LoggingDatastore logs the access. | [
"Returns",
"whether",
"the",
"object",
"named",
"by",
"key",
"exists",
".",
"LoggingDatastore",
"logs",
"the",
"access",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L444-L449 |
25,967 | datastore/datastore | datastore/core/basic.py | LoggingDatastore.query | def query(self, query):
'''Returns an iterable of objects matching criteria expressed in `query`.
LoggingDatastore logs the access.
'''
self.logger.info('%s: query %s' % (self, query))
return super(LoggingDatastore, self).query(query) | python | def query(self, query):
'''Returns an iterable of objects matching criteria expressed in `query`.
LoggingDatastore logs the access.
'''
self.logger.info('%s: query %s' % (self, query))
return super(LoggingDatastore, self).query(query) | [
"def",
"query",
"(",
"self",
",",
"query",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'%s: query %s'",
"%",
"(",
"self",
",",
"query",
")",
")",
"return",
"super",
"(",
"LoggingDatastore",
",",
"self",
")",
".",
"query",
"(",
"query",
")"
] | Returns an iterable of objects matching criteria expressed in `query`.
LoggingDatastore logs the access. | [
"Returns",
"an",
"iterable",
"of",
"objects",
"matching",
"criteria",
"expressed",
"in",
"query",
".",
"LoggingDatastore",
"logs",
"the",
"access",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L451-L456 |
25,968 | datastore/datastore | datastore/core/basic.py | NestedPathDatastore.nestKey | def nestKey(self, key):
'''Returns a nested `key`.'''
nest = self.nest_keyfn(key)
# if depth * length > len(key.name), we need to pad.
mult = 1 + int(self.nest_depth * self.nest_length / len(nest))
nest = nest * mult
pref = Key(self.nestedPath(nest, self.nest_depth, self.nest_length))
return pref.child(key) | python | def nestKey(self, key):
'''Returns a nested `key`.'''
nest = self.nest_keyfn(key)
# if depth * length > len(key.name), we need to pad.
mult = 1 + int(self.nest_depth * self.nest_length / len(nest))
nest = nest * mult
pref = Key(self.nestedPath(nest, self.nest_depth, self.nest_length))
return pref.child(key) | [
"def",
"nestKey",
"(",
"self",
",",
"key",
")",
":",
"nest",
"=",
"self",
".",
"nest_keyfn",
"(",
"key",
")",
"# if depth * length > len(key.name), we need to pad.",
"mult",
"=",
"1",
"+",
"int",
"(",
"self",
".",
"nest_depth",
"*",
"self",
".",
"nest_length... | Returns a nested `key`. | [
"Returns",
"a",
"nested",
"key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L643-L653 |
25,969 | datastore/datastore | datastore/core/basic.py | SymlinkDatastore._link_for_value | def _link_for_value(self, value):
'''Returns the linked key if `value` is a link, or None.'''
try:
key = Key(value)
if key.name == self.sentinel:
return key.parent
except:
pass
return None | python | def _link_for_value(self, value):
'''Returns the linked key if `value` is a link, or None.'''
try:
key = Key(value)
if key.name == self.sentinel:
return key.parent
except:
pass
return None | [
"def",
"_link_for_value",
"(",
"self",
",",
"value",
")",
":",
"try",
":",
"key",
"=",
"Key",
"(",
"value",
")",
"if",
"key",
".",
"name",
"==",
"self",
".",
"sentinel",
":",
"return",
"key",
".",
"parent",
"except",
":",
"pass",
"return",
"None"
] | Returns the linked key if `value` is a link, or None. | [
"Returns",
"the",
"linked",
"key",
"if",
"value",
"is",
"a",
"link",
"or",
"None",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L728-L736 |
25,970 | datastore/datastore | datastore/core/basic.py | SymlinkDatastore._follow_link | def _follow_link(self, value):
'''Returns given `value` or, if it is a symlink, the `value` it names.'''
seen_keys = set()
while True:
link_key = self._link_for_value(value)
if not link_key:
return value
assert link_key not in seen_keys, 'circular symlink reference'
seen_keys.add(link_key)
value = super(SymlinkDatastore, self).get(link_key) | python | def _follow_link(self, value):
'''Returns given `value` or, if it is a symlink, the `value` it names.'''
seen_keys = set()
while True:
link_key = self._link_for_value(value)
if not link_key:
return value
assert link_key not in seen_keys, 'circular symlink reference'
seen_keys.add(link_key)
value = super(SymlinkDatastore, self).get(link_key) | [
"def",
"_follow_link",
"(",
"self",
",",
"value",
")",
":",
"seen_keys",
"=",
"set",
"(",
")",
"while",
"True",
":",
"link_key",
"=",
"self",
".",
"_link_for_value",
"(",
"value",
")",
"if",
"not",
"link_key",
":",
"return",
"value",
"assert",
"link_key"... | Returns given `value` or, if it is a symlink, the `value` it names. | [
"Returns",
"given",
"value",
"or",
"if",
"it",
"is",
"a",
"symlink",
"the",
"value",
"it",
"names",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L739-L749 |
25,971 | datastore/datastore | datastore/core/basic.py | SymlinkDatastore.link | def link(self, source_key, target_key):
'''Creates a symbolic link key pointing from `target_key` to `source_key`'''
link_value = self._link_value_for_key(source_key)
# put straight into the child, to avoid following previous links.
self.child_datastore.put(target_key, link_value)
# exercise the link. ensure there are no cycles.
self.get(target_key) | python | def link(self, source_key, target_key):
'''Creates a symbolic link key pointing from `target_key` to `source_key`'''
link_value = self._link_value_for_key(source_key)
# put straight into the child, to avoid following previous links.
self.child_datastore.put(target_key, link_value)
# exercise the link. ensure there are no cycles.
self.get(target_key) | [
"def",
"link",
"(",
"self",
",",
"source_key",
",",
"target_key",
")",
":",
"link_value",
"=",
"self",
".",
"_link_value_for_key",
"(",
"source_key",
")",
"# put straight into the child, to avoid following previous links.",
"self",
".",
"child_datastore",
".",
"put",
... | Creates a symbolic link key pointing from `target_key` to `source_key` | [
"Creates",
"a",
"symbolic",
"link",
"key",
"pointing",
"from",
"target_key",
"to",
"source_key"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L757-L765 |
25,972 | datastore/datastore | datastore/core/basic.py | SymlinkDatastore.get | def get(self, key):
'''Return the object named by `key. Follows links.'''
value = super(SymlinkDatastore, self).get(key)
return self._follow_link(value) | python | def get(self, key):
'''Return the object named by `key. Follows links.'''
value = super(SymlinkDatastore, self).get(key)
return self._follow_link(value) | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"value",
"=",
"super",
"(",
"SymlinkDatastore",
",",
"self",
")",
".",
"get",
"(",
"key",
")",
"return",
"self",
".",
"_follow_link",
"(",
"value",
")"
] | Return the object named by `key. Follows links. | [
"Return",
"the",
"object",
"named",
"by",
"key",
".",
"Follows",
"links",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L768-L771 |
25,973 | datastore/datastore | datastore/core/basic.py | SymlinkDatastore.put | def put(self, key, value):
'''Stores the object named by `key`. Follows links.'''
# if value is a link, don't follow links
if self._link_for_value(value):
super(SymlinkDatastore, self).put(key, value)
return
# if `key` points to a symlink, need to follow it.
current_value = super(SymlinkDatastore, self).get(key)
link_key = self._link_for_value(current_value)
if link_key:
self.put(link_key, value) # self.put: could be another link.
else:
super(SymlinkDatastore, self).put(key, value) | python | def put(self, key, value):
'''Stores the object named by `key`. Follows links.'''
# if value is a link, don't follow links
if self._link_for_value(value):
super(SymlinkDatastore, self).put(key, value)
return
# if `key` points to a symlink, need to follow it.
current_value = super(SymlinkDatastore, self).get(key)
link_key = self._link_for_value(current_value)
if link_key:
self.put(link_key, value) # self.put: could be another link.
else:
super(SymlinkDatastore, self).put(key, value) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"# if value is a link, don't follow links",
"if",
"self",
".",
"_link_for_value",
"(",
"value",
")",
":",
"super",
"(",
"SymlinkDatastore",
",",
"self",
")",
".",
"put",
"(",
"key",
",",
"value... | Stores the object named by `key`. Follows links. | [
"Stores",
"the",
"object",
"named",
"by",
"key",
".",
"Follows",
"links",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L773-L786 |
25,974 | datastore/datastore | datastore/core/basic.py | SymlinkDatastore.query | def query(self, query):
'''Returns objects matching criteria expressed in `query`. Follows links.'''
results = super(SymlinkDatastore, self).query(query)
return self._follow_link_gen(results) | python | def query(self, query):
'''Returns objects matching criteria expressed in `query`. Follows links.'''
results = super(SymlinkDatastore, self).query(query)
return self._follow_link_gen(results) | [
"def",
"query",
"(",
"self",
",",
"query",
")",
":",
"results",
"=",
"super",
"(",
"SymlinkDatastore",
",",
"self",
")",
".",
"query",
"(",
"query",
")",
"return",
"self",
".",
"_follow_link_gen",
"(",
"results",
")"
] | Returns objects matching criteria expressed in `query`. Follows links. | [
"Returns",
"objects",
"matching",
"criteria",
"expressed",
"in",
"query",
".",
"Follows",
"links",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L788-L791 |
25,975 | datastore/datastore | datastore/core/basic.py | DirectoryDatastore.directory | def directory(self, dir_key):
'''Initializes directory at dir_key.'''
dir_items = self.get(dir_key)
if not isinstance(dir_items, list):
self.put(dir_key, []) | python | def directory(self, dir_key):
'''Initializes directory at dir_key.'''
dir_items = self.get(dir_key)
if not isinstance(dir_items, list):
self.put(dir_key, []) | [
"def",
"directory",
"(",
"self",
",",
"dir_key",
")",
":",
"dir_items",
"=",
"self",
".",
"get",
"(",
"dir_key",
")",
"if",
"not",
"isinstance",
"(",
"dir_items",
",",
"list",
")",
":",
"self",
".",
"put",
"(",
"dir_key",
",",
"[",
"]",
")"
] | Initializes directory at dir_key. | [
"Initializes",
"directory",
"at",
"dir_key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L823-L827 |
25,976 | datastore/datastore | datastore/core/basic.py | DirectoryDatastore.directoryAdd | def directoryAdd(self, dir_key, key):
'''Adds directory entry `key` to directory at `dir_key`.
If the directory `dir_key` does not exist, it is created.
'''
key = str(key)
dir_items = self.get(dir_key) or []
if key not in dir_items:
dir_items.append(key)
self.put(dir_key, dir_items) | python | def directoryAdd(self, dir_key, key):
'''Adds directory entry `key` to directory at `dir_key`.
If the directory `dir_key` does not exist, it is created.
'''
key = str(key)
dir_items = self.get(dir_key) or []
if key not in dir_items:
dir_items.append(key)
self.put(dir_key, dir_items) | [
"def",
"directoryAdd",
"(",
"self",
",",
"dir_key",
",",
"key",
")",
":",
"key",
"=",
"str",
"(",
"key",
")",
"dir_items",
"=",
"self",
".",
"get",
"(",
"dir_key",
")",
"or",
"[",
"]",
"if",
"key",
"not",
"in",
"dir_items",
":",
"dir_items",
".",
... | Adds directory entry `key` to directory at `dir_key`.
If the directory `dir_key` does not exist, it is created. | [
"Adds",
"directory",
"entry",
"key",
"to",
"directory",
"at",
"dir_key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L840-L850 |
25,977 | datastore/datastore | datastore/core/basic.py | DirectoryDatastore.directoryRemove | def directoryRemove(self, dir_key, key):
'''Removes directory entry `key` from directory at `dir_key`.
If either the directory `dir_key` or the directory entry `key` don't exist,
this method is a no-op.
'''
key = str(key)
dir_items = self.get(dir_key) or []
if key in dir_items:
dir_items = [k for k in dir_items if k != key]
self.put(dir_key, dir_items) | python | def directoryRemove(self, dir_key, key):
'''Removes directory entry `key` from directory at `dir_key`.
If either the directory `dir_key` or the directory entry `key` don't exist,
this method is a no-op.
'''
key = str(key)
dir_items = self.get(dir_key) or []
if key in dir_items:
dir_items = [k for k in dir_items if k != key]
self.put(dir_key, dir_items) | [
"def",
"directoryRemove",
"(",
"self",
",",
"dir_key",
",",
"key",
")",
":",
"key",
"=",
"str",
"(",
"key",
")",
"dir_items",
"=",
"self",
".",
"get",
"(",
"dir_key",
")",
"or",
"[",
"]",
"if",
"key",
"in",
"dir_items",
":",
"dir_items",
"=",
"[",
... | Removes directory entry `key` from directory at `dir_key`.
If either the directory `dir_key` or the directory entry `key` don't exist,
this method is a no-op. | [
"Removes",
"directory",
"entry",
"key",
"from",
"directory",
"at",
"dir_key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L853-L864 |
25,978 | datastore/datastore | datastore/core/basic.py | DirectoryTreeDatastore.put | def put(self, key, value):
'''Stores the object `value` named by `key`self.
DirectoryTreeDatastore stores a directory entry.
'''
super(DirectoryTreeDatastore, self).put(key, value)
str_key = str(key)
# ignore root
if str_key == '/':
return
# retrieve directory, to add entry
dir_key = key.parent.instance('directory')
directory = self.directory(dir_key)
# ensure key is in directory
if str_key not in directory:
directory.append(str_key)
super(DirectoryTreeDatastore, self).put(dir_key, directory) | python | def put(self, key, value):
'''Stores the object `value` named by `key`self.
DirectoryTreeDatastore stores a directory entry.
'''
super(DirectoryTreeDatastore, self).put(key, value)
str_key = str(key)
# ignore root
if str_key == '/':
return
# retrieve directory, to add entry
dir_key = key.parent.instance('directory')
directory = self.directory(dir_key)
# ensure key is in directory
if str_key not in directory:
directory.append(str_key)
super(DirectoryTreeDatastore, self).put(dir_key, directory) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"super",
"(",
"DirectoryTreeDatastore",
",",
"self",
")",
".",
"put",
"(",
"key",
",",
"value",
")",
"str_key",
"=",
"str",
"(",
"key",
")",
"# ignore root",
"if",
"str_key",
"==",
"'/'",... | Stores the object `value` named by `key`self.
DirectoryTreeDatastore stores a directory entry. | [
"Stores",
"the",
"object",
"value",
"named",
"by",
"key",
"self",
".",
"DirectoryTreeDatastore",
"stores",
"a",
"directory",
"entry",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L910-L929 |
25,979 | datastore/datastore | datastore/core/basic.py | DirectoryTreeDatastore.delete | def delete(self, key):
'''Removes the object named by `key`.
DirectoryTreeDatastore removes the directory entry.
'''
super(DirectoryTreeDatastore, self).delete(key)
str_key = str(key)
# ignore root
if str_key == '/':
return
# retrieve directory, to remove entry
dir_key = key.parent.instance('directory')
directory = self.directory(dir_key)
# ensure key is not in directory
if directory and str_key in directory:
directory.remove(str_key)
if len(directory) > 0:
super(DirectoryTreeDatastore, self).put(dir_key, directory)
else:
super(DirectoryTreeDatastore, self).delete(dir_key) | python | def delete(self, key):
'''Removes the object named by `key`.
DirectoryTreeDatastore removes the directory entry.
'''
super(DirectoryTreeDatastore, self).delete(key)
str_key = str(key)
# ignore root
if str_key == '/':
return
# retrieve directory, to remove entry
dir_key = key.parent.instance('directory')
directory = self.directory(dir_key)
# ensure key is not in directory
if directory and str_key in directory:
directory.remove(str_key)
if len(directory) > 0:
super(DirectoryTreeDatastore, self).put(dir_key, directory)
else:
super(DirectoryTreeDatastore, self).delete(dir_key) | [
"def",
"delete",
"(",
"self",
",",
"key",
")",
":",
"super",
"(",
"DirectoryTreeDatastore",
",",
"self",
")",
".",
"delete",
"(",
"key",
")",
"str_key",
"=",
"str",
"(",
"key",
")",
"# ignore root",
"if",
"str_key",
"==",
"'/'",
":",
"return",
"# retri... | Removes the object named by `key`.
DirectoryTreeDatastore removes the directory entry. | [
"Removes",
"the",
"object",
"named",
"by",
"key",
".",
"DirectoryTreeDatastore",
"removes",
"the",
"directory",
"entry",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L932-L954 |
25,980 | datastore/datastore | datastore/core/basic.py | DirectoryTreeDatastore.directory | def directory(self, key):
'''Retrieves directory entries for given key.'''
if key.name != 'directory':
key = key.instance('directory')
return self.get(key) or [] | python | def directory(self, key):
'''Retrieves directory entries for given key.'''
if key.name != 'directory':
key = key.instance('directory')
return self.get(key) or [] | [
"def",
"directory",
"(",
"self",
",",
"key",
")",
":",
"if",
"key",
".",
"name",
"!=",
"'directory'",
":",
"key",
"=",
"key",
".",
"instance",
"(",
"'directory'",
")",
"return",
"self",
".",
"get",
"(",
"key",
")",
"or",
"[",
"]"
] | Retrieves directory entries for given key. | [
"Retrieves",
"directory",
"entries",
"for",
"given",
"key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L965-L969 |
25,981 | datastore/datastore | datastore/core/basic.py | DirectoryTreeDatastore.directory_values_generator | def directory_values_generator(self, key):
'''Retrieve directory values for given key.'''
directory = self.directory(key)
for key in directory:
yield self.get(Key(key)) | python | def directory_values_generator(self, key):
'''Retrieve directory values for given key.'''
directory = self.directory(key)
for key in directory:
yield self.get(Key(key)) | [
"def",
"directory_values_generator",
"(",
"self",
",",
"key",
")",
":",
"directory",
"=",
"self",
".",
"directory",
"(",
"key",
")",
"for",
"key",
"in",
"directory",
":",
"yield",
"self",
".",
"get",
"(",
"Key",
"(",
"key",
")",
")"
] | Retrieve directory values for given key. | [
"Retrieve",
"directory",
"values",
"for",
"given",
"key",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L972-L976 |
25,982 | datastore/datastore | datastore/core/basic.py | DatastoreCollection.appendDatastore | def appendDatastore(self, store):
'''Appends datastore `store` to this collection.'''
if not isinstance(store, Datastore):
raise TypeError("stores must be of type %s" % Datastore)
self._stores.append(store) | python | def appendDatastore(self, store):
'''Appends datastore `store` to this collection.'''
if not isinstance(store, Datastore):
raise TypeError("stores must be of type %s" % Datastore)
self._stores.append(store) | [
"def",
"appendDatastore",
"(",
"self",
",",
"store",
")",
":",
"if",
"not",
"isinstance",
"(",
"store",
",",
"Datastore",
")",
":",
"raise",
"TypeError",
"(",
"\"stores must be of type %s\"",
"%",
"Datastore",
")",
"self",
".",
"_stores",
".",
"append",
"(",... | Appends datastore `store` to this collection. | [
"Appends",
"datastore",
"store",
"to",
"this",
"collection",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L999-L1004 |
25,983 | datastore/datastore | datastore/core/basic.py | DatastoreCollection.insertDatastore | def insertDatastore(self, index, store):
'''Inserts datastore `store` into this collection at `index`.'''
if not isinstance(store, Datastore):
raise TypeError("stores must be of type %s" % Datastore)
self._stores.insert(index, store) | python | def insertDatastore(self, index, store):
'''Inserts datastore `store` into this collection at `index`.'''
if not isinstance(store, Datastore):
raise TypeError("stores must be of type %s" % Datastore)
self._stores.insert(index, store) | [
"def",
"insertDatastore",
"(",
"self",
",",
"index",
",",
"store",
")",
":",
"if",
"not",
"isinstance",
"(",
"store",
",",
"Datastore",
")",
":",
"raise",
"TypeError",
"(",
"\"stores must be of type %s\"",
"%",
"Datastore",
")",
"self",
".",
"_stores",
".",
... | Inserts datastore `store` into this collection at `index`. | [
"Inserts",
"datastore",
"store",
"into",
"this",
"collection",
"at",
"index",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L1010-L1015 |
25,984 | datastore/datastore | datastore/core/basic.py | TieredDatastore.get | def get(self, key):
'''Return the object named by key. Checks each datastore in order.'''
value = None
for store in self._stores:
value = store.get(key)
if value is not None:
break
# add model to lower stores only
if value is not None:
for store2 in self._stores:
if store == store2:
break
store2.put(key, value)
return value | python | def get(self, key):
'''Return the object named by key. Checks each datastore in order.'''
value = None
for store in self._stores:
value = store.get(key)
if value is not None:
break
# add model to lower stores only
if value is not None:
for store2 in self._stores:
if store == store2:
break
store2.put(key, value)
return value | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"value",
"=",
"None",
"for",
"store",
"in",
"self",
".",
"_stores",
":",
"value",
"=",
"store",
".",
"get",
"(",
"key",
")",
"if",
"value",
"is",
"not",
"None",
":",
"break",
"# add model to lower stor... | Return the object named by key. Checks each datastore in order. | [
"Return",
"the",
"object",
"named",
"by",
"key",
".",
"Checks",
"each",
"datastore",
"in",
"order",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L1039-L1054 |
25,985 | datastore/datastore | datastore/core/basic.py | TieredDatastore.put | def put(self, key, value):
'''Stores the object in all underlying datastores.'''
for store in self._stores:
store.put(key, value) | python | def put(self, key, value):
'''Stores the object in all underlying datastores.'''
for store in self._stores:
store.put(key, value) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"for",
"store",
"in",
"self",
".",
"_stores",
":",
"store",
".",
"put",
"(",
"key",
",",
"value",
")"
] | Stores the object in all underlying datastores. | [
"Stores",
"the",
"object",
"in",
"all",
"underlying",
"datastores",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L1056-L1059 |
25,986 | datastore/datastore | datastore/core/basic.py | TieredDatastore.contains | def contains(self, key):
'''Returns whether the object is in this datastore.'''
for store in self._stores:
if store.contains(key):
return True
return False | python | def contains(self, key):
'''Returns whether the object is in this datastore.'''
for store in self._stores:
if store.contains(key):
return True
return False | [
"def",
"contains",
"(",
"self",
",",
"key",
")",
":",
"for",
"store",
"in",
"self",
".",
"_stores",
":",
"if",
"store",
".",
"contains",
"(",
"key",
")",
":",
"return",
"True",
"return",
"False"
] | Returns whether the object is in this datastore. | [
"Returns",
"whether",
"the",
"object",
"is",
"in",
"this",
"datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L1074-L1079 |
25,987 | datastore/datastore | datastore/core/basic.py | ShardedDatastore.put | def put(self, key, value):
'''Stores the object to the corresponding datastore.'''
self.shardDatastore(key).put(key, value) | python | def put(self, key, value):
'''Stores the object to the corresponding datastore.'''
self.shardDatastore(key).put(key, value) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"self",
".",
"shardDatastore",
"(",
"key",
")",
".",
"put",
"(",
"key",
",",
"value",
")"
] | Stores the object to the corresponding datastore. | [
"Stores",
"the",
"object",
"to",
"the",
"corresponding",
"datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L1120-L1122 |
25,988 | datastore/datastore | datastore/core/basic.py | ShardedDatastore.shard_query_generator | def shard_query_generator(self, query):
'''A generator that queries each shard in sequence.'''
shard_query = query.copy()
for shard in self._stores:
# yield all items matching within this shard
cursor = shard.query(shard_query)
for item in cursor:
yield item
# update query with results of first query
shard_query.offset = max(shard_query.offset - cursor.skipped, 0)
if shard_query.limit:
shard_query.limit = max(shard_query.limit - cursor.returned, 0)
if shard_query.limit <= 0:
break | python | def shard_query_generator(self, query):
'''A generator that queries each shard in sequence.'''
shard_query = query.copy()
for shard in self._stores:
# yield all items matching within this shard
cursor = shard.query(shard_query)
for item in cursor:
yield item
# update query with results of first query
shard_query.offset = max(shard_query.offset - cursor.skipped, 0)
if shard_query.limit:
shard_query.limit = max(shard_query.limit - cursor.returned, 0)
if shard_query.limit <= 0:
break | [
"def",
"shard_query_generator",
"(",
"self",
",",
"query",
")",
":",
"shard_query",
"=",
"query",
".",
"copy",
"(",
")",
"for",
"shard",
"in",
"self",
".",
"_stores",
":",
"# yield all items matching within this shard",
"cursor",
"=",
"shard",
".",
"query",
"(... | A generator that queries each shard in sequence. | [
"A",
"generator",
"that",
"queries",
"each",
"shard",
"in",
"sequence",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/basic.py#L1138-L1154 |
25,989 | datastore/datastore | datastore/core/serialize.py | monkey_patch_bson | def monkey_patch_bson(bson=None):
'''Patch bson in pymongo to use loads and dumps interface.'''
if not bson:
import bson
if not hasattr(bson, 'loads'):
bson.loads = lambda bsondoc: bson.BSON(bsondoc).decode()
if not hasattr(bson, 'dumps'):
bson.dumps = lambda document: bson.BSON.encode(document) | python | def monkey_patch_bson(bson=None):
'''Patch bson in pymongo to use loads and dumps interface.'''
if not bson:
import bson
if not hasattr(bson, 'loads'):
bson.loads = lambda bsondoc: bson.BSON(bsondoc).decode()
if not hasattr(bson, 'dumps'):
bson.dumps = lambda document: bson.BSON.encode(document) | [
"def",
"monkey_patch_bson",
"(",
"bson",
"=",
"None",
")",
":",
"if",
"not",
"bson",
":",
"import",
"bson",
"if",
"not",
"hasattr",
"(",
"bson",
",",
"'loads'",
")",
":",
"bson",
".",
"loads",
"=",
"lambda",
"bsondoc",
":",
"bson",
".",
"BSON",
"(",
... | Patch bson in pymongo to use loads and dumps interface. | [
"Patch",
"bson",
"in",
"pymongo",
"to",
"use",
"loads",
"and",
"dumps",
"interface",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L112-L121 |
25,990 | datastore/datastore | datastore/core/serialize.py | Stack.loads | def loads(self, value):
'''Returns deserialized `value`.'''
for serializer in reversed(self):
value = serializer.loads(value)
return value | python | def loads(self, value):
'''Returns deserialized `value`.'''
for serializer in reversed(self):
value = serializer.loads(value)
return value | [
"def",
"loads",
"(",
"self",
",",
"value",
")",
":",
"for",
"serializer",
"in",
"reversed",
"(",
"self",
")",
":",
"value",
"=",
"serializer",
".",
"loads",
"(",
"value",
")",
"return",
"value"
] | Returns deserialized `value`. | [
"Returns",
"deserialized",
"value",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L64-L68 |
25,991 | datastore/datastore | datastore/core/serialize.py | Stack.dumps | def dumps(self, value):
'''returns serialized `value`.'''
for serializer in self:
value = serializer.dumps(value)
return value | python | def dumps(self, value):
'''returns serialized `value`.'''
for serializer in self:
value = serializer.dumps(value)
return value | [
"def",
"dumps",
"(",
"self",
",",
"value",
")",
":",
"for",
"serializer",
"in",
"self",
":",
"value",
"=",
"serializer",
".",
"dumps",
"(",
"value",
")",
"return",
"value"
] | returns serialized `value`. | [
"returns",
"serialized",
"value",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L70-L74 |
25,992 | datastore/datastore | datastore/core/serialize.py | map_serializer.loads | def loads(cls, value):
'''Returns mapping type deserialized `value`.'''
if len(value) == 1 and cls.sentinel in value:
value = value[cls.sentinel]
return value | python | def loads(cls, value):
'''Returns mapping type deserialized `value`.'''
if len(value) == 1 and cls.sentinel in value:
value = value[cls.sentinel]
return value | [
"def",
"loads",
"(",
"cls",
",",
"value",
")",
":",
"if",
"len",
"(",
"value",
")",
"==",
"1",
"and",
"cls",
".",
"sentinel",
"in",
"value",
":",
"value",
"=",
"value",
"[",
"cls",
".",
"sentinel",
"]",
"return",
"value"
] | Returns mapping type deserialized `value`. | [
"Returns",
"mapping",
"type",
"deserialized",
"value",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L84-L88 |
25,993 | datastore/datastore | datastore/core/serialize.py | map_serializer.dumps | def dumps(cls, value):
'''returns mapping typed serialized `value`.'''
if not hasattr(value, '__getitem__') or not hasattr(value, 'iteritems'):
value = {cls.sentinel: value}
return value | python | def dumps(cls, value):
'''returns mapping typed serialized `value`.'''
if not hasattr(value, '__getitem__') or not hasattr(value, 'iteritems'):
value = {cls.sentinel: value}
return value | [
"def",
"dumps",
"(",
"cls",
",",
"value",
")",
":",
"if",
"not",
"hasattr",
"(",
"value",
",",
"'__getitem__'",
")",
"or",
"not",
"hasattr",
"(",
"value",
",",
"'iteritems'",
")",
":",
"value",
"=",
"{",
"cls",
".",
"sentinel",
":",
"value",
"}",
"... | returns mapping typed serialized `value`. | [
"returns",
"mapping",
"typed",
"serialized",
"value",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L91-L95 |
25,994 | datastore/datastore | datastore/core/serialize.py | SerializerShimDatastore.get | def get(self, key):
'''Return the object named by key or None if it does not exist.
Retrieves the value from the ``child_datastore``, and de-serializes
it on the way out.
Args:
key: Key naming the object to retrieve
Returns:
object or None
'''
''''''
value = self.child_datastore.get(key)
return self.deserializedValue(value) | python | def get(self, key):
'''Return the object named by key or None if it does not exist.
Retrieves the value from the ``child_datastore``, and de-serializes
it on the way out.
Args:
key: Key naming the object to retrieve
Returns:
object or None
'''
''''''
value = self.child_datastore.get(key)
return self.deserializedValue(value) | [
"def",
"get",
"(",
"self",
",",
"key",
")",
":",
"''''''",
"value",
"=",
"self",
".",
"child_datastore",
".",
"get",
"(",
"key",
")",
"return",
"self",
".",
"deserializedValue",
"(",
"value",
")"
] | Return the object named by key or None if it does not exist.
Retrieves the value from the ``child_datastore``, and de-serializes
it on the way out.
Args:
key: Key naming the object to retrieve
Returns:
object or None | [
"Return",
"the",
"object",
"named",
"by",
"key",
"or",
"None",
"if",
"it",
"does",
"not",
"exist",
".",
"Retrieves",
"the",
"value",
"from",
"the",
"child_datastore",
"and",
"de",
"-",
"serializes",
"it",
"on",
"the",
"way",
"out",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L172-L186 |
25,995 | datastore/datastore | datastore/core/serialize.py | SerializerShimDatastore.put | def put(self, key, value):
'''Stores the object `value` named by `key`.
Serializes values on the way in, and stores the serialized data into the
``child_datastore``.
Args:
key: Key naming `value`
value: the object to store.
'''
value = self.serializedValue(value)
self.child_datastore.put(key, value) | python | def put(self, key, value):
'''Stores the object `value` named by `key`.
Serializes values on the way in, and stores the serialized data into the
``child_datastore``.
Args:
key: Key naming `value`
value: the object to store.
'''
value = self.serializedValue(value)
self.child_datastore.put(key, value) | [
"def",
"put",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"value",
"=",
"self",
".",
"serializedValue",
"(",
"value",
")",
"self",
".",
"child_datastore",
".",
"put",
"(",
"key",
",",
"value",
")"
] | Stores the object `value` named by `key`.
Serializes values on the way in, and stores the serialized data into the
``child_datastore``.
Args:
key: Key naming `value`
value: the object to store. | [
"Stores",
"the",
"object",
"value",
"named",
"by",
"key",
".",
"Serializes",
"values",
"on",
"the",
"way",
"in",
"and",
"stores",
"the",
"serialized",
"data",
"into",
"the",
"child_datastore",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/serialize.py#L188-L199 |
25,996 | datastore/datastore | datastore/core/query.py | _object_getattr | def _object_getattr(obj, field):
'''Attribute getter for the objects to operate on.
This function can be overridden in classes or instances of Query, Filter, and
Order. Thus, a custom function to extract values to attributes can be
specified, and the system can remain agnostic to the client's data model,
without loosing query power.
For example, the default implementation works with attributes and items::
def _object_getattr(obj, field):
# check whether this key is an attribute
if hasattr(obj, field):
value = getattr(obj, field)
# if not, perhaps it is an item (raw dicts, etc)
elif field in obj:
value = obj[field]
# return whatever we've got.
return value
Or consider a more complex, application-specific structure::
def _object_getattr(version, field):
if field in ['key', 'committed', 'created', 'hash']:
return getattr(version, field)
else:
return version.attributes[field]['value']
'''
# TODO: consider changing this to raise an exception if no value is found.
value = None
# check whether this key is an attribute
if hasattr(obj, field):
value = getattr(obj, field)
# if not, perhaps it is an item (raw dicts, etc)
elif field in obj:
value = obj[field]
# return whatever we've got.
return value | python | def _object_getattr(obj, field):
'''Attribute getter for the objects to operate on.
This function can be overridden in classes or instances of Query, Filter, and
Order. Thus, a custom function to extract values to attributes can be
specified, and the system can remain agnostic to the client's data model,
without loosing query power.
For example, the default implementation works with attributes and items::
def _object_getattr(obj, field):
# check whether this key is an attribute
if hasattr(obj, field):
value = getattr(obj, field)
# if not, perhaps it is an item (raw dicts, etc)
elif field in obj:
value = obj[field]
# return whatever we've got.
return value
Or consider a more complex, application-specific structure::
def _object_getattr(version, field):
if field in ['key', 'committed', 'created', 'hash']:
return getattr(version, field)
else:
return version.attributes[field]['value']
'''
# TODO: consider changing this to raise an exception if no value is found.
value = None
# check whether this key is an attribute
if hasattr(obj, field):
value = getattr(obj, field)
# if not, perhaps it is an item (raw dicts, etc)
elif field in obj:
value = obj[field]
# return whatever we've got.
return value | [
"def",
"_object_getattr",
"(",
"obj",
",",
"field",
")",
":",
"# TODO: consider changing this to raise an exception if no value is found.",
"value",
"=",
"None",
"# check whether this key is an attribute",
"if",
"hasattr",
"(",
"obj",
",",
"field",
")",
":",
"value",
"=",... | Attribute getter for the objects to operate on.
This function can be overridden in classes or instances of Query, Filter, and
Order. Thus, a custom function to extract values to attributes can be
specified, and the system can remain agnostic to the client's data model,
without loosing query power.
For example, the default implementation works with attributes and items::
def _object_getattr(obj, field):
# check whether this key is an attribute
if hasattr(obj, field):
value = getattr(obj, field)
# if not, perhaps it is an item (raw dicts, etc)
elif field in obj:
value = obj[field]
# return whatever we've got.
return value
Or consider a more complex, application-specific structure::
def _object_getattr(version, field):
if field in ['key', 'committed', 'created', 'hash']:
return getattr(version, field)
else:
return version.attributes[field]['value'] | [
"Attribute",
"getter",
"for",
"the",
"objects",
"to",
"operate",
"on",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/query.py#L5-L52 |
25,997 | datastore/datastore | datastore/core/query.py | limit_gen | def limit_gen(limit, iterable):
'''A generator that applies a count `limit`.'''
limit = int(limit)
assert limit >= 0, 'negative limit'
for item in iterable:
if limit <= 0:
break
yield item
limit -= 1 | python | def limit_gen(limit, iterable):
'''A generator that applies a count `limit`.'''
limit = int(limit)
assert limit >= 0, 'negative limit'
for item in iterable:
if limit <= 0:
break
yield item
limit -= 1 | [
"def",
"limit_gen",
"(",
"limit",
",",
"iterable",
")",
":",
"limit",
"=",
"int",
"(",
"limit",
")",
"assert",
"limit",
">=",
"0",
",",
"'negative limit'",
"for",
"item",
"in",
"iterable",
":",
"if",
"limit",
"<=",
"0",
":",
"break",
"yield",
"item",
... | A generator that applies a count `limit`. | [
"A",
"generator",
"that",
"applies",
"a",
"count",
"limit",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/query.py#L57-L66 |
25,998 | datastore/datastore | datastore/core/query.py | offset_gen | def offset_gen(offset, iterable, skip_signal=None):
'''A generator that applies an `offset`, skipping `offset` elements from
`iterable`. If skip_signal is a callable, it will be called with every
skipped element.
'''
offset = int(offset)
assert offset >= 0, 'negative offset'
for item in iterable:
if offset > 0:
offset -= 1
if callable(skip_signal):
skip_signal(item)
else:
yield item | python | def offset_gen(offset, iterable, skip_signal=None):
'''A generator that applies an `offset`, skipping `offset` elements from
`iterable`. If skip_signal is a callable, it will be called with every
skipped element.
'''
offset = int(offset)
assert offset >= 0, 'negative offset'
for item in iterable:
if offset > 0:
offset -= 1
if callable(skip_signal):
skip_signal(item)
else:
yield item | [
"def",
"offset_gen",
"(",
"offset",
",",
"iterable",
",",
"skip_signal",
"=",
"None",
")",
":",
"offset",
"=",
"int",
"(",
"offset",
")",
"assert",
"offset",
">=",
"0",
",",
"'negative offset'",
"for",
"item",
"in",
"iterable",
":",
"if",
"offset",
">",
... | A generator that applies an `offset`, skipping `offset` elements from
`iterable`. If skip_signal is a callable, it will be called with every
skipped element. | [
"A",
"generator",
"that",
"applies",
"an",
"offset",
"skipping",
"offset",
"elements",
"from",
"iterable",
".",
"If",
"skip_signal",
"is",
"a",
"callable",
"it",
"will",
"be",
"called",
"with",
"every",
"skipped",
"element",
"."
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/query.py#L69-L83 |
25,999 | datastore/datastore | datastore/core/query.py | Filter.valuePasses | def valuePasses(self, value):
'''Returns whether this value passes this filter'''
return self._conditional_cmp[self.op](value, self.value) | python | def valuePasses(self, value):
'''Returns whether this value passes this filter'''
return self._conditional_cmp[self.op](value, self.value) | [
"def",
"valuePasses",
"(",
"self",
",",
"value",
")",
":",
"return",
"self",
".",
"_conditional_cmp",
"[",
"self",
".",
"op",
"]",
"(",
"value",
",",
"self",
".",
"value",
")"
] | Returns whether this value passes this filter | [
"Returns",
"whether",
"this",
"value",
"passes",
"this",
"filter"
] | 7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3 | https://github.com/datastore/datastore/blob/7ccf0cd4748001d3dbf5e6dda369b0f63e0269d3/datastore/core/query.py#L154-L156 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.