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/db.py
Database.get_record_class
(datamodel, raw_data)
return attachment_classes.get(attachment_type, Attachment)
Returns the appropriate record class for a datamodel and raw data.
Returns the appropriate record class for a datamodel and raw data.
1,558
1,564
def get_record_class(datamodel, raw_data): """Returns the appropriate record class for a datamodel and raw data.""" is_attachment = bool(raw_data.get("_attachment_for")) if not is_attachment: return Page attachment_type = raw_data["_attachment_type"] return attachment_classes.get(attachment_type, Attachment)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1558-L1564
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
89.992532
7
2
100
1
def get_record_class(datamodel, raw_data): is_attachment = bool(raw_data.get("_attachment_for")) if not is_attachment: return Page attachment_type = raw_data["_attachment_type"] return attachment_classes.get(attachment_type, Attachment)
26,314
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Database.new_pad
(self)
return Pad(self)
Creates a new pad object for this database.
Creates a new pad object for this database.
1,566
1,568
def new_pad(self): """Creates a new pad object for this database.""" return Pad(self)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1566-L1568
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
1
def new_pad(self): return Pad(self)
26,315
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.__init__
(self, db)
1,600
1,603
def __init__(self, db): self.db = db self.cache = RecordCache(db.config["EPHEMERAL_RECORD_CACHE_SIZE"]) self.databags = Databags(db.env)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1600-L1603
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
0
def __init__(self, db): self.db = db self.cache = RecordCache(db.config["EPHEMERAL_RECORD_CACHE_SIZE"]) self.databags = Databags(db.env)
26,316
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.config
(self)
return self.db.config
The config for this pad.
The config for this pad.
1,606
1,608
def config(self): """The config for this pad.""" return self.db.config
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1606-L1608
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
1
def config(self): return self.db.config
26,317
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.env
(self)
return self.db.env
The env for this pad.
The env for this pad.
1,611
1,613
def env(self): """The env for this pad.""" return self.db.env
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1611-L1613
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
1
def env(self): return self.db.env
26,318
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.make_absolute_url
(self, url)
return url_join(base_url.rstrip("/") + "/", url.lstrip("/"))
Given a URL this makes it absolute if this is possible.
Given a URL this makes it absolute if this is possible.
1,615
1,623
def make_absolute_url(self, url): """Given a URL this makes it absolute if this is possible.""" base_url = self.db.config["PROJECT"].get("url") if base_url is None: raise RuntimeError( "To use absolute URLs you need to configure " "the URL in the project config." ) return url_join(base_url.rstrip("/") + "/", url.lstrip("/"))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1615-L1623
40
[ 0, 1 ]
22.222222
[ 2, 3, 4, 8 ]
44.444444
false
89.992532
9
2
55.555556
1
def make_absolute_url(self, url): base_url = self.db.config["PROJECT"].get("url") if base_url is None: raise RuntimeError( "To use absolute URLs you need to configure " "the URL in the project config." ) return url_join(base_url.rstrip("/") + "/", url.lstrip("/"))
26,319
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.make_url
(self, url, base_url=None, absolute=None, external=None)
return make_relative_url(base_url, url)
Helper method that creates a finalized URL based on the parameters provided and the config. :param url: URL path (starting with "/") relative to the configured base_path. :param base_url: Base URL path (starting with "/") relative to the configured base_path.
Helper method that creates a finalized URL based on the parameters provided and the config.
1,625
1,655
def make_url(self, url, base_url=None, absolute=None, external=None): """Helper method that creates a finalized URL based on the parameters provided and the config. :param url: URL path (starting with "/") relative to the configured base_path. :param base_url: Base URL path (starting with "/") relative to the configured base_path. """ url_style = self.db.config.url_style if absolute is None: absolute = url_style == "absolute" if external is None: external = url_style == "external" if external: external_base_url = self.db.config.base_url if external_base_url is None: raise RuntimeError( "To use absolute URLs you need to " "configure the URL in the project config." ) return url_join(external_base_url, url.lstrip("/")) if absolute: return url_join(self.db.config.base_path, url.lstrip("/")) if base_url is None: raise RuntimeError( "Cannot calculate a relative URL if no base URL has been provided." ) return make_relative_url(base_url, url)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1625-L1655
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, 29, 30 ]
93.548387
[ 27 ]
3.225806
false
89.992532
31
7
96.774194
8
def make_url(self, url, base_url=None, absolute=None, external=None): url_style = self.db.config.url_style if absolute is None: absolute = url_style == "absolute" if external is None: external = url_style == "external" if external: external_base_url = self.db.config.base_url if external_base_url is None: raise RuntimeError( "To use absolute URLs you need to " "configure the URL in the project config." ) return url_join(external_base_url, url.lstrip("/")) if absolute: return url_join(self.db.config.base_path, url.lstrip("/")) if base_url is None: raise RuntimeError( "Cannot calculate a relative URL if no base URL has been provided." ) return make_relative_url(base_url, url)
26,320
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.resolve_url_path
( self, url_path, include_invisible=False, include_assets=True, alt_fallback=True )
return None
Given a URL path this will find the correct record which also might be an attachment. If a record cannot be found or is unexposed the return value will be `None`.
Given a URL path this will find the correct record which also might be an attachment. If a record cannot be found or is unexposed the return value will be `None`.
1,657
1,698
def resolve_url_path( self, url_path, include_invisible=False, include_assets=True, alt_fallback=True ): """Given a URL path this will find the correct record which also might be an attachment. If a record cannot be found or is unexposed the return value will be `None`. """ try: clean_path = cleanup_url_path(url_path).strip("/") except ValueError: return None # Split off the alt and if no alt was found, point it to the # primary alternative. If the clean path comes back as `None` # then the config does not include a rooted alternative and we # have to skip handling of regular records. alt, clean_path = _split_alt_from_url(self.db.config, clean_path) if clean_path is not None: if not alt: if alt_fallback: alt = self.db.config.primary_alternative or PRIMARY_ALT else: alt = PRIMARY_ALT node = self.get_root(alt=alt) if node is None: raise RuntimeError("Tree root could not be found.") pieces = clean_path.split("/") if pieces == [""]: pieces = [] rv = node.resolve_url_path(pieces) if rv is not None and (include_invisible or rv.is_visible): return rv if include_assets: for asset_root in [self.asset_root] + self.theme_asset_roots: rv = asset_root.resolve_url_path(pieces) if rv is not None: break return rv return None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1657-L1698
40
[ 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41 ]
85.714286
[ 25 ]
2.380952
false
89.992532
42
14
97.619048
3
def resolve_url_path( self, url_path, include_invisible=False, include_assets=True, alt_fallback=True ): try: clean_path = cleanup_url_path(url_path).strip("/") except ValueError: return None # Split off the alt and if no alt was found, point it to the # primary alternative. If the clean path comes back as `None` # then the config does not include a rooted alternative and we # have to skip handling of regular records. alt, clean_path = _split_alt_from_url(self.db.config, clean_path) if clean_path is not None: if not alt: if alt_fallback: alt = self.db.config.primary_alternative or PRIMARY_ALT else: alt = PRIMARY_ALT node = self.get_root(alt=alt) if node is None: raise RuntimeError("Tree root could not be found.") pieces = clean_path.split("/") if pieces == [""]: pieces = [] rv = node.resolve_url_path(pieces) if rv is not None and (include_invisible or rv.is_visible): return rv if include_assets: for asset_root in [self.asset_root] + self.theme_asset_roots: rv = asset_root.resolve_url_path(pieces) if rv is not None: break return rv return None
26,321
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.get_root
(self, alt=None)
return self.get("/", alt=alt, persist=True)
The root page of the database.
The root page of the database.
1,700
1,704
def get_root(self, alt=None): """The root page of the database.""" if alt is None: alt = self.config.primary_alternative or PRIMARY_ALT return self.get("/", alt=alt, persist=True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1700-L1704
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
3
100
1
def get_root(self, alt=None): if alt is None: alt = self.config.primary_alternative or PRIMARY_ALT return self.get("/", alt=alt, persist=True)
26,322
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.asset_root
(self)
return Directory( self, name="", path=os.path.join(self.db.env.root_path, "assets") )
The root of the asset tree.
The root of the asset tree.
1,709
1,713
def asset_root(self): """The root of the asset tree.""" return Directory( self, name="", path=os.path.join(self.db.env.root_path, "assets") )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1709-L1713
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
1
100
1
def asset_root(self): return Directory( self, name="", path=os.path.join(self.db.env.root_path, "assets") )
26,323
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.theme_asset_roots
(self)
return asset_roots
The root of the asset tree of each theme.
The root of the asset tree of each theme.
1,716
1,723
def theme_asset_roots(self): """The root of the asset tree of each theme.""" asset_roots = [] for theme_path in self.db.env.theme_paths: asset_roots.append( Directory(self, name="", path=os.path.join(theme_path, "assets")) ) return asset_roots
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1716-L1723
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
89.992532
8
2
100
1
def theme_asset_roots(self): asset_roots = [] for theme_path in self.db.env.theme_paths: asset_roots.append( Directory(self, name="", path=os.path.join(theme_path, "assets")) ) return asset_roots
26,324
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.get_all_roots
(self)
return rv
Returns all the roots for building.
Returns all the roots for building.
1,725
1,738
def get_all_roots(self): """Returns all the roots for building.""" rv = [] for alt in self.db.config.list_alternatives(): rv.append(self.get_root(alt=alt)) # If we don't have any alternatives, then we go with the implied # root. if not rv and self.root: rv = [self.root] rv.append(self.asset_root) rv.extend(self.theme_asset_roots) return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1725-L1738
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
89.992532
14
4
100
1
def get_all_roots(self): rv = [] for alt in self.db.config.list_alternatives(): rv.append(self.get_root(alt=alt)) # If we don't have any alternatives, then we go with the implied # root. if not rv and self.root: rv = [self.root] rv.append(self.asset_root) rv.extend(self.theme_asset_roots) return rv
26,325
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.get_virtual
(self, record, virtual_path)
return resolver(record, pieces[1:])
Resolves a virtual path below a record.
Resolves a virtual path below a record.
1,740
1,757
def get_virtual(self, record, virtual_path): """Resolves a virtual path below a record.""" pieces = virtual_path.strip("/").split("/") if not pieces or pieces == [""]: return record if pieces[0].isdigit(): if len(pieces) == 1: return self.get( record["_path"], alt=record.alt, page_num=int(pieces[0]) ) return None resolver = self.env.virtual_sources.get(pieces[0]) if resolver is None: return None return resolver(record, pieces[1:])
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1740-L1757
40
[ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 14, 16, 17 ]
83.333333
[ 4, 11, 15 ]
16.666667
false
89.992532
18
6
83.333333
1
def get_virtual(self, record, virtual_path): pieces = virtual_path.strip("/").split("/") if not pieces or pieces == [""]: return record if pieces[0].isdigit(): if len(pieces) == 1: return self.get( record["_path"], alt=record.alt, page_num=int(pieces[0]) ) return None resolver = self.env.virtual_sources.get(pieces[0]) if resolver is None: return None return resolver(record, pieces[1:])
26,326
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.get
(self, path, alt=None, page_num=None, persist=True, allow_virtual=True)
return self.db.track_record_dependency(rv)
Loads a record by path.
Loads a record by path.
1,759
1,810
def get(self, path, alt=None, page_num=None, persist=True, allow_virtual=True): """Loads a record by path.""" if alt is None: alt = self.config.primary_alternative or PRIMARY_ALT virt_markers = path.count("@") # If the virtual marker is included, we also want to look up the # virtual path below an item. Special case: if virtual paths are # not allowed but one was passed, we just return `None`. if virt_markers == 1: if page_num is not None: raise RuntimeError( "Cannot use both virtual paths and " "explicit page number lookups. You " "need to one or the other." ) if not allow_virtual: return None path, virtual_path = path.split("@", 1) rv = self.get(path, alt=alt, page_num=page_num, persist=persist) if rv is None: return None return self.get_virtual(rv, virtual_path) # Sanity check: there must only be one or things will get weird. if virt_markers > 1: return None path = cleanup_path(path) virtual_path = None if page_num is not None: virtual_path = str(page_num) rv = self.cache.get(path, alt, virtual_path) if rv is not Ellipsis: if rv is not None: self.db.track_record_dependency(rv) return rv raw_data = self.db.load_raw_data(path, alt=alt) if raw_data is None: self.cache.remember_as_missing(path, alt, virtual_path) return None rv = self.instance_from_data(raw_data, page_num=page_num) if persist: self.cache.persist(rv) else: self.cache.remember(rv) return self.db.track_record_dependency(rv)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1759-L1810
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 18, 19, 20, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 ]
86.538462
[ 11, 17, 21, 26 ]
7.692308
false
89.992532
52
13
92.307692
1
def get(self, path, alt=None, page_num=None, persist=True, allow_virtual=True): if alt is None: alt = self.config.primary_alternative or PRIMARY_ALT virt_markers = path.count("@") # If the virtual marker is included, we also want to look up the # virtual path below an item. Special case: if virtual paths are # not allowed but one was passed, we just return `None`. if virt_markers == 1: if page_num is not None: raise RuntimeError( "Cannot use both virtual paths and " "explicit page number lookups. You " "need to one or the other." ) if not allow_virtual: return None path, virtual_path = path.split("@", 1) rv = self.get(path, alt=alt, page_num=page_num, persist=persist) if rv is None: return None return self.get_virtual(rv, virtual_path) # Sanity check: there must only be one or things will get weird. if virt_markers > 1: return None path = cleanup_path(path) virtual_path = None if page_num is not None: virtual_path = str(page_num) rv = self.cache.get(path, alt, virtual_path) if rv is not Ellipsis: if rv is not None: self.db.track_record_dependency(rv) return rv raw_data = self.db.load_raw_data(path, alt=alt) if raw_data is None: self.cache.remember_as_missing(path, alt, virtual_path) return None rv = self.instance_from_data(raw_data, page_num=page_num) if persist: self.cache.persist(rv) else: self.cache.remember(rv) return self.db.track_record_dependency(rv)
26,327
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.alt_exists
(self, path, alt=PRIMARY_ALT, fallback=False)
return False
Checks if an alt exists.
Checks if an alt exists.
1,812
1,831
def alt_exists(self, path, alt=PRIMARY_ALT, fallback=False): """Checks if an alt exists.""" path = cleanup_path(path) if "@" in path: return False # If we find the path in the cache, check if it was loaded from # the right source alt. rv = self.get(path, alt) if rv is not None: if rv["_source_alt"] == alt: return True if fallback or ( rv["_source_alt"] == PRIMARY_ALT and alt == self.config.primary_alternative ): return True return False return False
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1812-L1831
40
[ 0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
80
[ 4, 19 ]
10
false
89.992532
20
7
90
1
def alt_exists(self, path, alt=PRIMARY_ALT, fallback=False): path = cleanup_path(path) if "@" in path: return False # If we find the path in the cache, check if it was loaded from # the right source alt. rv = self.get(path, alt) if rv is not None: if rv["_source_alt"] == alt: return True if fallback or ( rv["_source_alt"] == PRIMARY_ALT and alt == self.config.primary_alternative ): return True return False return False
26,328
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.get_asset
(self, path)
return None
Loads an asset by path.
Loads an asset by path.
1,833
1,844
def get_asset(self, path): """Loads an asset by path.""" clean_path = cleanup_path(path).strip("/") nodes = [self.asset_root] + self.theme_asset_roots for node in nodes: for piece in clean_path.split("/"): node = node.get_child(piece) if node is None: break if node is not None: return node return None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1833-L1844
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
91.666667
[ 11 ]
8.333333
false
89.992532
12
5
91.666667
1
def get_asset(self, path): clean_path = cleanup_path(path).strip("/") nodes = [self.asset_root] + self.theme_asset_roots for node in nodes: for piece in clean_path.split("/"): node = node.get_child(piece) if node is None: break if node is not None: return node return None
26,329
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.instance_from_data
(self, raw_data, datamodel=None, page_num=None)
return cls(self, data, page_num=page_num)
This creates an instance from the given raw data.
This creates an instance from the given raw data.
1,846
1,853
def instance_from_data(self, raw_data, datamodel=None, page_num=None): """This creates an instance from the given raw data.""" if datamodel is None: datamodel = self.db.get_datamodel_for_raw_data(raw_data, self) data = datamodel.process_raw_data(raw_data, self) self.db.process_data(data, datamodel, self) cls = self.db.get_record_class(datamodel, data) return cls(self, data, page_num=page_num)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1846-L1853
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
89.992532
8
2
100
1
def instance_from_data(self, raw_data, datamodel=None, page_num=None): if datamodel is None: datamodel = self.db.get_datamodel_for_raw_data(raw_data, self) data = datamodel.process_raw_data(raw_data, self) self.db.process_data(data, datamodel, self) cls = self.db.get_record_class(datamodel, data) return cls(self, data, page_num=page_num)
26,330
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Pad.query
(self, path=None, alt=PRIMARY_ALT)
return Query( path="/" + (path or "").strip("/"), pad=self, alt=alt ).include_hidden(True)
Queries the database either at root level or below a certain path. This is the recommended way to interact with toplevel data. The alternative is to work with the :attr:`root` document.
Queries the database either at root level or below a certain path. This is the recommended way to interact with toplevel data. The alternative is to work with the :attr:`root` document.
1,855
1,866
def query(self, path=None, alt=PRIMARY_ALT): """Queries the database either at root level or below a certain path. This is the recommended way to interact with toplevel data. The alternative is to work with the :attr:`root` document. """ # Don't accidentally pass `None` down to the query as this might # do some unexpected things. if alt is None: alt = PRIMARY_ALT return Query( path="/" + (path or "").strip("/"), pad=self, alt=alt ).include_hidden(True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1855-L1866
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11 ]
91.666667
[ 8 ]
8.333333
false
89.992532
12
3
91.666667
3
def query(self, path=None, alt=PRIMARY_ALT): # Don't accidentally pass `None` down to the query as this might # do some unexpected things. if alt is None: alt = PRIMARY_ALT return Query( path="/" + (path or "").strip("/"), pad=self, alt=alt ).include_hidden(True)
26,331
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.__init__
(self, tree, path, alts, primary_record)
1,872
1,876
def __init__(self, tree, path, alts, primary_record): self.tree = tree self.path = path self.alts = alts self._primary_record = primary_record
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1872-L1876
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
1
100
0
def __init__(self, tree, path, alts, primary_record): self.tree = tree self.path = path self.alts = alts self._primary_record = primary_record
26,332
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.id
(self)
return posixpath.basename(self.path)
The local ID of the item.
The local ID of the item.
1,879
1,881
def id(self): """The local ID of the item.""" return posixpath.basename(self.path)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1879-L1881
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
1
def id(self): return posixpath.basename(self.path)
26,333
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.exists
(self)
return self._primary_record is not None
True iff metadata exists for the item. If metadata exists for any alt, including the fallback (PRIMARY_ALT). Note that for attachments without metadata, this is currently False. But note that if is_attachment is True, the attachment file does exist.
True iff metadata exists for the item.
1,884
1,894
def exists(self): """True iff metadata exists for the item. If metadata exists for any alt, including the fallback (PRIMARY_ALT). Note that for attachments without metadata, this is currently False. But note that if is_attachment is True, the attachment file does exist. """ # FIXME: this should probably be changed to return True for attachments, # even those without metadata. return self._primary_record is not None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1884-L1894
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.992532
11
1
100
6
def exists(self): # FIXME: this should probably be changed to return True for attachments, # even those without metadata. return self._primary_record is not None
26,334
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.is_attachment
(self)
return self._primary_record.is_attachment
True iff item is an attachment.
True iff item is an attachment.
1,897
1,901
def is_attachment(self): """True iff item is an attachment.""" if self._primary_record is None: return False return self._primary_record.is_attachment
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1897-L1901
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
2
100
1
def is_attachment(self): if self._primary_record is None: return False return self._primary_record.is_attachment
26,335
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.is_visible
(self)
return self._primary_record.is_visible
True iff item is not hidden.
True iff item is not hidden.
1,904
1,910
def is_visible(self): """True iff item is not hidden.""" # XXX: This is send out from /api/recordinfo but appears to be # unused by the React app if self._primary_record is None: return True return self._primary_record.is_visible
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1904-L1910
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
89.992532
7
2
100
1
def is_visible(self): # XXX: This is send out from /api/recordinfo but appears to be # unused by the React app if self._primary_record is None: return True return self._primary_record.is_visible
26,336
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.can_be_deleted
(self)
return self.is_attachment or not self._datamodel.protected
True iff item can be deleted.
True iff item can be deleted.
1,913
1,917
def can_be_deleted(self): """True iff item can be deleted.""" if self.path == "/" or not self.exists: return False return self.is_attachment or not self._datamodel.protected
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1913-L1917
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
4
100
1
def can_be_deleted(self): if self.path == "/" or not self.exists: return False return self.is_attachment or not self._datamodel.protected
26,337
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem._datamodel
(self)
return self._primary_record.datamodel
1,920
1,923
def _datamodel(self): if self._primary_record is None: return None return self._primary_record.datamodel
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1920-L1923
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
2
100
0
def _datamodel(self): if self._primary_record is None: return None return self._primary_record.datamodel
26,338
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.get_record_label_i18n
(self, alt=PRIMARY_ALT)
return record.get_record_label_i18n()
Get record label translations for specific alt.
Get record label translations for specific alt.
1,925
1,933
def get_record_label_i18n(self, alt=PRIMARY_ALT): """Get record label translations for specific alt.""" record = self.alts[alt].record if record is None: # generate a reasonable fallback # ("en" is the magical fallback lang) label = self.id.replace("-", " ").replace("_", " ").title() return {"en": label or "(Index)"} return record.get_record_label_i18n()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1925-L1933
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
89.992532
9
3
100
1
def get_record_label_i18n(self, alt=PRIMARY_ALT): record = self.alts[alt].record if record is None: # generate a reasonable fallback # ("en" is the magical fallback lang) label = self.id.replace("-", " ").replace("_", " ").title() return {"en": label or "(Index)"} return record.get_record_label_i18n()
26,339
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.can_have_children
(self)
return self._datamodel.has_own_children
True iff the item can contain subpages.
True iff the item can contain subpages.
1,936
1,940
def can_have_children(self): """True iff the item can contain subpages.""" if self._primary_record is None or self.is_attachment: return False return self._datamodel.has_own_children
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1936-L1940
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
3
100
1
def can_have_children(self): if self._primary_record is None or self.is_attachment: return False return self._datamodel.has_own_children
26,340
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.implied_child_datamodel
(self)
return datamodel.child_config.model if datamodel else None
The name of the default datamodel for children of this page, if any.
The name of the default datamodel for children of this page, if any.
1,943
1,946
def implied_child_datamodel(self): """The name of the default datamodel for children of this page, if any.""" datamodel = self._datamodel return datamodel.child_config.model if datamodel else None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1943-L1946
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
1
def implied_child_datamodel(self): datamodel = self._datamodel return datamodel.child_config.model if datamodel else None
26,341
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.can_have_attachments
(self)
return self._datamodel.has_own_attachments
True iff the item can contain attachments.
True iff the item can contain attachments.
1,949
1,953
def can_have_attachments(self): """True iff the item can contain attachments.""" if self._primary_record is None or self.is_attachment: return False return self._datamodel.has_own_attachments
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1949-L1953
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
3
100
1
def can_have_attachments(self): if self._primary_record is None or self.is_attachment: return False return self._datamodel.has_own_attachments
26,342
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.attachment_type
(self)
return self._primary_record["_attachment_type"] or None
The type of an attachment. E.g. "image", "video", or None if type is unknown.
The type of an attachment.
1,956
1,963
def attachment_type(self): """The type of an attachment. E.g. "image", "video", or None if type is unknown. """ if self._primary_record is None or not self.is_attachment: return None return self._primary_record["_attachment_type"] or None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1956-L1963
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
89.992532
8
4
100
3
def attachment_type(self): if self._primary_record is None or not self.is_attachment: return None return self._primary_record["_attachment_type"] or None
26,343
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.get_parent
(self)
return self.tree.get(posixpath.dirname(self.path))
Returns the parent item.
Returns the parent item.
1,965
1,969
def get_parent(self): """Returns the parent item.""" if self.path == "/": return None return self.tree.get(posixpath.dirname(self.path))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1965-L1969
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
2
100
1
def get_parent(self): if self.path == "/": return None return self.tree.get(posixpath.dirname(self.path))
26,344
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.get
(self, path)
return self.tree.get(posixpath.join(self.path, path))
Returns a child within this item.
Returns a child within this item.
1,971
1,974
def get(self, path): """Returns a child within this item.""" # XXX: Unused? return self.tree.get(posixpath.join(self.path, path))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1971-L1974
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
1
def get(self, path): # XXX: Unused? return self.tree.get(posixpath.join(self.path, path))
26,345
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem._get_child_ids
(self, include_attachments=True, include_pages=True)
return sorted(names, key=lambda name: name.lower())
Returns a sorted list of just the IDs of existing children.
Returns a sorted list of just the IDs of existing children.
1,976
1,986
def _get_child_ids(self, include_attachments=True, include_pages=True): """Returns a sorted list of just the IDs of existing children.""" db = self.tree.pad.db keep_attachments = include_attachments and self.can_have_attachments keep_pages = include_pages and self.can_have_children names = set( name for name, _, is_attachment in db.iter_items(self.path, alt=None) if (keep_attachments if is_attachment else keep_pages) ) return sorted(names, key=lambda name: name.lower())
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1976-L1986
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.992532
11
3
100
1
def _get_child_ids(self, include_attachments=True, include_pages=True): db = self.tree.pad.db keep_attachments = include_attachments and self.can_have_attachments keep_pages = include_pages and self.can_have_children names = set( name for name, _, is_attachment in db.iter_items(self.path, alt=None) if (keep_attachments if is_attachment else keep_pages) ) return sorted(names, key=lambda name: name.lower())
26,346
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.iter_children
( self, include_attachments=True, include_pages=True, order_by=None )
return children
Iterates over all children
Iterates over all children
1,988
1,998
def iter_children( self, include_attachments=True, include_pages=True, order_by=None ): """Iterates over all children""" children = ( self.tree.get(posixpath.join(self.path, name), persist=False) for name in self._get_child_ids(include_attachments, include_pages) ) if order_by is not None: children = sorted(children, key=methodcaller("get_sort_key", order_by)) return children
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L1988-L1998
40
[ 0, 3, 4, 5, 6, 7, 8, 9, 10 ]
81.818182
[]
0
false
89.992532
11
2
100
1
def iter_children( self, include_attachments=True, include_pages=True, order_by=None ): children = ( self.tree.get(posixpath.join(self.path, name), persist=False) for name in self._get_child_ids(include_attachments, include_pages) ) if order_by is not None: children = sorted(children, key=methodcaller("get_sort_key", order_by)) return children
26,347
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.get_children
( self, offset=0, limit=None, include_attachments=True, include_pages=True, order_by=None, )
return list(islice(children, offset, end))
Returns a slice of children.
Returns a slice of children.
2,000
2,014
def get_children( self, offset=0, limit=None, include_attachments=True, include_pages=True, order_by=None, ): """Returns a slice of children.""" # XXX: this method appears unused? end = None if limit is not None: end = offset + limit children = self.iter_children(include_attachments, include_pages, order_by) return list(islice(children, offset, end))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2000-L2014
40
[ 0, 9, 10, 11, 12, 13, 14 ]
46.666667
[]
0
false
89.992532
15
2
100
1
def get_children( self, offset=0, limit=None, include_attachments=True, include_pages=True, order_by=None, ): # XXX: this method appears unused? end = None if limit is not None: end = offset + limit children = self.iter_children(include_attachments, include_pages, order_by) return list(islice(children, offset, end))
26,348
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.iter_attachments
(self, order_by=None)
return self.iter_children(include_pages=False, order_by=order_by)
Return an iterable of this records attachments. By default, the attachments are sorted as specified by ``[attachments]order_by`` in this records datamodel.
Return an iterable of this records attachments.
2,016
2,026
def iter_attachments(self, order_by=None): """Return an iterable of this records attachments. By default, the attachments are sorted as specified by ``[attachments]order_by`` in this records datamodel. """ if order_by is None: dm = self._datamodel if dm is not None: order_by = dm.attachment_config.order_by return self.iter_children(include_pages=False, order_by=order_by)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2016-L2026
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.992532
11
3
100
4
def iter_attachments(self, order_by=None): if order_by is None: dm = self._datamodel if dm is not None: order_by = dm.attachment_config.order_by return self.iter_children(include_pages=False, order_by=order_by)
26,349
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.iter_subpages
(self, order_by=None)
return self.iter_children(include_attachments=False, order_by=order_by)
Return an iterable of this records sub-pages. By default, the records are sorted as specified by ``[children]order_by`` in this records datamodel. NB: This method should probably be called ``iter_children``, but that name was already taken.
Return an iterable of this records sub-pages.
2,028
2,041
def iter_subpages(self, order_by=None): """Return an iterable of this records sub-pages. By default, the records are sorted as specified by ``[children]order_by`` in this records datamodel. NB: This method should probably be called ``iter_children``, but that name was already taken. """ if order_by is None: dm = self._datamodel if dm is not None: order_by = dm.child_config.order_by return self.iter_children(include_attachments=False, order_by=order_by)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2028-L2041
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
89.992532
14
3
100
7
def iter_subpages(self, order_by=None): if order_by is None: dm = self._datamodel if dm is not None: order_by = dm.child_config.order_by return self.iter_children(include_attachments=False, order_by=order_by)
26,350
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.get_sort_key
(self, order_by)
return self._primary_record.get_sort_key(order_by)
2,043
2,055
def get_sort_key(self, order_by): if self._primary_record is None: def sort_key(fieldspec): if fieldspec.startswith("-"): field, reverse = fieldspec[1:], True else: field, reverse = fieldspec.lstrip("+"), False value = self.id if field == "_id" else None return _CmpHelper(value, reverse) return [sort_key(fieldspec) for fieldspec in order_by] return self._primary_record.get_sort_key(order_by)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2043-L2055
40
[ 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12 ]
92.307692
[]
0
false
89.992532
13
5
100
0
def get_sort_key(self, order_by): if self._primary_record is None: def sort_key(fieldspec): if fieldspec.startswith("-"): field, reverse = fieldspec[1:], True else: field, reverse = fieldspec.lstrip("+"), False value = self.id if field == "_id" else None return _CmpHelper(value, reverse) return [sort_key(fieldspec) for fieldspec in order_by] return self._primary_record.get_sort_key(order_by)
26,351
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
TreeItem.__repr__
(self)
return "<TreeItem %r%s>" % ( self.path, self.is_attachment and " attachment" or "", )
2,057
2,061
def __repr__(self): return "<TreeItem %r%s>" % ( self.path, self.is_attachment and " attachment" or "", )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2057-L2061
40
[ 0, 1 ]
40
[]
0
false
89.992532
5
3
100
0
def __repr__(self): return "<TreeItem %r%s>" % ( self.path, self.is_attachment and " attachment" or "", )
26,352
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Alt.__init__
(self, id, record, is_primary_overlay, name_i18n)
2,065
2,070
def __init__(self, id, record, is_primary_overlay, name_i18n): self.id = id self.record = record self.is_primary_overlay = is_primary_overlay self.name_i18n = name_i18n self.exists = record is not None and os.path.isfile(record.source_filename)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2065-L2070
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
89.992532
6
2
100
0
def __init__(self, id, record, is_primary_overlay, name_i18n): self.id = id self.record = record self.is_primary_overlay = is_primary_overlay self.name_i18n = name_i18n self.exists = record is not None and os.path.isfile(record.source_filename)
26,353
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Alt.__repr__
(self)
return "<Alt %r%s>" % (self.id, self.exists and "*" or "")
2,072
2,073
def __repr__(self): return "<Alt %r%s>" % (self.id, self.exists and "*" or "")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2072-L2073
40
[ 0, 1 ]
100
[]
0
true
89.992532
2
3
100
0
def __repr__(self): return "<Alt %r%s>" % (self.id, self.exists and "*" or "")
26,354
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Tree.__init__
(self, pad)
2,088
2,125
def __init__(self, pad): # Note that in theory different alts can disagree on what # datamodel they use but this is something that is really not # supported. This cannot happen if you edit based on the admin # panel and if you edit it manually and screw up that part, we # cannot really do anything about it. # # We will favor the datamodel from the fallback record # (alt=PRIMARY_ALT) if it exists. If it does not, we will # use the data for the primary alternative. If data does not exist # for either of those, we will pick from among the other # existing alts quasi-randomly. # # Here we construct a list of configured alts in preference order config = pad.db.config alt_info = OrderedDict() if config.primary_alternative: # Alternatives are configured alts = [PRIMARY_ALT] alts.append(config.primary_alternative) alts.extend( alt for alt in config.list_alternatives() if alt != config.primary_alternative ) for alt in alts: alt_info[alt] = { "is_primary_overlay": alt == config.primary_alternative, "name_i18n": config.get_alternative(alt)["name"], } else: alt_info[PRIMARY_ALT] = { "is_primary_overlay": True, "name_i18n": {"en": "Primary"}, } self.pad = pad self._alt_info = alt_info
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2088-L2125
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, 31, 35, 36, 37 ]
71.052632
[]
0
false
89.992532
38
3
100
0
def __init__(self, pad): # Note that in theory different alts can disagree on what # datamodel they use but this is something that is really not # supported. This cannot happen if you edit based on the admin # panel and if you edit it manually and screw up that part, we # cannot really do anything about it. # # We will favor the datamodel from the fallback record # (alt=PRIMARY_ALT) if it exists. If it does not, we will # use the data for the primary alternative. If data does not exist # for either of those, we will pick from among the other # existing alts quasi-randomly. # # Here we construct a list of configured alts in preference order config = pad.db.config alt_info = OrderedDict() if config.primary_alternative: # Alternatives are configured alts = [PRIMARY_ALT] alts.append(config.primary_alternative) alts.extend( alt for alt in config.list_alternatives() if alt != config.primary_alternative ) for alt in alts: alt_info[alt] = { "is_primary_overlay": alt == config.primary_alternative, "name_i18n": config.get_alternative(alt)["name"], } else: alt_info[PRIMARY_ALT] = { "is_primary_overlay": True, "name_i18n": {"en": "Primary"}, } self.pad = pad self._alt_info = alt_info
26,355
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Tree.get
(self, path=None, persist=True)
return TreeItem(self, path, alts, primary_record)
Returns a path item at the given node.
Returns a path item at the given node.
2,127
2,137
def get(self, path=None, persist=True): """Returns a path item at the given node.""" path = "/" + (path or "").strip("/") alts = {} primary_record = None for alt, alt_info in self._alt_info.items(): record = self.pad.get(path, alt=alt, persist=persist, allow_virtual=False) if primary_record is None: primary_record = record alts[alt] = Alt(alt, record, **alt_info) return TreeItem(self, path, alts, primary_record)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2127-L2137
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
89.992532
11
4
100
1
def get(self, path=None, persist=True): path = "/" + (path or "").strip("/") alts = {} primary_record = None for alt, alt_info in self._alt_info.items(): record = self.pad.get(path, alt=alt, persist=persist, allow_virtual=False) if primary_record is None: primary_record = record alts[alt] = Alt(alt, record, **alt_info) return TreeItem(self, path, alts, primary_record)
26,356
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Tree.iter_children
( self, path=None, include_attachments=True, include_pages=True, order_by=None )
return self.get(path, persist=False).iter_children( include_attachments, include_pages, order_by )
Iterates over all children below a path
Iterates over all children below a path
2,139
2,147
def iter_children( self, path=None, include_attachments=True, include_pages=True, order_by=None ): """Iterates over all children below a path""" # XXX: this method is unused? path = "/" + (path or "").strip("/") return self.get(path, persist=False).iter_children( include_attachments, include_pages, order_by )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2139-L2147
40
[ 0 ]
11.111111
[ 5, 6 ]
22.222222
false
89.992532
9
2
77.777778
1
def iter_children( self, path=None, include_attachments=True, include_pages=True, order_by=None ): # XXX: this method is unused? path = "/" + (path or "").strip("/") return self.get(path, persist=False).iter_children( include_attachments, include_pages, order_by )
26,357
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Tree.get_children
( self, path=None, offset=0, limit=None, include_attachments=True, include_pages=True, order_by=None, )
return self.get(path, persist=False).get_children( offset, limit, include_attachments, include_pages, order_by )
Returns a slice of children.
Returns a slice of children.
2,149
2,163
def get_children( self, path=None, offset=0, limit=None, include_attachments=True, include_pages=True, order_by=None, ): """Returns a slice of children.""" # XXX: this method is unused? path = "/" + (path or "").strip("/") return self.get(path, persist=False).get_children( offset, limit, include_attachments, include_pages, order_by )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2149-L2163
40
[ 0 ]
6.666667
[ 11, 12 ]
13.333333
false
89.992532
15
2
86.666667
1
def get_children( self, path=None, offset=0, limit=None, include_attachments=True, include_pages=True, order_by=None, ): # XXX: this method is unused? path = "/" + (path or "").strip("/") return self.get(path, persist=False).get_children( offset, limit, include_attachments, include_pages, order_by )
26,358
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
Tree.edit
(self, path, is_attachment=None, alt=PRIMARY_ALT, datamodel=None)
return make_editor_session( self.pad, cleanup_path(path), alt=alt, is_attachment=is_attachment, datamodel=datamodel, )
Edits a record by path.
Edits a record by path.
2,165
2,173
def edit(self, path, is_attachment=None, alt=PRIMARY_ALT, datamodel=None): """Edits a record by path.""" return make_editor_session( self.pad, cleanup_path(path), alt=alt, is_attachment=is_attachment, datamodel=datamodel, )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2165-L2173
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
89.992532
9
1
100
1
def edit(self, path, is_attachment=None, alt=PRIMARY_ALT, datamodel=None): return make_editor_session( self.pad, cleanup_path(path), alt=alt, is_attachment=is_attachment, datamodel=datamodel, )
26,359
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.__init__
(self, ephemeral_cache_size=1000)
2,181
2,183
def __init__(self, ephemeral_cache_size=1000): self.persistent = {} self.ephemeral = LRUCache(ephemeral_cache_size)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2181-L2183
40
[ 0, 1, 2 ]
100
[]
0
true
89.992532
3
1
100
0
def __init__(self, ephemeral_cache_size=1000): self.persistent = {} self.ephemeral = LRUCache(ephemeral_cache_size)
26,360
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache._get_cache_key
(record_or_path, alt=PRIMARY_ALT, virtual_path=None)
return (path, alt, virtual_path)
2,186
2,194
def _get_cache_key(record_or_path, alt=PRIMARY_ALT, virtual_path=None): if isinstance(record_or_path, str): path = record_or_path.strip("/") else: path, virtual_path = split_virtual_path(record_or_path.path) path = path.strip("/") virtual_path = virtual_path or None alt = record_or_path.alt return (path, alt, virtual_path)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2186-L2194
40
[ 0, 1, 2, 4, 5, 6, 7, 8 ]
88.888889
[]
0
false
89.992532
9
3
100
0
def _get_cache_key(record_or_path, alt=PRIMARY_ALT, virtual_path=None): if isinstance(record_or_path, str): path = record_or_path.strip("/") else: path, virtual_path = split_virtual_path(record_or_path.path) path = path.strip("/") virtual_path = virtual_path or None alt = record_or_path.alt return (path, alt, virtual_path)
26,361
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.flush
(self)
Flushes the cache
Flushes the cache
2,196
2,199
def flush(self): """Flushes the cache""" self.persistent.clear() self.ephemeral.clear()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2196-L2199
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
1
def flush(self): self.persistent.clear() self.ephemeral.clear()
26,362
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.is_persistent
(self, record)
return cache_key in self.persistent
Indicates if a record is in the persistent record cache.
Indicates if a record is in the persistent record cache.
2,201
2,204
def is_persistent(self, record): """Indicates if a record is in the persistent record cache.""" cache_key = self._get_cache_key(record) return cache_key in self.persistent
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2201-L2204
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
1
def is_persistent(self, record): cache_key = self._get_cache_key(record) return cache_key in self.persistent
26,363
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.remember
(self, record)
Remembers the record in the record cache.
Remembers the record in the record cache.
2,206
2,210
def remember(self, record): """Remembers the record in the record cache.""" cache_key = self._get_cache_key(record) if cache_key not in self.persistent and cache_key not in self.ephemeral: self.ephemeral[cache_key] = record
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2206-L2210
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
89.992532
5
3
100
1
def remember(self, record): cache_key = self._get_cache_key(record) if cache_key not in self.persistent and cache_key not in self.ephemeral: self.ephemeral[cache_key] = record
26,364
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.persist
(self, record)
Persists a record. This will put it into the persistent cache.
Persists a record. This will put it into the persistent cache.
2,212
2,219
def persist(self, record): """Persists a record. This will put it into the persistent cache.""" cache_key = self._get_cache_key(record) self.persistent[cache_key] = record try: del self.ephemeral[cache_key] except KeyError: pass
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2212-L2219
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
89.992532
8
2
100
1
def persist(self, record): cache_key = self._get_cache_key(record) self.persistent[cache_key] = record try: del self.ephemeral[cache_key] except KeyError: pass
26,365
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.persist_if_cached
(self, record)
If the record is already ephemerally cached, this promotes it to the persistent cache section.
If the record is already ephemerally cached, this promotes it to the persistent cache section.
2,221
2,227
def persist_if_cached(self, record): """If the record is already ephemerally cached, this promotes it to the persistent cache section. """ cache_key = self._get_cache_key(record) if cache_key in self.ephemeral: self.persist(record)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2221-L2227
40
[ 0, 1, 2, 3 ]
57.142857
[ 4, 5, 6 ]
42.857143
false
89.992532
7
2
57.142857
2
def persist_if_cached(self, record): cache_key = self._get_cache_key(record) if cache_key in self.ephemeral: self.persist(record)
26,366
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.get
(self, path, alt=PRIMARY_ALT, virtual_path=None)
return Ellipsis
Looks up a record from the cache.
Looks up a record from the cache.
2,229
2,238
def get(self, path, alt=PRIMARY_ALT, virtual_path=None): """Looks up a record from the cache.""" cache_key = self._get_cache_key(path, alt, virtual_path) rv = self.persistent.get(cache_key, Ellipsis) if rv is not Ellipsis: return rv rv = self.ephemeral.get(cache_key, Ellipsis) if rv is not Ellipsis: return rv return Ellipsis
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2229-L2238
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
89.992532
10
3
100
1
def get(self, path, alt=PRIMARY_ALT, virtual_path=None): cache_key = self._get_cache_key(path, alt, virtual_path) rv = self.persistent.get(cache_key, Ellipsis) if rv is not Ellipsis: return rv rv = self.ephemeral.get(cache_key, Ellipsis) if rv is not Ellipsis: return rv return Ellipsis
26,367
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/db.py
RecordCache.remember_as_missing
(self, path, alt=PRIMARY_ALT, virtual_path=None)
2,240
2,243
def remember_as_missing(self, path, alt=PRIMARY_ALT, virtual_path=None): cache_key = self._get_cache_key(path, alt, virtual_path) self.persistent.pop(cache_key, None) self.ephemeral[cache_key] = None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/db.py#L2240-L2243
40
[ 0, 1, 2, 3 ]
100
[]
0
true
89.992532
4
1
100
0
def remember_as_missing(self, path, alt=PRIMARY_ALT, virtual_path=None): cache_key = self._get_cache_key(path, alt, virtual_path) self.persistent.pop(cache_key, None) self.ephemeral[cache_key] = None
26,368
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
echo_json
(data)
12
13
def echo_json(data): click.echo(json.dumps(data, indent=2).rstrip())
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L12-L13
40
[ 0 ]
50
[ 1 ]
50
false
33.333333
2
1
50
0
def echo_json(data): click.echo(json.dumps(data, indent=2).rstrip())
26,369
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
pruneflag
(cli)
return click.option( "--prune/--no-prune", default=True, help="Controls if old " 'artifacts should be pruned. "prune" is the default.', )(cli)
16
21
def pruneflag(cli): return click.option( "--prune/--no-prune", default=True, help="Controls if old " 'artifacts should be pruned. "prune" is the default.', )(cli)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L16-L21
40
[ 0, 1 ]
33.333333
[]
0
false
33.333333
6
1
100
0
def pruneflag(cli): return click.option( "--prune/--no-prune", default=True, help="Controls if old " 'artifacts should be pruned. "prune" is the default.', )(cli)
26,370
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
extraflag
(cli)
return click.option( "-f", "--extra-flag", "extra_flags", multiple=True, help="Defines an arbitrary flag. These can be used by plugins " "to customize the build and deploy process. More information can be " "found in the documentation of affected plugins.", )(cli)
24
33
def extraflag(cli): return click.option( "-f", "--extra-flag", "extra_flags", multiple=True, help="Defines an arbitrary flag. These can be used by plugins " "to customize the build and deploy process. More information can be " "found in the documentation of affected plugins.", )(cli)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L24-L33
40
[ 0, 1 ]
20
[]
0
false
33.333333
10
1
100
0
def extraflag(cli): return click.option( "-f", "--extra-flag", "extra_flags", multiple=True, help="Defines an arbitrary flag. These can be used by plugins " "to customize the build and deploy process. More information can be " "found in the documentation of affected plugins.", )(cli)
26,371
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
validate_language
(ctx, param, value)
return value
126
129
def validate_language(ctx, param, value): if value is not None and not is_valid_language(value): raise click.BadParameter('Unsupported language "%s".' % value) return value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L126-L129
40
[ 0 ]
25
[ 1, 2, 3 ]
75
false
33.333333
4
3
25
0
def validate_language(ctx, param, value): if value is not None and not is_valid_language(value): raise click.BadParameter('Unsupported language "%s".' % value) return value
26,372
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
AliasedGroup.get_command
(self, ctx, cmd_name)
39
48
def get_command(self, ctx, cmd_name): rv = click.Group.get_command(self, ctx, cmd_name) if rv is not None: return rv matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)] if not matches: return None if len(matches) == 1: return click.Group.get_command(self, ctx, matches[0]) ctx.fail("Too many matches: %s" % ", ".join(sorted(matches)))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L39-L48
40
[ 0 ]
10
[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
90
false
33.333333
10
5
10
0
def get_command(self, ctx, cmd_name): rv = click.Group.get_command(self, ctx, cmd_name) if rv is not None: return rv matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)] if not matches: return None if len(matches) == 1: return click.Group.get_command(self, ctx, matches[0]) ctx.fail("Too many matches: %s" % ", ".join(sorted(matches)))
26,373
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context.__init__
(self)
52
56
def __init__(self): self._project_path = os.environ.get("LEKTOR_PROJECT") or None self._project = None self._env = None self._ui_lang = None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L52-L56
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
33.333333
5
2
20
0
def __init__(self): self._project_path = os.environ.get("LEKTOR_PROJECT") or None self._project = None self._env = None self._ui_lang = None
26,374
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context._get_ui_lang
(self)
return rv
58
62
def _get_ui_lang(self): rv = self._ui_lang if rv is None: rv = self._ui_lang = get_default_lang() return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L58-L62
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
33.333333
5
2
20
0
def _get_ui_lang(self): rv = self._ui_lang if rv is None: rv = self._ui_lang = get_default_lang() return rv
26,375
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context._set_ui_lang
(self, value)
64
65
def _set_ui_lang(self, value): self._ui_lang = value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L64-L65
40
[ 0 ]
50
[ 1 ]
50
false
33.333333
2
1
50
0
def _set_ui_lang(self, value): self._ui_lang = value
26,376
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context.set_project_path
(self, value)
70
72
def set_project_path(self, value): self._project_path = value self._project = None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L70-L72
40
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
33.333333
3
1
33.333333
0
def set_project_path(self, value): self._project_path = value self._project = None
26,377
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context.get_project
(self, silent=False)
return rv
74
93
def get_project(self, silent=False): if self._project is not None: return self._project if self._project_path is not None: rv = Project.from_path(self._project_path) else: rv = Project.discover() if rv is None: if silent: return None if self._project_path is None: raise click.UsageError( "Could not automatically discover " "project. A Lektor project must " "exist in the working directory or " "any of the parent directories." ) raise click.UsageError('Could not find project "%s"' % self._project_path) self._project = rv return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L74-L93
40
[ 0 ]
5
[ 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 17, 18, 19 ]
65
false
33.333333
20
6
35
0
def get_project(self, silent=False): if self._project is not None: return self._project if self._project_path is not None: rv = Project.from_path(self._project_path) else: rv = Project.discover() if rv is None: if silent: return None if self._project_path is None: raise click.UsageError( "Could not automatically discover " "project. A Lektor project must " "exist in the working directory or " "any of the parent directories." ) raise click.UsageError('Could not find project "%s"' % self._project_path) self._project = rv return rv
26,378
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context.get_default_output_path
(self)
return self.get_project().get_output_path()
95
99
def get_default_output_path(self): rv = os.environ.get("LEKTOR_OUTPUT_PATH") if rv is not None: return rv return self.get_project().get_output_path()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L95-L99
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
33.333333
5
2
20
0
def get_default_output_path(self): rv = os.environ.get("LEKTOR_OUTPUT_PATH") if rv is not None: return rv return self.get_project().get_output_path()
26,379
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context.get_env
(self, extra_flags=None)
return env
101
110
def get_env(self, extra_flags=None): if self._env is not None: return self._env from lektor.environment import Environment env = Environment( self.get_project(), load_plugins=False, extra_flags=extra_flags ) self._env = env return env
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L101-L110
40
[ 0 ]
10
[ 1, 2, 3, 5, 8, 9 ]
60
false
33.333333
10
2
40
0
def get_env(self, extra_flags=None): if self._env is not None: return self._env from lektor.environment import Environment env = Environment( self.get_project(), load_plugins=False, extra_flags=extra_flags ) self._env = env return env
26,380
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/cli_utils.py
Context.load_plugins
(self, reinstall=False, extra_flags=None)
112
120
def load_plugins(self, reinstall=False, extra_flags=None): from .packages import load_packages load_packages(self.get_env(extra_flags=extra_flags), reinstall=reinstall) if not reinstall: from .pluginsystem import initialize_plugins initialize_plugins(self.get_env())
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/cli_utils.py#L112-L120
40
[ 0 ]
11.111111
[ 1, 3, 5, 6, 8 ]
55.555556
false
33.333333
9
2
44.444444
0
def load_plugins(self, reinstall=False, extra_flags=None): from .packages import load_packages load_packages(self.get_env(extra_flags=extra_flags), reinstall=reinstall) if not reinstall: from .pluginsystem import initialize_plugins initialize_plugins(self.get_env())
26,381
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
url_to
(*args, **kwargs)
return ctx.url_to(*args, **kwargs)
Calculates a URL to another record.
Calculates a URL to another record.
13
18
def url_to(*args, **kwargs): """Calculates a URL to another record.""" ctx = get_ctx() if ctx is None: raise RuntimeError("No context found") return ctx.url_to(*args, **kwargs)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L13-L18
40
[ 0, 1, 2, 3, 5 ]
83.333333
[ 4 ]
16.666667
false
76.821192
6
2
83.333333
1
def url_to(*args, **kwargs): ctx = get_ctx() if ctx is None: raise RuntimeError("No context found") return ctx.url_to(*args, **kwargs)
26,382
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
get_asset_url
(asset)
return ctx.get_asset_url(asset)
Calculates the asset URL relative to the current record.
Calculates the asset URL relative to the current record.
21
29
def get_asset_url(asset): """Calculates the asset URL relative to the current record.""" ctx = get_ctx() if ctx is None: raise RuntimeError("No context found") asset = ctx.pad.get_asset(asset) if asset is None: return Undefined("Asset not found") return ctx.get_asset_url(asset)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L21-L29
40
[ 0, 1, 2, 3, 5, 6, 8 ]
77.777778
[ 4, 7 ]
22.222222
false
76.821192
9
3
77.777778
1
def get_asset_url(asset): ctx = get_ctx() if ctx is None: raise RuntimeError("No context found") asset = ctx.pad.get_asset(asset) if asset is None: return Undefined("Asset not found") return ctx.get_asset_url(asset)
26,383
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
site_proxy
()
return ctx.pad
Returns the current pad.
Returns the current pad.
33
38
def site_proxy(): """Returns the current pad.""" ctx = get_ctx() if ctx is None: return Undefined(hint="Cannot access the site from here", name="site") return ctx.pad
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L33-L38
40
[ 0, 1 ]
33.333333
[ 2, 3, 4, 5 ]
66.666667
false
76.821192
6
2
33.333333
1
def site_proxy(): ctx = get_ctx() if ctx is None: return Undefined(hint="Cannot access the site from here", name="site") return ctx.pad
26,384
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
config_proxy
()
return site_proxy.db.config
Returns the current config.
Returns the current config.
42
44
def config_proxy(): """Returns the current config.""" return site_proxy.db.config
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L42-L44
40
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
76.821192
3
1
66.666667
1
def config_proxy(): return site_proxy.db.config
26,385
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
get_ctx
()
return _ctx_stack.top
Returns the current context.
Returns the current context.
47
49
def get_ctx(): """Returns the current context.""" return _ctx_stack.top
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L47-L49
40
[ 0, 1, 2 ]
100
[]
0
true
76.821192
3
1
100
1
def get_ctx(): return _ctx_stack.top
26,386
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
get_locale
(default="en_US")
return default
Returns the current locale.
Returns the current locale.
52
60
def get_locale(default="en_US"): """Returns the current locale.""" ctx = get_ctx() if ctx is not None: rv = ctx.locale if rv is not None: return rv return ctx.pad.db.config.site_locale return default
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L52-L60
40
[ 0, 1 ]
22.222222
[ 2, 3, 4, 5, 6, 7, 8 ]
77.777778
false
76.821192
9
3
22.222222
1
def get_locale(default="en_US"): ctx = get_ctx() if ctx is not None: rv = ctx.locale if rv is not None: return rv return ctx.pad.db.config.site_locale return default
26,387
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
ignore_url_unaffecting_dependencies
(value=True)
Ignore dependencies which do not affect URL resolution within context.
Ignore dependencies which do not affect URL resolution within context.
272
282
def ignore_url_unaffecting_dependencies(value=True): """Ignore dependencies which do not affect URL resolution within context.""" ctx = get_ctx() if ctx is not None: old = ctx._resolving_url ctx._resolving_url = value try: yield finally: if ctx is not None: ctx._resolving_url = old
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L272-L282
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
76.821192
11
3
100
1
def ignore_url_unaffecting_dependencies(value=True): ctx = get_ctx() if ctx is not None: old = ctx._resolving_url ctx._resolving_url = value try: yield finally: if ctx is not None: ctx._resolving_url = old
26,388
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.__init__
(self, artifact=None, pad=None)
73
108
def __init__(self, artifact=None, pad=None): if pad is None: if artifact is None: raise TypeError( "Either artifact or pad is needed to construct a context." ) pad = artifact.build_state.pad if artifact is not None: self.artifact = artifact self.source = artifact.source_obj self.build_state = self.artifact.build_state else: self.artifact = None self.source = None self.build_state = None self.exc_info = None self.pad = pad # Processing information self.referenced_dependencies = set() self.referenced_virtual_dependencies = {} self.sub_artifacts = [] self.flow_block_render_stack = [] self._forced_base_url = None self._resolving_url = False # General cache system where other things can put their temporary # stuff in. self.cache = {} self._dependency_collectors = []
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L73-L108
40
[ 0, 1, 2, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 ]
88.888889
[ 3 ]
2.777778
false
76.821192
36
4
97.222222
0
def __init__(self, artifact=None, pad=None): if pad is None: if artifact is None: raise TypeError( "Either artifact or pad is needed to construct a context." ) pad = artifact.build_state.pad if artifact is not None: self.artifact = artifact self.source = artifact.source_obj self.build_state = self.artifact.build_state else: self.artifact = None self.source = None self.build_state = None self.exc_info = None self.pad = pad # Processing information self.referenced_dependencies = set() self.referenced_virtual_dependencies = {} self.sub_artifacts = [] self.flow_block_render_stack = [] self._forced_base_url = None self._resolving_url = False # General cache system where other things can put their temporary # stuff in. self.cache = {} self._dependency_collectors = []
26,389
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.env
(self)
return self.pad.db.env
The environment of the context.
The environment of the context.
111
113
def env(self): """The environment of the context.""" return self.pad.db.env
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L111-L113
40
[ 0, 1, 2 ]
100
[]
0
true
76.821192
3
1
100
1
def env(self): return self.pad.db.env
26,390
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.record
(self)
return None
If the source is a record it will be available here.
If the source is a record it will be available here.
116
121
def record(self): """If the source is a record it will be available here.""" rv = self.source if rv is not None and rv.source_classification == "record": return rv return None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L116-L121
40
[ 0, 1 ]
33.333333
[ 2, 3, 4, 5 ]
66.666667
false
76.821192
6
3
33.333333
1
def record(self): rv = self.source if rv is not None and rv.source_classification == "record": return rv return None
26,391
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.locale
(self)
return None
Returns the current locale if it's available, otherwise `None`. This does not fall back to the site locale.
Returns the current locale if it's available, otherwise `None`. This does not fall back to the site locale.
124
133
def locale(self): """Returns the current locale if it's available, otherwise `None`. This does not fall back to the site locale. """ source = self.source if source is not None: alt_cfg = self.pad.db.config["ALTERNATIVES"].get(source.alt) if alt_cfg: return alt_cfg["locale"] return None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L124-L133
40
[ 0, 1, 2, 3 ]
40
[ 4, 5, 6, 7, 8, 9 ]
60
false
76.821192
10
3
40
2
def locale(self): source = self.source if source is not None: alt_cfg = self.pad.db.config["ALTERNATIVES"].get(source.alt) if alt_cfg: return alt_cfg["locale"] return None
26,392
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.push
(self)
135
136
def push(self): _ctx_stack.push(self)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L135-L136
40
[ 0, 1 ]
100
[]
0
true
76.821192
2
1
100
0
def push(self): _ctx_stack.push(self)
26,393
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.pop
()
139
140
def pop(): _ctx_stack.pop()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L139-L140
40
[ 0, 1 ]
100
[]
0
true
76.821192
2
1
100
0
def pop(): _ctx_stack.pop()
26,394
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.__enter__
(self)
return self
142
144
def __enter__(self): self.push() return self
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L142-L144
40
[ 0, 1, 2 ]
100
[]
0
true
76.821192
3
1
100
0
def __enter__(self): self.push() return self
26,395
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.__exit__
(self, exc_type, exc_value, tb)
146
147
def __exit__(self, exc_type, exc_value, tb): self.pop()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L146-L147
40
[ 0, 1 ]
100
[]
0
true
76.821192
2
1
100
0
def __exit__(self, exc_type, exc_value, tb): self.pop()
26,396
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.base_url
(self)
return "/"
The URL path for the current context.
The URL path for the current context.
150
156
def base_url(self): """The URL path for the current context.""" if self._forced_base_url: return self._forced_base_url if self.source is not None: return self.source.url_path return "/"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L150-L156
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
76.821192
7
3
100
1
def base_url(self): if self._forced_base_url: return self._forced_base_url if self.source is not None: return self.source.url_path return "/"
26,397
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.url_to
( self, path, alt=None, absolute=None, external=None, resolve=None, strict_resolve=None, )
return self.source.url_to( path, alt=alt, base_url=self.base_url, absolute=absolute, external=external, resolve=resolve, strict_resolve=strict_resolve, )
Returns a URL to another path.
Returns a URL to another path.
158
181
def url_to( self, path, alt=None, absolute=None, external=None, resolve=None, strict_resolve=None, ): """Returns a URL to another path.""" if self.source is None: raise RuntimeError( "Can only generate paths to other pages if " "the context has a source document set." ) return self.source.url_to( path, alt=alt, base_url=self.base_url, absolute=absolute, external=external, resolve=resolve, strict_resolve=strict_resolve, )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L158-L181
40
[ 0, 9, 10, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
54.166667
[ 11 ]
4.166667
false
76.821192
24
2
95.833333
1
def url_to( self, path, alt=None, absolute=None, external=None, resolve=None, strict_resolve=None, ): if self.source is None: raise RuntimeError( "Can only generate paths to other pages if " "the context has a source document set." ) return self.source.url_to( path, alt=alt, base_url=self.base_url, absolute=absolute, external=external, resolve=resolve, strict_resolve=strict_resolve, )
26,398
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.get_asset_url
(self, asset)
return f"{asset_url}?h={info.checksum[:8]}"
Calculates the asset URL relative to the current record.
Calculates the asset URL relative to the current record.
183
193
def get_asset_url(self, asset): """Calculates the asset URL relative to the current record.""" if self.source is None: raise RuntimeError( "Can only generate paths to assets if " "the context has a source document set." ) asset_url = self.source.url_to("!" + asset.url_path) info = self.build_state.get_file_info(asset.source_filename) self.record_dependency(asset.source_filename) return f"{asset_url}?h={info.checksum[:8]}"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L183-L193
40
[ 0, 1, 2, 6, 7, 8, 9, 10 ]
72.727273
[ 3 ]
9.090909
false
76.821192
11
2
90.909091
1
def get_asset_url(self, asset): if self.source is None: raise RuntimeError( "Can only generate paths to assets if " "the context has a source document set." ) asset_url = self.source.url_to("!" + asset.url_path) info = self.build_state.get_file_info(asset.source_filename) self.record_dependency(asset.source_filename) return f"{asset_url}?h={info.checksum[:8]}"
26,399
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.sub_artifact
(self, *args, **kwargs)
return decorator
Decorator version of :func:`add_sub_artifact`.
Decorator version of :func:`add_sub_artifact`.
195
202
def sub_artifact(self, *args, **kwargs): """Decorator version of :func:`add_sub_artifact`.""" def decorator(f): self.add_sub_artifact(build_func=f, *args, **kwargs) return f return decorator
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L195-L202
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
76.821192
8
2
100
1
def sub_artifact(self, *args, **kwargs): def decorator(f): self.add_sub_artifact(build_func=f, *args, **kwargs) return f return decorator
26,400
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.add_sub_artifact
( self, artifact_name, build_func=None, sources=None, source_obj=None, config_hash=None, )
Sometimes it can happen that while building an artifact another artifact needs building. This function is generally used to record this request.
Sometimes it can happen that while building an artifact another artifact needs building. This function is generally used to record this request.
204
228
def add_sub_artifact( self, artifact_name, build_func=None, sources=None, source_obj=None, config_hash=None, ): """Sometimes it can happen that while building an artifact another artifact needs building. This function is generally used to record this request. """ if self.build_state is None: raise TypeError( "The context does not have a build state which " "means that artifact declaration is not possible." ) aft = self.build_state.new_artifact( artifact_name=artifact_name, sources=sources, source_obj=source_obj, config_hash=config_hash, ) self.sub_artifacts.append((aft, build_func)) reporter.report_sub_artifact(aft)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L204-L228
40
[ 0, 11, 12, 16, 17, 18, 19, 20, 21, 22, 23, 24 ]
48
[ 13 ]
4
false
76.821192
25
2
96
3
def add_sub_artifact( self, artifact_name, build_func=None, sources=None, source_obj=None, config_hash=None, ): if self.build_state is None: raise TypeError( "The context does not have a build state which " "means that artifact declaration is not possible." ) aft = self.build_state.new_artifact( artifact_name=artifact_name, sources=sources, source_obj=source_obj, config_hash=config_hash, ) self.sub_artifacts.append((aft, build_func)) reporter.report_sub_artifact(aft)
26,401
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.record_dependency
(self, filename, affects_url=None)
Records a dependency from processing. If ``affects_url`` is set to ``False`` the dependency will be ignored if we are in the process of resolving a URL.
Records a dependency from processing.
230
240
def record_dependency(self, filename, affects_url=None): """Records a dependency from processing. If ``affects_url`` is set to ``False`` the dependency will be ignored if we are in the process of resolving a URL. """ if self._resolving_url and affects_url is False: return self.referenced_dependencies.add(filename) for coll in self._dependency_collectors: coll(filename)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L230-L240
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
90.909091
[ 10 ]
9.090909
false
76.821192
11
4
90.909091
4
def record_dependency(self, filename, affects_url=None): if self._resolving_url and affects_url is False: return self.referenced_dependencies.add(filename) for coll in self._dependency_collectors: coll(filename)
26,402
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.record_virtual_dependency
(self, virtual_source)
Records a dependency from processing.
Records a dependency from processing.
242
247
def record_virtual_dependency(self, virtual_source): """Records a dependency from processing.""" path = virtual_source.path self.referenced_virtual_dependencies[path] = virtual_source for coll in self._dependency_collectors: coll(virtual_source)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L242-L247
40
[ 0, 1, 2, 3, 4 ]
83.333333
[ 5 ]
16.666667
false
76.821192
6
2
83.333333
1
def record_virtual_dependency(self, virtual_source): path = virtual_source.path self.referenced_virtual_dependencies[path] = virtual_source for coll in self._dependency_collectors: coll(virtual_source)
26,403
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.gather_dependencies
(self, func)
For the duration of the `with` block the provided function will be invoked for all dependencies encountered.
For the duration of the `with` block the provided function will be invoked for all dependencies encountered.
250
258
def gather_dependencies(self, func): """For the duration of the `with` block the provided function will be invoked for all dependencies encountered. """ self._dependency_collectors.append(func) try: yield finally: self._dependency_collectors.pop()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L250-L258
40
[ 0, 1, 2, 3 ]
44.444444
[ 4, 5, 6, 8 ]
44.444444
false
76.821192
9
1
55.555556
2
def gather_dependencies(self, func): self._dependency_collectors.append(func) try: yield finally: self._dependency_collectors.pop()
26,404
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/context.py
Context.changed_base_url
(self, value)
Temporarily overrides the URL path of the context.
Temporarily overrides the URL path of the context.
261
268
def changed_base_url(self, value): """Temporarily overrides the URL path of the context.""" old = self._forced_base_url self._forced_base_url = value try: yield finally: self._forced_base_url = old
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/context.py#L261-L268
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
76.821192
8
1
100
1
def changed_base_url(self, value): old = self._forced_base_url self._forced_base_url = value try: yield finally: self._forced_base_url = old
26,405
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/i18n.py
get_translations
(language)
return translations.get(language)
Looks up the translations for a given language.
Looks up the translations for a given language.
19
21
def get_translations(language): """Looks up the translations for a given language.""" return translations.get(language)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/i18n.py#L19-L21
40
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
77.272727
3
1
66.666667
1
def get_translations(language): return translations.get(language)
26,406
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/i18n.py
is_valid_language
(lang)
return lang in KNOWN_LANGUAGES
Verifies a language is known and valid.
Verifies a language is known and valid.
24
26
def is_valid_language(lang): """Verifies a language is known and valid.""" return lang in KNOWN_LANGUAGES
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/i18n.py#L24-L26
40
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
77.272727
3
1
66.666667
1
def is_valid_language(lang): return lang in KNOWN_LANGUAGES
26,407
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/i18n.py
get_default_lang
()
return "en"
Returns the default language the system should use.
Returns the default language the system should use.
29
38
def get_default_lang(): """Returns the default language the system should use.""" for key in "LANGUAGE", "LC_ALL", "LC_CTYPE", "LANG": value = os.environ.get(key) if not value: continue lang = value.split("_")[0].lower() if is_valid_language(lang): return lang return "en"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/i18n.py#L29-L38
40
[ 0, 1 ]
20
[ 2, 3, 4, 5, 6, 7, 8, 9 ]
80
false
77.272727
10
4
20
1
def get_default_lang(): for key in "LANGUAGE", "LC_ALL", "LC_CTYPE", "LANG": value = os.environ.get(key) if not value: continue lang = value.split("_")[0].lower() if is_valid_language(lang): return lang return "en"
26,408
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/i18n.py
load_i18n_block
(key)
return rv
Looks up an entire i18n block from a known translation.
Looks up an entire i18n block from a known translation.
41
48
def load_i18n_block(key): """Looks up an entire i18n block from a known translation.""" rv = {} for lang in KNOWN_LANGUAGES: val = translations.get(lang, {}).get(key) if val is not None: rv[lang] = val return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/i18n.py#L41-L48
40
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
77.272727
8
3
100
1
def load_i18n_block(key): rv = {} for lang in KNOWN_LANGUAGES: val = translations.get(lang, {}).get(key) if val is not None: rv[lang] = val return rv
26,409
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/i18n.py
get_i18n_block
(inifile_or_dict, key, pop=False)
return rv
Extracts an i18n block from an ini file or dictionary for a given key. If "pop", delete keys from "inifile_or_dict".
Extracts an i18n block from an ini file or dictionary for a given key. If "pop", delete keys from "inifile_or_dict".
51
65
def get_i18n_block(inifile_or_dict, key, pop=False): """Extracts an i18n block from an ini file or dictionary for a given key. If "pop", delete keys from "inifile_or_dict". """ rv = {} for k in list(inifile_or_dict): if k == key: # English is the internal default language with preferred # treatment. rv["en"] = inifile_or_dict.pop(k) if pop else inifile_or_dict[k] elif k.startswith(key + "["): rv[k[len(key) + 1 : -1]] = ( inifile_or_dict.pop(k) if pop else inifile_or_dict[k] ) return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/i18n.py#L51-L65
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
77.272727
15
4
100
2
def get_i18n_block(inifile_or_dict, key, pop=False): rv = {} for k in list(inifile_or_dict): if k == key: # English is the internal default language with preferred # treatment. rv["en"] = inifile_or_dict.pop(k) if pop else inifile_or_dict[k] elif k.startswith(key + "["): rv[k[len(key) + 1 : -1]] = ( inifile_or_dict.pop(k) if pop else inifile_or_dict[k] ) return rv
26,410
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/i18n.py
generate_i18n_kvs
(**opts)
Generates key-value pairs based on the kwargs passed into this function. For every key ending in "_i18n", its corresponding value will be translated and returned once for every language that has a known translation.
Generates key-value pairs based on the kwargs passed into this function. For every key ending in "_i18n", its corresponding value will be translated and returned once for every language that has a known translation.
68
80
def generate_i18n_kvs(**opts): """Generates key-value pairs based on the kwargs passed into this function. For every key ending in "_i18n", its corresponding value will be translated and returned once for every language that has a known translation. """ for key, value in opts.items(): if key.endswith("_i18n"): base_key = key[:-5] for lang, trans in load_i18n_block(value).items(): lang_key = "%s[%s]" % (base_key, lang) yield lang_key, trans else: yield key, value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/i18n.py#L68-L80
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
77.272727
13
4
100
3
def generate_i18n_kvs(**opts): for key, value in opts.items(): if key.endswith("_i18n"): base_key = key[:-5] for lang, trans in load_i18n_block(value).items(): lang_key = "%s[%s]" % (base_key, lang) yield lang_key, trans else: yield key, value
26,411
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/pagination.py
Pagination.__init__
(self, record, pagination_config)
2
12
def __init__(self, record, pagination_config): #: the pagination config self.config = pagination_config #: the current page's record self.current = record #: the current page number (1 indexed) self.page = record.page_num #: the number of items to be displayed on a page. self.per_page = pagination_config.per_page #: the total number of items matching the query self.total = pagination_config.count_total_items(record)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L2-L12
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
98.148148
11
1
100
0
def __init__(self, record, pagination_config): #: the pagination config self.config = pagination_config #: the current page's record self.current = record #: the current page number (1 indexed) self.page = record.page_num #: the number of items to be displayed on a page. self.per_page = pagination_config.per_page #: the total number of items matching the query self.total = pagination_config.count_total_items(record)
26,412
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/pagination.py
Pagination.items
(self)
return self.config.slice_query_for_page(self.current, self.page)
The children for this page.
The children for this page.
15
17
def items(self): """The children for this page.""" return self.config.slice_query_for_page(self.current, self.page)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/pagination.py#L15-L17
40
[ 0, 1, 2 ]
100
[]
0
true
98.148148
3
1
100
1
def items(self): return self.config.slice_query_for_page(self.current, self.page)
26,413