nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
join_path
(a, b)
return rv
56
76
def join_path(a, b): a_p, a_v = split_virtual_path(a) b_p, b_v = split_virtual_path(b) # Special case: paginations are considered special virtual paths # where the parent is the actual parent of the page. This however # is explicitly not done if the path we join with refers to the # current path (empty string or dot). if b_p not in ("", ".") and a_v and a_v.isdigit(): a_v = None # New path has a virtual path, add that to it. if b_v: rv = _norm_join(a_p, b_p) + "@" + b_v elif a_v: rv = a_p + "@" + _norm_join(a_v, b_p) else: rv = _norm_join(a_p, b_p) if rv[-2:] == "@.": rv = rv[:-2] return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L56-L76
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20 ]
95.238095
[]
0
false
63.731656
21
7
100
0
def join_path(a, b): a_p, a_v = split_virtual_path(a) b_p, b_v = split_virtual_path(b) # Special case: paginations are considered special virtual paths # where the parent is the actual parent of the page. This however # is explicitly not done if the path we join with refers to the # current path (empty string or dot). if b_p not in ("", ".") and a_v and a_v.isdigit(): a_v = None # New path has a virtual path, add that to it. if b_v: rv = _norm_join(a_p, b_p) + "@" + b_v elif a_v: rv = a_p + "@" + _norm_join(a_v, b_p) else: rv = _norm_join(a_p, b_p) if rv[-2:] == "@.": rv = rv[:-2] return rv
26,114
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
cleanup_path
(path)
return posixpath.normpath("/" + path.lstrip("/"))
79
82
def cleanup_path(path): # NB: POSIX allows for two leading slashes in a pathname, so we have to # deal with the possiblity of leading double-slash ourself. return posixpath.normpath("/" + path.lstrip("/"))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L79-L82
40
[ 0, 1, 2, 3 ]
100
[]
0
true
63.731656
4
1
100
0
def cleanup_path(path): # NB: POSIX allows for two leading slashes in a pathname, so we have to # deal with the possiblity of leading double-slash ourself. return posixpath.normpath("/" + path.lstrip("/"))
26,115
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
cleanup_url_path
(url_path)
return posixpath.normpath("/" + path.lstrip("/"))
Clean up a URL path. This strips any query, and/or fragment that may be present in the input path. Raises ValueError if the path contains a _scheme_ which is neither ``http`` nor ``https``, or a _netloc_.
Clean up a URL path.
85
102
def cleanup_url_path(url_path): """Clean up a URL path. This strips any query, and/or fragment that may be present in the input path. Raises ValueError if the path contains a _scheme_ which is neither ``http`` nor ``https``, or a _netloc_. """ scheme, netloc, path, _, _ = urlsplit(url_path, scheme="http") if scheme not in ("http", "https"): raise ValueError(f"Invalid scheme: {url_path!r}") if netloc: raise ValueError(f"Invalid netloc: {url_path!r}") # NB: POSIX allows for two leading slashes in a pathname, so we have to # deal with the possiblity of leading double-slash ourself. return posixpath.normpath("/" + path.lstrip("/"))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L85-L102
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
63.731656
18
3
100
7
def cleanup_url_path(url_path): scheme, netloc, path, _, _ = urlsplit(url_path, scheme="http") if scheme not in ("http", "https"): raise ValueError(f"Invalid scheme: {url_path!r}") if netloc: raise ValueError(f"Invalid netloc: {url_path!r}") # NB: POSIX allows for two leading slashes in a pathname, so we have to # deal with the possiblity of leading double-slash ourself. return posixpath.normpath("/" + path.lstrip("/"))
26,116
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
parse_path
(path)
return x
105
109
def parse_path(path): x = cleanup_path(path).strip("/").split("/") if x == [""]: return [] return x
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L105-L109
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
63.731656
5
2
100
0
def parse_path(path): x = cleanup_path(path).strip("/").split("/") if x == [""]: return [] return x
26,117
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
is_path_child_of
(a, b, strict=True)
return a_p[: len(b_p)] == b_p and len(a_p) > len(b_p)
112
126
def is_path_child_of(a, b, strict=True): a_p, a_v = split_virtual_path(a) b_p, b_v = split_virtual_path(b) a_p = parse_path(a_p) b_p = parse_path(b_p) a_v = parse_path(a_v or "") b_v = parse_path(b_v or "") if not strict and a_p == b_p and a_v == b_v: return True if not a_v and b_v: return False if a_p == b_p and a_v[: len(b_v)] == b_v and len(a_v) > len(b_v): return True return a_p[: len(b_p)] == b_p and len(a_p) > len(b_p)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L112-L126
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14 ]
93.333333
[ 11 ]
6.666667
false
63.731656
15
12
93.333333
0
def is_path_child_of(a, b, strict=True): a_p, a_v = split_virtual_path(a) b_p, b_v = split_virtual_path(b) a_p = parse_path(a_p) b_p = parse_path(b_p) a_v = parse_path(a_v or "") b_v = parse_path(b_v or "") if not strict and a_p == b_p and a_v == b_v: return True if not a_v and b_v: return False if a_p == b_p and a_v[: len(b_v)] == b_v and len(a_v) > len(b_v): return True return a_p[: len(b_p)] == b_p and len(a_p) > len(b_p)
26,118
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
untrusted_to_os_path
(path)
return path
129
133
def untrusted_to_os_path(path): path = path.strip("/").replace("/", os.path.sep) if not isinstance(path, str): path = path.decode(fs_enc, "replace") return path
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L129-L133
40
[ 0, 1, 2, 4 ]
80
[ 3 ]
20
false
63.731656
5
2
80
0
def untrusted_to_os_path(path): path = path.strip("/").replace("/", os.path.sep) if not isinstance(path, str): path = path.decode(fs_enc, "replace") return path
26,119
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
is_path
(path)
return os.path.sep in path or (os.path.altsep and os.path.altsep in path)
136
137
def is_path(path): return os.path.sep in path or (os.path.altsep and os.path.altsep in path)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L136-L137
40
[ 0 ]
50
[ 1 ]
50
false
63.731656
2
3
50
0
def is_path(path): return os.path.sep in path or (os.path.altsep and os.path.altsep in path)
26,120
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
magic_split_ext
(filename, ext_check=True)
return basename, ext
Splits a filename into base and extension. If ext check is enabled (which is the default) then it verifies the extension is at least reasonable.
Splits a filename into base and extension. If ext check is enabled (which is the default) then it verifies the extension is at least reasonable.
140
166
def magic_split_ext(filename, ext_check=True): """Splits a filename into base and extension. If ext check is enabled (which is the default) then it verifies the extension is at least reasonable. """ def bad_ext(ext): if not ext_check: return False if not ext or ext.split() != [ext] or ext.strip() != ext: return True return False parts = filename.rsplit(".", 2) if len(parts) == 1: return parts[0], "" if len(parts) == 2 and not parts[0]: return "." + parts[1], "" if len(parts) == 3 and len(parts[1]) < 5: ext = ".".join(parts[1:]) if not bad_ext(ext): return parts[0], ext ext = parts[-1] if bad_ext(ext): return filename, "" basename = ".".join(parts[:-1]) return basename, ext
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L140-L166
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 22, 23, 24, 25, 26 ]
85.185185
[ 17, 19, 20, 21 ]
14.814815
false
63.731656
27
13
85.185185
3
def magic_split_ext(filename, ext_check=True): def bad_ext(ext): if not ext_check: return False if not ext or ext.split() != [ext] or ext.strip() != ext: return True return False parts = filename.rsplit(".", 2) if len(parts) == 1: return parts[0], "" if len(parts) == 2 and not parts[0]: return "." + parts[1], "" if len(parts) == 3 and len(parts[1]) < 5: ext = ".".join(parts[1:]) if not bad_ext(ext): return parts[0], ext ext = parts[-1] if bad_ext(ext): return filename, "" basename = ".".join(parts[:-1]) return basename, ext
26,121
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
iter_dotted_path_prefixes
(dotted_path)
169
175
def iter_dotted_path_prefixes(dotted_path): pieces = dotted_path.split(".") if len(pieces) == 1: yield dotted_path, None else: for x in range(1, len(pieces)): yield ".".join(pieces[:x]), ".".join(pieces[x:])
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L169-L175
40
[ 0 ]
14.285714
[ 1, 2, 3, 5, 6 ]
71.428571
false
63.731656
7
3
28.571429
0
def iter_dotted_path_prefixes(dotted_path): pieces = dotted_path.split(".") if len(pieces) == 1: yield dotted_path, None else: for x in range(1, len(pieces)): yield ".".join(pieces[:x]), ".".join(pieces[x:])
26,122
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
resolve_dotted_value
(obj, dotted_path)
return node
178
195
def resolve_dotted_value(obj, dotted_path): node = obj for key in dotted_path.split("."): if isinstance(node, dict): new_node = node.get(key) if new_node is None and key.isdigit(): new_node = node.get(int(key)) elif isinstance(node, list): try: new_node = node[int(key)] except (ValueError, TypeError, IndexError): new_node = None else: new_node = None node = new_node if node is None: break return node
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L178-L195
40
[ 0 ]
5.555556
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17 ]
88.888889
false
63.731656
18
8
11.111111
0
def resolve_dotted_value(obj, dotted_path): node = obj for key in dotted_path.split("."): if isinstance(node, dict): new_node = node.get(key) if new_node is None and key.isdigit(): new_node = node.get(int(key)) elif isinstance(node, list): try: new_node = node[int(key)] except (ValueError, TypeError, IndexError): new_node = None else: new_node = None node = new_node if node is None: break return node
26,123
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
decode_flat_data
(itemiter, dict_cls=dict)
return _convert(result)
198
241
def decode_flat_data(itemiter, dict_cls=dict): def _split_key(name): result = name.split(".") for idx, part in enumerate(result): if part.isdigit(): result[idx] = int(part) return result def _enter_container(container, key): if key not in container: return container.setdefault(key, dict_cls()) return container[key] def _convert(container): if _value_marker in container: force_list = False values = container.pop(_value_marker) if container.pop(_list_marker, False): force_list = True values.extend(_convert(x[1]) for x in sorted(container.items())) if not force_list and len(values) == 1: values = values[0] if not container: return values return _convert(container) if container.pop(_list_marker, False): return [_convert(x[1]) for x in sorted(container.items())] return dict_cls((k, _convert(v)) for k, v in container.items()) result = dict_cls() for key, value in itemiter: parts = _split_key(key) if not parts: continue container = result for part in parts: last_container = container container = _enter_container(container, part) last_container[_list_marker] = isinstance(part, int) container[_value_marker] = [value] return _convert(result)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L198-L241
40
[ 0 ]
2.272727
[ 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43 ]
84.090909
false
63.731656
44
17
15.909091
0
def decode_flat_data(itemiter, dict_cls=dict): def _split_key(name): result = name.split(".") for idx, part in enumerate(result): if part.isdigit(): result[idx] = int(part) return result def _enter_container(container, key): if key not in container: return container.setdefault(key, dict_cls()) return container[key] def _convert(container): if _value_marker in container: force_list = False values = container.pop(_value_marker) if container.pop(_list_marker, False): force_list = True values.extend(_convert(x[1]) for x in sorted(container.items())) if not force_list and len(values) == 1: values = values[0] if not container: return values return _convert(container) if container.pop(_list_marker, False): return [_convert(x[1]) for x in sorted(container.items())] return dict_cls((k, _convert(v)) for k, v in container.items()) result = dict_cls() for key, value in itemiter: parts = _split_key(key) if not parts: continue container = result for part in parts: last_container = container container = _enter_container(container, part) last_container[_list_marker] = isinstance(part, int) container[_value_marker] = [value] return _convert(result)
26,124
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
merge
(a, b)
return a
Merges two values together.
Merges two values together.
244
257
def merge(a, b): """Merges two values together.""" if b is None and a is not None: return a if a is None: return b if isinstance(a, list) and isinstance(b, list): for idx, (item_1, item_2) in enumerate(zip(a, b)): a[idx] = merge(item_1, item_2) if isinstance(a, dict) and isinstance(b, dict): for key, value in b.items(): a[key] = merge(a.get(key), value) return a return a
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L244-L257
40
[ 0, 1 ]
14.285714
[ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
85.714286
false
63.731656
14
10
14.285714
1
def merge(a, b): if b is None and a is not None: return a if a is None: return b if isinstance(a, list) and isinstance(b, list): for idx, (item_1, item_2) in enumerate(zip(a, b)): a[idx] = merge(item_1, item_2) if isinstance(a, dict) and isinstance(b, dict): for key, value in b.items(): a[key] = merge(a.get(key), value) return a return a
26,125
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
slugify
(text)
return out
A wrapper around python-slugify which preserves file extensions and forward slashes.
A wrapper around python-slugify which preserves file extensions and forward slashes.
260
273
def slugify(text): """ A wrapper around python-slugify which preserves file extensions and forward slashes. """ parts = text.split("/") parts[-1], ext = magic_split_ext(parts[-1]) out = "/".join(_slugify(part) for part in parts) if ext: return out + "." + ext return out
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L260-L273
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
63.731656
14
2
100
2
def slugify(text): parts = text.split("/") parts[-1], ext = magic_split_ext(parts[-1]) out = "/".join(_slugify(part) for part in parts) if ext: return out + "." + ext return out
26,126
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
secure_filename
(filename, fallback_name="file")
return rv
276
284
def secure_filename(filename, fallback_name="file"): base = filename.replace("/", " ").replace("\\", " ") basename, ext = magic_split_ext(base) rv = slugify(basename).lstrip(".") if not rv: rv = fallback_name if ext: return rv + "." + ext return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L276-L284
40
[ 0, 1, 2, 3, 4, 6, 7 ]
77.777778
[ 5, 8 ]
22.222222
false
63.731656
9
3
77.777778
0
def secure_filename(filename, fallback_name="file"): base = filename.replace("/", " ").replace("\\", " ") basename, ext = magic_split_ext(base) rv = slugify(basename).lstrip(".") if not rv: rv = fallback_name if ext: return rv + "." + ext return rv
26,127
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
increment_filename
(filename)
return rv
287
301
def increment_filename(filename): directory, filename = os.path.split(filename) basename, ext = magic_split_ext(filename, ext_check=False) match = _last_num_re.match(basename) if match is not None: rv = match.group(1) + str(int(match.group(2)) + 1) + match.group(3) else: rv = basename + "2" if ext: rv += "." + ext if directory: return os.path.join(directory, rv) return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L287-L301
40
[ 0 ]
6.666667
[ 1, 2, 4, 5, 6, 8, 10, 11, 12, 13, 14 ]
73.333333
false
63.731656
15
4
26.666667
0
def increment_filename(filename): directory, filename = os.path.split(filename) basename, ext = magic_split_ext(filename, ext_check=False) match = _last_num_re.match(basename) if match is not None: rv = match.group(1) + str(int(match.group(2)) + 1) + match.group(3) else: rv = basename + "2" if ext: rv += "." + ext if directory: return os.path.join(directory, rv) return rv
26,128
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
locate_executable
(exe_file, cwd=None, include_bundle_path=True)
Locates an executable in the search path.
Locates an executable in the search path.
305
337
def locate_executable(exe_file, cwd=None, include_bundle_path=True): """Locates an executable in the search path.""" choices = [exe_file] resolve = True # If it's already a path, we don't resolve. if os.path.sep in exe_file or (os.path.altsep and os.path.altsep in exe_file): resolve = False extensions = os.environ.get("PATHEXT", "").split(";") _, ext = os.path.splitext(exe_file) if ( os.name != "nt" and "" not in extensions or any(ext.lower() == extension.lower() for extension in extensions) ): extensions.insert(0, "") if resolve: paths = os.environ.get("PATH", "").split(os.pathsep) choices = [os.path.join(path, exe_file) for path in paths] if os.name == "nt": choices.append(os.path.join((cwd or os.getcwd()), exe_file)) try: for path in choices: for ext in extensions: if os.access(path + ext, os.X_OK): return path + ext return None except OSError: return None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L305-L337
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30 ]
90.909091
[ 23, 31, 32 ]
9.090909
false
63.731656
33
15
90.909091
1
def locate_executable(exe_file, cwd=None, include_bundle_path=True): choices = [exe_file] resolve = True # If it's already a path, we don't resolve. if os.path.sep in exe_file or (os.path.altsep and os.path.altsep in exe_file): resolve = False extensions = os.environ.get("PATHEXT", "").split(";") _, ext = os.path.splitext(exe_file) if ( os.name != "nt" and "" not in extensions or any(ext.lower() == extension.lower() for extension in extensions) ): extensions.insert(0, "") if resolve: paths = os.environ.get("PATH", "").split(os.pathsep) choices = [os.path.join(path, exe_file) for path in paths] if os.name == "nt": choices.append(os.path.join((cwd or os.getcwd()), exe_file)) try: for path in choices: for ext in extensions: if os.access(path + ext, os.X_OK): return path + ext return None except OSError: return None
26,129
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
htmlsafe_json_dump
(obj, **kwargs)
return rv
353
364
def htmlsafe_json_dump(obj, **kwargs): kwargs.setdefault("cls", JSONEncoder) rv = ( json.dumps(obj, **kwargs) .replace("<", "\\u003c") .replace(">", "\\u003e") .replace("&", "\\u0026") .replace("'", "\\u0027") ) if not _slash_escape: rv = rv.replace("\\/", "/") return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L353-L364
40
[ 0 ]
8.333333
[ 1, 2, 9, 10, 11 ]
41.666667
false
63.731656
12
2
58.333333
0
def htmlsafe_json_dump(obj, **kwargs): kwargs.setdefault("cls", JSONEncoder) rv = ( json.dumps(obj, **kwargs) .replace("<", "\\u003c") .replace(">", "\\u003e") .replace("&", "\\u0026") .replace("'", "\\u0027") ) if not _slash_escape: rv = rv.replace("\\/", "/") return rv
26,130
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
tojson_filter
(obj, **kwargs)
return Markup(htmlsafe_json_dump(obj, **kwargs))
367
368
def tojson_filter(obj, **kwargs): return Markup(htmlsafe_json_dump(obj, **kwargs))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L367-L368
40
[ 0 ]
50
[ 1 ]
50
false
63.731656
2
1
50
0
def tojson_filter(obj, **kwargs): return Markup(htmlsafe_json_dump(obj, **kwargs))
26,131
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
is_unsafe_to_delete
(path, base)
return first in (os.path.curdir, os.path.pardir)
392
397
def is_unsafe_to_delete(path, base): a = os.path.abspath(path) b = os.path.abspath(base) diff = os.path.relpath(a, b) first = diff.split(os.path.sep)[0] return first in (os.path.curdir, os.path.pardir)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L392-L397
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
63.731656
6
1
100
0
def is_unsafe_to_delete(path, base): a = os.path.abspath(path) b = os.path.abspath(base) diff = os.path.relpath(a, b) first = diff.split(os.path.sep)[0] return first in (os.path.curdir, os.path.pardir)
26,132
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
prune_file_and_folder
(name, base)
return True
400
421
def prune_file_and_folder(name, base): if is_unsafe_to_delete(name, base): return False try: os.remove(name) except OSError: try: os.rmdir(name) except OSError: return False head, tail = os.path.split(name) if not tail: head, tail = os.path.split(head) while head and tail: try: if is_unsafe_to_delete(head, base): return False os.rmdir(head) except OSError: break head, tail = os.path.split(head) return True
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L400-L421
40
[ 0, 1, 3, 4, 10, 11, 13, 14, 15, 16, 17, 20 ]
54.545455
[ 2, 5, 6, 7, 8, 9, 12, 18, 19, 21 ]
45.454545
false
63.731656
22
9
54.545455
0
def prune_file_and_folder(name, base): if is_unsafe_to_delete(name, base): return False try: os.remove(name) except OSError: try: os.rmdir(name) except OSError: return False head, tail = os.path.split(name) if not tail: head, tail = os.path.split(head) while head and tail: try: if is_unsafe_to_delete(head, base): return False os.rmdir(head) except OSError: break head, tail = os.path.split(head) return True
26,133
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
sort_normalize_string
(s)
return unicodedata.normalize("NFD", str(s).lower().strip())
424
425
def sort_normalize_string(s): return unicodedata.normalize("NFD", str(s).lower().strip())
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L424-L425
40
[ 0, 1 ]
100
[]
0
true
63.731656
2
1
100
0
def sort_normalize_string(s): return unicodedata.normalize("NFD", str(s).lower().strip())
26,134
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
get_dependent_url
(url_path, suffix, ext=None)
return posixpath.join(url_directory, url_base + "@" + suffix + ext)
428
433
def get_dependent_url(url_path, suffix, ext=None): url_directory, url_filename = posixpath.split(url_path) url_base, url_ext = posixpath.splitext(url_filename) if ext is None: ext = url_ext return posixpath.join(url_directory, url_base + "@" + suffix + ext)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L428-L433
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
63.731656
6
2
100
0
def get_dependent_url(url_path, suffix, ext=None): url_directory, url_filename = posixpath.split(url_path) url_base, url_ext = posixpath.splitext(url_filename) if ext is None: ext = url_ext return posixpath.join(url_directory, url_base + "@" + suffix + ext)
26,135
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
atomic_open
(filename, mode="r", encoding=None)
437
464
def atomic_open(filename, mode="r", encoding=None): if "r" not in mode: fd, tmp_filename = tempfile.mkstemp( dir=os.path.dirname(filename), prefix=".__atomic-write" ) os.chmod(tmp_filename, 0o644) f = os.fdopen(fd, mode) else: f = open(filename, mode=mode, encoding=encoding) tmp_filename = None try: yield f except Exception as e: f.close() _exc_type, exc_value, tb = sys.exc_info() if tmp_filename is not None: try: os.remove(tmp_filename) except OSError: pass if exc_value.__traceback__ is not tb: raise exc_value.with_traceback(tb) from e raise exc_value from e else: f.close() if tmp_filename is not None: os.replace(tmp_filename, filename)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L437-L464
40
[ 0, 1, 2, 5, 6, 10, 11, 25, 26, 27 ]
35.714286
[ 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23 ]
46.428571
false
63.731656
28
7
53.571429
0
def atomic_open(filename, mode="r", encoding=None): if "r" not in mode: fd, tmp_filename = tempfile.mkstemp( dir=os.path.dirname(filename), prefix=".__atomic-write" ) os.chmod(tmp_filename, 0o644) f = os.fdopen(fd, mode) else: f = open(filename, mode=mode, encoding=encoding) tmp_filename = None try: yield f except Exception as e: f.close() _exc_type, exc_value, tb = sys.exc_info() if tmp_filename is not None: try: os.remove(tmp_filename) except OSError: pass if exc_value.__traceback__ is not tb: raise exc_value.with_traceback(tb) from e raise exc_value from e else: f.close() if tmp_filename is not None: os.replace(tmp_filename, filename)
26,136
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
portable_popen
(cmd, *args, **kwargs)
return subprocess.Popen(cmd, *args, **kwargs)
A portable version of subprocess.Popen that automatically locates executables before invoking them. This also looks for executables in the bundle bin.
A portable version of subprocess.Popen that automatically locates executables before invoking them. This also looks for executables in the bundle bin.
467
481
def portable_popen(cmd, *args, **kwargs): """A portable version of subprocess.Popen that automatically locates executables before invoking them. This also looks for executables in the bundle bin. """ if cmd[0] is None: raise RuntimeError("No executable specified") exe = locate_executable(cmd[0], kwargs.get("cwd")) if exe is None: raise RuntimeError('Could not locate executable "%s"' % cmd[0]) if isinstance(exe, str) and sys.platform != "win32": exe = exe.encode(sys.getfilesystemencoding()) cmd[0] = exe return subprocess.Popen(cmd, *args, **kwargs)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L467-L481
40
[ 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 12, 13, 14 ]
86.666667
[ 6, 9 ]
13.333333
false
63.731656
15
5
86.666667
3
def portable_popen(cmd, *args, **kwargs): if cmd[0] is None: raise RuntimeError("No executable specified") exe = locate_executable(cmd[0], kwargs.get("cwd")) if exe is None: raise RuntimeError('Could not locate executable "%s"' % cmd[0]) if isinstance(exe, str) and sys.platform != "win32": exe = exe.encode(sys.getfilesystemencoding()) cmd[0] = exe return subprocess.Popen(cmd, *args, **kwargs)
26,137
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
is_valid_id
(value)
return ( "/" not in value and value.strip() == value and value.split() == [value] and not value.startswith(".") )
484
492
def is_valid_id(value): if value == "": return True return ( "/" not in value and value.strip() == value and value.split() == [value] and not value.startswith(".") )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L484-L492
40
[ 0, 1, 2, 3 ]
44.444444
[]
0
false
63.731656
9
5
100
0
def is_valid_id(value): if value == "": return True return ( "/" not in value and value.strip() == value and value.split() == [value] and not value.startswith(".") )
26,138
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
secure_url
(url)
return url.to_url()
495
505
def secure_url(url): url = urls.url_parse(url) if url.password is not None: url = url.replace( netloc="%s@%s" % ( url.username, url.netloc.split("@")[-1], ) ) return url.to_url()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L495-L505
40
[ 0, 1, 2, 10 ]
36.363636
[ 3 ]
9.090909
false
63.731656
11
2
90.909091
0
def secure_url(url): url = urls.url_parse(url) if url.password is not None: url = url.replace( netloc="%s@%s" % ( url.username, url.netloc.split("@")[-1], ) ) return url.to_url()
26,139
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
bool_from_string
(val, default=None)
return default
508
517
def bool_from_string(val, default=None): if val in (True, False, 1, 0): return bool(val) if isinstance(val, str): val = val.lower() if val in ("true", "yes", "1"): return True if val in ("false", "no", "0"): return False return default
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L508-L517
40
[ 0, 1, 3, 4, 5, 6, 7, 8, 9 ]
90
[ 2 ]
10
false
63.731656
10
5
90
0
def bool_from_string(val, default=None): if val in (True, False, 1, 0): return bool(val) if isinstance(val, str): val = val.lower() if val in ("true", "yes", "1"): return True if val in ("false", "no", "0"): return False return default
26,140
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
make_relative_url
(source, target)
return relpath
Returns the relative path (url) needed to navigate from `source` to `target`.
Returns the relative path (url) needed to navigate from `source` to `target`.
520
542
def make_relative_url(source, target): """ Returns the relative path (url) needed to navigate from `source` to `target`. """ # WARNING: this logic makes some unwarranted assumptions about # what is a directory and what isn't. Ideally, this function # would be aware of the actual filesystem. s_is_dir = source.endswith("/") t_is_dir = target.endswith("/") source = PurePosixPath(posixpath.normpath(source)) target = PurePosixPath(posixpath.normpath(target)) if not s_is_dir: source = source.parent relpath = str(get_relative_path(source, target)) if t_is_dir: relpath += "/" return relpath
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L520-L542
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ]
100
[]
0
true
63.731656
23
3
100
2
def make_relative_url(source, target): # WARNING: this logic makes some unwarranted assumptions about # what is a directory and what isn't. Ideally, this function # would be aware of the actual filesystem. s_is_dir = source.endswith("/") t_is_dir = target.endswith("/") source = PurePosixPath(posixpath.normpath(source)) target = PurePosixPath(posixpath.normpath(target)) if not s_is_dir: source = source.parent relpath = str(get_relative_path(source, target)) if t_is_dir: relpath += "/" return relpath
26,141
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
get_relative_path
(source, target)
Returns the relative path needed to navigate from `source` to `target`. get_relative_path(source: PurePosixPath, target: PurePosixPath) -> PurePosixPath
Returns the relative path needed to navigate from `source` to `target`.
545
586
def get_relative_path(source, target): """ Returns the relative path needed to navigate from `source` to `target`. get_relative_path(source: PurePosixPath, target: PurePosixPath) -> PurePosixPath """ if not source.is_absolute() and target.is_absolute(): raise ValueError("Cannot navigate from a relative path to an absolute one") if source.is_absolute() and not target.is_absolute(): # nothing to do return target if source.is_absolute() and target.is_absolute(): # convert them to relative paths to simplify the logic source = source.relative_to("/") target = target.relative_to("/") # is the source an ancestor of the target? try: return target.relative_to(source) except ValueError: pass # even if it isn't, one of the source's ancestors might be # (and if not, the root will be the common ancestor) distance = PurePosixPath(".") for ancestor in source.parents: distance /= ".." try: relpath = target.relative_to(ancestor) except ValueError: continue else: # prepend the distance to the common ancestor return distance / relpath # We should never get here. (The last ancestor in source.parents will # be '.' — target.relative_to('.') will always succeed.) raise AssertionError("This should not happen")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L545-L586
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 ]
97.619048
[ 41 ]
2.380952
false
63.731656
42
10
97.619048
4
def get_relative_path(source, target): if not source.is_absolute() and target.is_absolute(): raise ValueError("Cannot navigate from a relative path to an absolute one") if source.is_absolute() and not target.is_absolute(): # nothing to do return target if source.is_absolute() and target.is_absolute(): # convert them to relative paths to simplify the logic source = source.relative_to("/") target = target.relative_to("/") # is the source an ancestor of the target? try: return target.relative_to(source) except ValueError: pass # even if it isn't, one of the source's ancestors might be # (and if not, the root will be the common ancestor) distance = PurePosixPath(".") for ancestor in source.parents: distance /= ".." try: relpath = target.relative_to(ancestor) except ValueError: continue else: # prepend the distance to the common ancestor return distance / relpath # We should never get here. (The last ancestor in source.parents will # be '.' — target.relative_to('.') will always succeed.) raise AssertionError("This should not happen")
26,142
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
profile_func
(func)
return rv[0]
589
604
def profile_func(func): # pylint: disable=import-outside-toplevel from cProfile import Profile from pstats import Stats p = Profile() rv = [] p.runcall(lambda: rv.append(func())) p.dump_stats("/tmp/lektor-%s.prof" % func.__name__) stats = Stats(p, stream=sys.stderr) stats.sort_stats("time", "calls") stats.print_stats() return rv[0]
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L589-L604
40
[ 0, 1, 2 ]
18.75
[ 3, 4, 6, 7, 8, 9, 11, 12, 13, 15 ]
62.5
false
63.731656
16
1
37.5
0
def profile_func(func): # pylint: disable=import-outside-toplevel from cProfile import Profile from pstats import Stats p = Profile() rv = [] p.runcall(lambda: rv.append(func())) p.dump_stats("/tmp/lektor-%s.prof" % func.__name__) stats = Stats(p, stream=sys.stderr) stats.sort_stats("time", "calls") stats.print_stats() return rv[0]
26,143
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
deg_to_dms
(deg)
return (d, m, sd)
607
612
def deg_to_dms(deg): d = int(deg) md = abs(deg - d) * 60 m = int(md) sd = (md - m) * 60 return (d, m, sd)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L607-L612
40
[ 0 ]
16.666667
[ 1, 2, 3, 4, 5 ]
83.333333
false
63.731656
6
1
16.666667
0
def deg_to_dms(deg): d = int(deg) md = abs(deg - d) * 60 m = int(md) sd = (md - m) * 60 return (d, m, sd)
26,144
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
format_lat_long
(lat=None, long=None, secs=True)
return ", ".join(rv)
615
630
def format_lat_long(lat=None, long=None, secs=True): def _format(value, sign): d, m, sd = deg_to_dms(value) return "%d° %d′ %s%s" % ( abs(d), abs(m), secs and ("%d″ " % abs(sd)) or "", sign[d < 0], ) rv = [] if lat is not None: rv.append(_format(lat, "NS")) if long is not None: rv.append(_format(long, "EW")) return ", ".join(rv)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L615-L630
40
[ 0 ]
6.25
[ 1, 2, 3, 10, 11, 12, 13, 14, 15 ]
56.25
false
63.731656
16
6
43.75
0
def format_lat_long(lat=None, long=None, secs=True): def _format(value, sign): d, m, sd = deg_to_dms(value) return "%d° %d′ %s%s" % ( abs(d), abs(m), secs and ("%d″ " % abs(sd)) or "", sign[d < 0], ) rv = [] if lat is not None: rv.append(_format(lat, "NS")) if long is not None: rv.append(_format(long, "EW")) return ", ".join(rv)
26,145
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
get_cache_dir
()
return os.path.join( os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")), "lektor" )
633
645
def get_cache_dir(): if is_windows: folder = os.environ.get("LOCALAPPDATA") if folder is None: folder = os.environ.get("APPDATA") if folder is None: folder = os.path.expanduser("~") return os.path.join(folder, "Lektor", "Cache") if sys.platform == "darwin": return os.path.join(os.path.expanduser("~/Library/Caches/Lektor")) return os.path.join( os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")), "lektor" )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L633-L645
40
[ 0, 1, 8, 10 ]
30.769231
[ 2, 3, 4, 5, 6, 7, 9 ]
53.846154
false
63.731656
13
5
46.153846
0
def get_cache_dir(): if is_windows: folder = os.environ.get("LOCALAPPDATA") if folder is None: folder = os.environ.get("APPDATA") if folder is None: folder = os.path.expanduser("~") return os.path.join(folder, "Lektor", "Cache") if sys.platform == "darwin": return os.path.join(os.path.expanduser("~/Library/Caches/Lektor")) return os.path.join( os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")), "lektor" )
26,146
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
build_url
(iterable, trailing_slash=None)
return builder.get_url(trailing_slash=trailing_slash)
672
679
def build_url(iterable, trailing_slash=None): # NB: While this function is not used by Lektor itself, it is used # by a number of plugins including: lektor-atom, # lektor-gemini-capsule, lektor-index-pages, and lektor-tags. builder = URLBuilder() for item in iterable: builder.append(item) return builder.get_url(trailing_slash=trailing_slash)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L672-L679
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
63.731656
8
2
100
0
def build_url(iterable, trailing_slash=None): # NB: While this function is not used by Lektor itself, it is used # by a number of plugins including: lektor-atom, # lektor-gemini-capsule, lektor-index-pages, and lektor-tags. builder = URLBuilder() for item in iterable: builder.append(item) return builder.get_url(trailing_slash=trailing_slash)
26,147
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
comma_delimited
(s)
Split a comma-delimited string.
Split a comma-delimited string.
682
687
def comma_delimited(s): """Split a comma-delimited string.""" for part in s.split(","): stripped = part.strip() if stripped: yield stripped
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L682-L687
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
63.731656
6
3
100
1
def comma_delimited(s): for part in s.split(","): stripped = part.strip() if stripped: yield stripped
26,148
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
process_extra_flags
(flags)
return rv
690
700
def process_extra_flags(flags): if isinstance(flags, dict): return flags rv = {} for flag in flags or (): if ":" in flag: k, v = flag.split(":", 1) rv[k] = v else: rv[flag] = flag return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L690-L700
40
[ 0, 1, 2, 3, 4, 5, 9, 10 ]
72.727273
[ 6, 7 ]
18.181818
false
63.731656
11
5
81.818182
0
def process_extra_flags(flags): if isinstance(flags, dict): return flags rv = {} for flag in flags or (): if ":" in flag: k, v = flag.split(":", 1) rv[k] = v else: rv[flag] = flag return rv
26,149
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
unique_everseen
(seq: Iterable[_H])
Filter out duplicates from iterable.
Filter out duplicates from iterable.
706
714
def unique_everseen(seq: Iterable[_H]) -> Iterable[_H]: """Filter out duplicates from iterable.""" # This is a less general version of more_itertools.unique_everseen. # Should we need more general functionality, consider using that instead. seen = set() for val in seq: if val not in seen: seen.add(val) yield val
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L706-L714
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
63.731656
9
3
100
1
def unique_everseen(seq: Iterable[_H]) -> Iterable[_H]: # This is a less general version of more_itertools.unique_everseen. # Should we need more general functionality, consider using that instead. seen = set() for val in seq: if val not in seen: seen.add(val) yield val
26,150
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
JSONEncoder.default
(self, o)
return json.JSONEncoder.default(self, o)
341
350
def default(self, o): # pylint: disable=method-hidden if is_undefined(o): return None if isinstance(o, datetime): return http_date(o) if isinstance(o, uuid.UUID): return str(o) if hasattr(o, "__html__"): return str(o.__html__()) return json.JSONEncoder.default(self, o)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L341-L350
40
[ 0 ]
10
[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
90
false
63.731656
10
5
10
0
def default(self, o): # pylint: disable=method-hidden if is_undefined(o): return None if isinstance(o, datetime): return http_date(o) if isinstance(o, uuid.UUID): return str(o) if hasattr(o, "__html__"): return str(o.__html__()) return json.JSONEncoder.default(self, o)
26,151
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
Url.__init__
(self, value)
372
383
def __init__(self, value): self.url = value u = url_parse(value) i = u.to_iri_tuple() self.ascii_url = str(u) self.host = i.host self.ascii_host = u.ascii_host self.port = u.port self.path = i.path self.query = u.query self.anchor = i.fragment self.scheme = u.scheme
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L372-L383
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
63.731656
12
1
100
0
def __init__(self, value): self.url = value u = url_parse(value) i = u.to_iri_tuple() self.ascii_url = str(u) self.host = i.host self.ascii_host = u.ascii_host self.port = u.port self.path = i.path self.query = u.query self.anchor = i.fragment self.scheme = u.scheme
26,152
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
Url.__unicode__
(self)
return self.url
385
386
def __unicode__(self): return self.url
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L385-L386
40
[ 0 ]
50
[ 1 ]
50
false
63.731656
2
1
50
0
def __unicode__(self): return self.url
26,153
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
Url.__str__
(self)
return self.ascii_url
388
389
def __str__(self): return self.ascii_url
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L388-L389
40
[ 0, 1 ]
100
[]
0
true
63.731656
2
1
100
0
def __str__(self): return self.ascii_url
26,154
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
URLBuilder.__init__
(self)
649
650
def __init__(self): self.items = []
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L649-L650
40
[ 0, 1 ]
100
[]
0
true
63.731656
2
1
100
0
def __init__(self): self.items = []
26,155
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
URLBuilder.append
(self, item)
652
657
def append(self, item): if item is None: return item = str(item).strip("/") if item: self.items.append(item)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L652-L657
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
63.731656
6
3
100
0
def append(self, item): if item is None: return item = str(item).strip("/") if item: self.items.append(item)
26,156
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/utils.py
URLBuilder.get_url
(self, trailing_slash=None)
return url + "/"
659
669
def get_url(self, trailing_slash=None): url = "/" + "/".join(self.items) if trailing_slash is not None and not trailing_slash: return url if url == "/": return url if trailing_slash is None: _, last = url.split("/", 1) if "." in last: return url return url + "/"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L659-L669
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
63.731656
11
6
100
0
def get_url(self, trailing_slash=None): url = "/" + "/".join(self.items) if trailing_slash is not None and not trailing_slash: return url if url == "/": return url if trailing_slash is None: _, last = url.split("/", 1) if "." in last: return url return url + "/"
26,157
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
get_alts
(source=None, fallback=False)
return rv
Given a source this returns the list of all alts that the source exists as. It does not include fallbacks unless `fallback` is passed. If no source is provided all configured alts are returned. If alts are not configured at all, the return value is an empty list.
Given a source this returns the list of all alts that the source exists as. It does not include fallbacks unless `fallback` is passed. If no source is provided all configured alts are returned. If alts are not configured at all, the return value is an empty list.
51
78
def get_alts(source=None, fallback=False): """Given a source this returns the list of all alts that the source exists as. It does not include fallbacks unless `fallback` is passed. If no source is provided all configured alts are returned. If alts are not configured at all, the return value is an empty list. """ if source is None: ctx = get_ctx() if ctx is None: raise RuntimeError("This function requires the context to be supplied.") pad = ctx.pad else: pad = source.pad alts = list(pad.config.iter_alternatives()) if alts == [PRIMARY_ALT]: return [] rv = alts # If a source is provided and it's not virtual, we look up all alts # of the path on the pad to figure out which records exist. if source is not None and "@" not in source.path: rv = [] for alt in alts: if pad.alt_exists(source.path, alt=alt, fallback=fallback): rv.append(alt) return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L51-L78
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
92.857143
[ 9, 15 ]
7.142857
false
89.992532
28
8
92.857143
4
def get_alts(source=None, fallback=False): if source is None: ctx = get_ctx() if ctx is None: raise RuntimeError("This function requires the context to be supplied.") pad = ctx.pad else: pad = source.pad alts = list(pad.config.iter_alternatives()) if alts == [PRIMARY_ALT]: return [] rv = alts # If a source is provided and it's not virtual, we look up all alts # of the path on the pad to figure out which records exist. if source is not None and "@" not in source.path: rv = [] for alt in alts: if pad.alt_exists(source.path, alt=alt, fallback=fallback): rv.append(alt) return rv
26,158
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_require_ctx
(record)
return ctx
81
91
def _require_ctx(record): ctx = get_ctx() if ctx is None: raise RuntimeError( "This operation requires a context but none was on the stack." ) if ctx.pad is not record.pad: raise RuntimeError( "The context on the stack does not match the pad of the record." ) return ctx
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L81-L91
40
[ 0, 1, 2, 6, 10 ]
45.454545
[ 3, 7 ]
18.181818
false
89.992532
11
3
81.818182
0
def _require_ctx(record): ctx = get_ctx() if ctx is None: raise RuntimeError( "This operation requires a context but none was on the stack." ) if ctx.pad is not record.pad: raise RuntimeError( "The context on the stack does not match the pad of the record." ) return ctx
26,159
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_auto_wrap_expr
(value)
return _Literal(value)
152
155
def _auto_wrap_expr(value): if isinstance(value, Expression): return value return _Literal(value)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L152-L155
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
2
100
0
def _auto_wrap_expr(value): if isinstance(value, Expression): return value return _Literal(value)
26,160
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
save_eval
(filter, record)
158
162
def save_eval(filter, record): try: return filter.__eval__(record) except UndefinedError as e: return Undefined(e.message)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L158-L162
40
[ 0, 1, 2 ]
60
[ 3, 4 ]
40
false
89.992532
5
2
60
0
def save_eval(filter, record): try: return filter.__eval__(record) except UndefinedError as e: return Undefined(e.message)
26,161
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
siblings_resolver
(node, url_path)
return node.get_siblings()
547
548
def siblings_resolver(node, url_path): return node.get_siblings()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L547-L548
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def siblings_resolver(node, url_path): return node.get_siblings()
26,162
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
require_ffmpeg
(f)
return wrapper
Decorator to help with error messages for ffmpeg template functions.
Decorator to help with error messages for ffmpeg template functions.
860
873
def require_ffmpeg(f): """Decorator to help with error messages for ffmpeg template functions.""" # If both ffmpeg and ffprobe executables are available we don't need to # override the function if locate_executable("ffmpeg") and locate_executable("ffprobe"): return f @functools.wraps(f) def wrapper(*args, **kwargs): return Undefined( "Unable to locate ffmpeg or ffprobe executable. Is it installed?" ) return wrapper
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L860-L873
40
[ 0, 1, 2, 3, 4, 5, 6 ]
50
[ 7, 8, 9, 13 ]
28.571429
false
89.992532
14
4
71.428571
1
def require_ffmpeg(f): # If both ffmpeg and ffprobe executables are available we don't need to # override the function if locate_executable("ffmpeg") and locate_executable("ffprobe"): return f @functools.wraps(f) def wrapper(*args, **kwargs): return Undefined( "Unable to locate ffmpeg or ffprobe executable. Is it installed?" ) return wrapper
26,163
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_iter_filename_choices
(fn_base, alts, config, fallback=True)
Returns an iterator over all possible filename choices to .lr files below a base filename that matches any of the given alts.
Returns an iterator over all possible filename choices to .lr files below a base filename that matches any of the given alts.
1,253
1,272
def _iter_filename_choices(fn_base, alts, config, fallback=True): """Returns an iterator over all possible filename choices to .lr files below a base filename that matches any of the given alts. """ # the order here is important as attachments can exist without a .lr # file and as such need to come second or the loading of raw data will # implicitly say the record exists. for alt in alts: if alt != PRIMARY_ALT and config.is_valid_alternative(alt): yield os.path.join(fn_base, "contents+%s.lr" % alt), alt, False if fallback or PRIMARY_ALT in alts: yield os.path.join(fn_base, "contents.lr"), PRIMARY_ALT, False for alt in alts: if alt != PRIMARY_ALT and config.is_valid_alternative(alt): yield fn_base + "+%s.lr" % alt, alt, True if fallback or PRIMARY_ALT in alts: yield fn_base + ".lr", PRIMARY_ALT, True
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1253-L1272
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
100
[]
0
true
89.992532
20
11
100
2
def _iter_filename_choices(fn_base, alts, config, fallback=True): # the order here is important as attachments can exist without a .lr # file and as such need to come second or the loading of raw data will # implicitly say the record exists. for alt in alts: if alt != PRIMARY_ALT and config.is_valid_alternative(alt): yield os.path.join(fn_base, "contents+%s.lr" % alt), alt, False if fallback or PRIMARY_ALT in alts: yield os.path.join(fn_base, "contents.lr"), PRIMARY_ALT, False for alt in alts: if alt != PRIMARY_ALT and config.is_valid_alternative(alt): yield fn_base + "+%s.lr" % alt, alt, True if fallback or PRIMARY_ALT in alts: yield fn_base + ".lr", PRIMARY_ALT, True
26,164
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_iter_content_files
(dir_path, alts)
Returns an iterator over all existing content files below the given directory. This yields specific files for alts before it falls back to the primary alt.
Returns an iterator over all existing content files below the given directory. This yields specific files for alts before it falls back to the primary alt.
1,275
1,286
def _iter_content_files(dir_path, alts): """Returns an iterator over all existing content files below the given directory. This yields specific files for alts before it falls back to the primary alt. """ for alt in alts: if alt == PRIMARY_ALT: continue if os.path.isfile(os.path.join(dir_path, "contents+%s.lr" % alt)): yield alt if os.path.isfile(os.path.join(dir_path, "contents.lr")): yield PRIMARY_ALT
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1275-L1286
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
89.992532
12
5
100
3
def _iter_content_files(dir_path, alts): for alt in alts: if alt == PRIMARY_ALT: continue if os.path.isfile(os.path.join(dir_path, "contents+%s.lr" % alt)): yield alt if os.path.isfile(os.path.join(dir_path, "contents.lr")): yield PRIMARY_ALT
26,165
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_iter_datamodel_choices
(datamodel_name, path, is_attachment=False)
1,289
1,294
def _iter_datamodel_choices(datamodel_name, path, is_attachment=False): yield datamodel_name if not is_attachment: yield posixpath.basename(path).split(".")[0].replace("-", "_").lower() yield "page" yield "none"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1289-L1294
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
89.992532
6
2
100
0
def _iter_datamodel_choices(datamodel_name, path, is_attachment=False): yield datamodel_name if not is_attachment: yield posixpath.basename(path).split(".")[0].replace("-", "_").lower() yield "page" yield "none"
26,166
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
get_default_slug
(record)
return parent.datamodel.get_default_child_slug(record.pad, record)
Compute the default slug for a page. This computes the default value of ``_slug`` for a page. The slug is computed by expanding the parent’s ``slug_format`` value.
Compute the default slug for a page.
1,297
1,307
def get_default_slug(record): """Compute the default slug for a page. This computes the default value of ``_slug`` for a page. The slug is computed by expanding the parent’s ``slug_format`` value. """ parent = getattr(record, "parent", None) if parent is None: return "" return parent.datamodel.get_default_child_slug(record.pad, record)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1297-L1307
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.992532
11
2
100
4
def get_default_slug(record): parent = getattr(record, "parent", None) if parent is None: return "" return parent.datamodel.get_default_child_slug(record.pad, record)
26,167
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_split_alt_from_url
(config, clean_path)
return None, None
1,571
1,596
def _split_alt_from_url(config, clean_path): primary = config.primary_alternative # The alternative system is not configured, just return if primary is None: return None, clean_path # First try to find alternatives that are identified by a prefix. for prefix, alt in config.get_alternative_url_prefixes(): if clean_path.startswith(prefix): return alt, clean_path[len(prefix) :].strip("/") # Special case which is the URL root. if prefix.strip("/") == clean_path: return alt, "" # Now find alternatives that are identified by a suffix. for suffix, alt in config.get_alternative_url_suffixes(): if clean_path.endswith(suffix): return alt, clean_path[: -len(suffix)].strip("/") # If we have a primary alternative without a prefix and suffix, we can # return that one. if config.primary_alternative_is_rooted: return None, clean_path return None, None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1571-L1596
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 21, 22, 23, 24 ]
80.769231
[ 17, 18, 25 ]
11.538462
false
89.992532
26
8
88.461538
0
def _split_alt_from_url(config, clean_path): primary = config.primary_alternative # The alternative system is not configured, just return if primary is None: return None, clean_path # First try to find alternatives that are identified by a prefix. for prefix, alt in config.get_alternative_url_prefixes(): if clean_path.startswith(prefix): return alt, clean_path[len(prefix) :].strip("/") # Special case which is the URL root. if prefix.strip("/") == clean_path: return alt, "" # Now find alternatives that are identified by a suffix. for suffix, alt in config.get_alternative_url_suffixes(): if clean_path.endswith(suffix): return alt, clean_path[: -len(suffix)].strip("/") # If we have a primary alternative without a prefix and suffix, we can # return that one. if config.primary_alternative_is_rooted: return None, clean_path return None, None
26,168
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__init__
(self, value, reverse)
95
97
def __init__(self, value, reverse): self.value = value self.reverse = reverse
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L95-L97
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
0
def __init__(self, value, reverse): self.value = value self.reverse = reverse
26,169
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.coerce
(a, b)
return a, b
100
121
def coerce(a, b): if isinstance(a, str) and isinstance(b, str): return sort_normalize_string(a), sort_normalize_string(b) if type(a) is type(b): return a, b if isinstance(a, Undefined) or isinstance(b, Undefined): if isinstance(a, Undefined): a = None if isinstance(b, Undefined): b = None return a, b if isinstance(a, (int, float)): try: return a, type(a)(b) except (ValueError, TypeError, OverflowError): pass if isinstance(b, (int, float)): try: return type(b)(a), b except (ValueError, TypeError, OverflowError): pass return a, b
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L100-L121
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 21 ]
81.818182
[ 17, 18, 19, 20 ]
18.181818
false
89.992532
22
12
81.818182
0
def coerce(a, b): if isinstance(a, str) and isinstance(b, str): return sort_normalize_string(a), sort_normalize_string(b) if type(a) is type(b): return a, b if isinstance(a, Undefined) or isinstance(b, Undefined): if isinstance(a, Undefined): a = None if isinstance(b, Undefined): b = None return a, b if isinstance(a, (int, float)): try: return a, type(a)(b) except (ValueError, TypeError, OverflowError): pass if isinstance(b, (int, float)): try: return type(b)(a), b except (ValueError, TypeError, OverflowError): pass return a, b
26,170
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__eq__
(self, other)
return a == b
123
125
def __eq__(self, other): a, b = self.coerce(self.value, other.value) return a == b
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L123-L125
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
0
def __eq__(self, other): a, b = self.coerce(self.value, other.value) return a == b
26,171
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__ne__
(self, other)
return not self.__eq__(other)
127
128
def __ne__(self, other): return not self.__eq__(other)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L127-L128
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __ne__(self, other): return not self.__eq__(other)
26,172
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__lt__
(self, other)
130
140
def __lt__(self, other): a, b = self.coerce(self.value, other.value) try: if self.reverse: return b < a return a < b except TypeError: # Put None at the beginning if reversed, else at the end. if self.reverse: return a is not None return a is None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L130-L140
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.992532
11
4
100
0
def __lt__(self, other): a, b = self.coerce(self.value, other.value) try: if self.reverse: return b < a return a < b except TypeError: # Put None at the beginning if reversed, else at the end. if self.reverse: return a is not None return a is None
26,173
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__gt__
(self, other)
return not (self.__lt__(other) or self.__eq__(other))
142
143
def __gt__(self, other): return not (self.__lt__(other) or self.__eq__(other))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L142-L143
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
2
50
0
def __gt__(self, other): return not (self.__lt__(other) or self.__eq__(other))
26,174
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__le__
(self, other)
return self.__lt__(other) or self.__eq__(other)
145
146
def __le__(self, other): return self.__lt__(other) or self.__eq__(other)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L145-L146
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
2
50
0
def __le__(self, other): return self.__lt__(other) or self.__eq__(other)
26,175
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CmpHelper.__ge__
(self, other)
return not self.__lt__(other)
148
149
def __ge__(self, other): return not self.__lt__(other)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L148-L149
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __ge__(self, other): return not self.__lt__(other)
26,176
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__eval__
(self, record)
return record
166
168
def __eval__(self, record): # pylint: disable=no-self-use return record
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L166-L168
40
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
89.992532
3
1
66.666667
0
def __eval__(self, record): # pylint: disable=no-self-use return record
26,177
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__eq__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.eq)
170
171
def __eq__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.eq)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L170-L171
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __eq__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.eq)
26,178
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__ne__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.ne)
173
174
def __ne__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.ne)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L173-L174
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __ne__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.ne)
26,179
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__and__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.and_)
176
177
def __and__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.and_)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L176-L177
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __and__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.and_)
26,180
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__or__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.or_)
179
180
def __or__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.or_)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L179-L180
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __or__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.or_)
26,181
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__gt__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.gt)
182
183
def __gt__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.gt)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L182-L183
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __gt__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.gt)
26,182
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__ge__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.ge)
185
186
def __ge__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.ge)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L185-L186
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __ge__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.ge)
26,183
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__lt__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.lt)
188
189
def __lt__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.lt)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L188-L189
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __lt__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.lt)
26,184
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.__le__
(self, other)
return _BinExpr(self, _auto_wrap_expr(other), operator.le)
191
192
def __le__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.le)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L191-L192
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __le__(self, other): return _BinExpr(self, _auto_wrap_expr(other), operator.le)
26,185
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.contains
(self, item)
return _ContainmentExpr(self, _auto_wrap_expr(item))
194
195
def contains(self, item): return _ContainmentExpr(self, _auto_wrap_expr(item))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L194-L195
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def contains(self, item): return _ContainmentExpr(self, _auto_wrap_expr(item))
26,186
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.startswith
(self, other)
return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).lower().startswith(str(b).lower()), )
197
202
def startswith(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).lower().startswith(str(b).lower()), )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L197-L202
40
[ 0 ]
16.666667
[ 1 ]
16.666667
false
89.992532
6
1
83.333333
0
def startswith(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).lower().startswith(str(b).lower()), )
26,187
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.endswith
(self, other)
return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).lower().endswith(str(b).lower()), )
204
209
def endswith(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).lower().endswith(str(b).lower()), )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L204-L209
40
[ 0 ]
16.666667
[ 1 ]
16.666667
false
89.992532
6
1
83.333333
0
def endswith(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).lower().endswith(str(b).lower()), )
26,188
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.startswith_cs
(self, other)
return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).startswith(str(b)), )
211
216
def startswith_cs(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).startswith(str(b)), )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L211-L216
40
[ 0 ]
16.666667
[ 1 ]
16.666667
false
89.992532
6
1
83.333333
0
def startswith_cs(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).startswith(str(b)), )
26,189
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.endswith_cs
(self, other)
return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).endswith(str(b)), )
218
223
def endswith_cs(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).endswith(str(b)), )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L218-L223
40
[ 0 ]
16.666667
[ 1 ]
16.666667
false
89.992532
6
1
83.333333
0
def endswith_cs(self, other): return _BinExpr( self, _auto_wrap_expr(other), lambda a, b: str(a).endswith(str(b)), )
26,190
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.false
(self)
return _IsBoolExpr(self, False)
225
226
def false(self): return _IsBoolExpr(self, False)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L225-L226
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def false(self): return _IsBoolExpr(self, False)
26,191
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Expression.true
(self)
return _IsBoolExpr(self, True)
228
229
def true(self): return _IsBoolExpr(self, True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L228-L229
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def true(self): return _IsBoolExpr(self, True)
26,192
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CallbackExpr.__init__
(self, func)
238
239
def __init__(self, func): self.func = func
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L238-L239
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __init__(self, func): self.func = func
26,193
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_CallbackExpr.__eval__
(self, record)
return self.func(record)
241
242
def __eval__(self, record): return self.func(record)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L241-L242
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def __eval__(self, record): return self.func(record)
26,194
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_IsBoolExpr.__init__
(self, expr, true)
246
248
def __init__(self, expr, true): self.__expr = expr self.__true = true
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L246-L248
40
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
89.992532
3
1
33.333333
0
def __init__(self, expr, true): self.__expr = expr self.__true = true
26,195
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_IsBoolExpr.__eval__
(self, record)
return ( not is_undefined(val) and val not in (None, 0, False, "") ) == self.__true
250
254
def __eval__(self, record): val = self.__expr.__eval__(record) return ( not is_undefined(val) and val not in (None, 0, False, "") ) == self.__true
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L250-L254
40
[ 0 ]
20
[ 1, 2 ]
40
false
89.992532
5
2
60
0
def __eval__(self, record): val = self.__expr.__eval__(record) return ( not is_undefined(val) and val not in (None, 0, False, "") ) == self.__true
26,196
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_Literal.__init__
(self, value)
258
259
def __init__(self, value): self.__value = value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L258-L259
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __init__(self, value): self.__value = value
26,197
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_Literal.__eval__
(self, record)
return self.__value
261
262
def __eval__(self, record): return self.__value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L261-L262
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __eval__(self, record): return self.__value
26,198
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_BinExpr.__init__
(self, left, right, op)
266
269
def __init__(self, left, right, op): self.__left = left self.__right = right self.__op = op
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L266-L269
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
0
def __init__(self, left, right, op): self.__left = left self.__right = right self.__op = op
26,199
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_BinExpr.__eval__
(self, record)
return self.__op(self.__left.__eval__(record), self.__right.__eval__(record))
271
272
def __eval__(self, record): return self.__op(self.__left.__eval__(record), self.__right.__eval__(record))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L271-L272
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __eval__(self, record): return self.__op(self.__left.__eval__(record), self.__right.__eval__(record))
26,200
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_ContainmentExpr.__init__
(self, seq, item)
276
278
def __init__(self, seq, item): self.__seq = seq self.__item = item
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L276-L278
40
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
89.992532
3
1
33.333333
0
def __init__(self, seq, item): self.__seq = seq self.__item = item
26,201
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_ContainmentExpr.__eval__
(self, record)
return item in seq
280
285
def __eval__(self, record): seq = self.__seq.__eval__(record) item = self.__item.__eval__(record) if isinstance(item, Record): item = item["_id"] return item in seq
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L280-L285
40
[ 0 ]
16.666667
[ 1, 2, 3, 4, 5 ]
83.333333
false
89.992532
6
2
16.666667
0
def __eval__(self, record): seq = self.__seq.__eval__(record) item = self.__item.__eval__(record) if isinstance(item, Record): item = item["_id"] return item in seq
26,202
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_RecordQueryField.__init__
(self, field)
289
290
def __init__(self, field): self.__field = field
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L289-L290
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
1
100
0
def __init__(self, field): self.__field = field
26,203
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_RecordQueryField.__eval__
(self, record)
292
296
def __eval__(self, record): try: return record[self.__field] except KeyError: return Undefined(obj=record, name=self.__field)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L292-L296
40
[ 0, 1, 2 ]
60
[ 3, 4 ]
40
false
89.992532
5
2
60
0
def __eval__(self, record): try: return record[self.__field] except KeyError: return Undefined(obj=record, name=self.__field)
26,204
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_RecordQueryProxy.__getattr__
(self, name)
300
303
def __getattr__(self, name): if name[:2] != "__": return _RecordQueryField(name) raise AttributeError(name)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L300-L303
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
2
100
0
def __getattr__(self, name): if name[:2] != "__": return _RecordQueryField(name) raise AttributeError(name)
26,205
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
_RecordQueryProxy.__getitem__
(self, name)
305
309
def __getitem__(self, name): try: return self.__getattr__(name) except AttributeError as error: raise KeyError(name) from error
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L305-L309
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
89.992532
5
2
20
0
def __getitem__(self, name): try: return self.__getattr__(name) except AttributeError as error: raise KeyError(name) from error
26,206
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record.__init__
(self, pad, data, page_num=None)
319
327
def __init__(self, pad, data, page_num=None): SourceObject.__init__(self, pad) self._data = data self._bound_data = {} if page_num is not None and not self.supports_pagination: raise RuntimeError( "%s does not support pagination" % self.__class__.__name__ ) self.page_num = page_num
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L319-L327
40
[ 0, 1, 2, 3, 4, 8 ]
66.666667
[ 5 ]
11.111111
false
89.992532
9
3
88.888889
0
def __init__(self, pad, data, page_num=None): SourceObject.__init__(self, pad) self._data = data self._bound_data = {} if page_num is not None and not self.supports_pagination: raise RuntimeError( "%s does not support pagination" % self.__class__.__name__ ) self.page_num = page_num
26,207
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record.record
(self)
return self
330
331
def record(self): return self
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L330-L331
40
[ 0 ]
50
[ 1 ]
50
false
89.992532
2
1
50
0
def record(self): return self
26,208
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record.datamodel
(self)
Returns the data model for this record.
Returns the data model for this record.
334
340
def datamodel(self): """Returns the data model for this record.""" try: return self.pad.db.datamodels[self._data["_model"]] except LookupError: # If we cannot find the model we fall back to the default one. return self.pad.db.default_model
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L334-L340
40
[ 0, 1, 2, 3 ]
57.142857
[ 4, 6 ]
28.571429
false
89.992532
7
2
71.428571
1
def datamodel(self): try: return self.pad.db.datamodels[self._data["_model"]] except LookupError: # If we cannot find the model we fall back to the default one. return self.pad.db.default_model
26,209
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record.alt
(self)
return self["_alt"]
Returns the alt of this source object.
Returns the alt of this source object.
343
345
def alt(self): """Returns the alt of this source object.""" return self["_alt"]
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L343-L345
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
1
def alt(self): return self["_alt"]
26,210
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record.is_hidden
(self)
return self._is_considered_hidden()
Indicates if a record is hidden. A record is considered hidden if the record itself is hidden or the parent is.
Indicates if a record is hidden. A record is considered hidden if the record itself is hidden or the parent is.
348
354
def is_hidden(self): """Indicates if a record is hidden. A record is considered hidden if the record itself is hidden or the parent is. """ if not is_undefined(self._data["_hidden"]): return self._data["_hidden"] return self._is_considered_hidden()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L348-L354
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
89.992532
7
2
100
2
def is_hidden(self): if not is_undefined(self._data["_hidden"]): return self._data["_hidden"] return self._is_considered_hidden()
26,211
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record._is_considered_hidden
(self)
return parent.is_hidden
356
364
def _is_considered_hidden(self): parent = self.parent if parent is None: return False hidden_children = parent.datamodel.child_config.hidden if hidden_children is not None: return hidden_children return parent.is_hidden
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L356-L364
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
89.992532
9
3
100
0
def _is_considered_hidden(self): parent = self.parent if parent is None: return False hidden_children = parent.datamodel.child_config.hidden if hidden_children is not None: return hidden_children return parent.is_hidden
26,212
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Record.is_discoverable
(self)
return self._data["_discoverable"] and not self.is_hidden
Indicates if the page is discoverable without knowing the URL.
Indicates if the page is discoverable without knowing the URL.
367
369
def is_discoverable(self): """Indicates if the page is discoverable without knowing the URL.""" return self._data["_discoverable"] and not self.is_hidden
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L367-L369
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
2
100
1
def is_discoverable(self): return self._data["_discoverable"] and not self.is_hidden
26,213