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/admin/modules/api.py
browsefs
(validated: _PathAndAlt, ctx: LektorContext)
return jsonify(okay=okay)
233
244
def browsefs(validated: _PathAndAlt, ctx: LektorContext) -> Response: record = ctx.pad.get(validated.path, alt=validated.alt) okay = False if record is not None: if record.is_attachment: fn = record.attachment_filename else: fn = record.source_filename if os.path.exists(fn): click.launch(fn, locate=True) okay = True return jsonify(okay=okay)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L233-L244
40
[ 0 ]
8.333333
[ 1, 2, 3, 4, 5, 7, 8, 9, 10, 11 ]
83.333333
false
86.85259
12
4
16.666667
0
def browsefs(validated: _PathAndAlt, ctx: LektorContext) -> Response: record = ctx.pad.get(validated.path, alt=validated.alt) okay = False if record is not None: if record.is_attachment: fn = record.attachment_filename else: fn = record.source_filename if os.path.exists(fn): click.launch(fn, locate=True) okay = True return jsonify(okay=okay)
26,614
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
match_url
(validated: _UrlPath, ctx: LektorContext)
return jsonify(exists=True, path=record["_path"], alt=record["_alt"])
Find the Record that corresponds to a URL. This is used by the admin UI to find the db record that corresponds to a page when the preview iframe is navigated.
Find the Record that corresponds to a URL.
254
263
def match_url(validated: _UrlPath, ctx: LektorContext) -> Response: """Find the Record that corresponds to a URL. This is used by the admin UI to find the db record that corresponds to a page when the preview iframe is navigated. """ record = ctx.pad.resolve_url_path(validated.url_path, alt_fallback=False) if not isinstance(record, Record): return jsonify(exists=False, path=None, alt=None) return jsonify(exists=True, path=record["_path"], alt=record["_alt"])
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L254-L263
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
86.85259
10
2
100
4
def match_url(validated: _UrlPath, ctx: LektorContext) -> Response: record = ctx.pad.resolve_url_path(validated.url_path, alt_fallback=False) if not isinstance(record, Record): return jsonify(exists=False, path=None, alt=None) return jsonify(exists=True, path=record["_path"], alt=record["_alt"])
26,615
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
get_raw_record
(validated: _PathAndAlt, ctx: LektorContext)
return jsonify(ts.to_json())
268
270
def get_raw_record(validated: _PathAndAlt, ctx: LektorContext) -> Response: ts = ctx.tree.edit(validated.path, alt=validated.alt) return jsonify(ts.to_json())
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L268-L270
40
[ 0, 1, 2 ]
100
[]
0
true
86.85259
3
1
100
0
def get_raw_record(validated: _PathAndAlt, ctx: LektorContext) -> Response: ts = ctx.tree.edit(validated.path, alt=validated.alt) return jsonify(ts.to_json())
26,616
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
get_new_record_info
(validated: _PathAndAlt, ctx: LektorContext)
return jsonify( { "label_i18n": label_i18n, "label": label_i18n["en"], "can_have_children": tree_item.can_have_children, "implied_model": implied_model, "available_models": dict( (k, describe_model(v)) for k, v in pad.db.datamodels.items() if not v.hidden or k == implied_model ), } )
275
307
def get_new_record_info(validated: _PathAndAlt, ctx: LektorContext) -> Response: pad = ctx.pad alt = validated.alt tree_item = ctx.tree.get(validated.path) def describe_model(model: DataModel) -> Dict[str, Any]: primary_field = None if model.primary_field is not None: f = model.field_map.get(model.primary_field) if f is not None: primary_field = f.to_json(pad) return { "id": model.id, "name": model.name, "name_i18n": model.name_i18n, "primary_field": primary_field, } implied_model = tree_item.implied_child_datamodel label_i18n = tree_item.get_record_label_i18n(alt) return jsonify( { "label_i18n": label_i18n, "label": label_i18n["en"], "can_have_children": tree_item.can_have_children, "implied_model": implied_model, "available_models": dict( (k, describe_model(v)) for k, v in pad.db.datamodels.items() if not v.hidden or k == implied_model ), } )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L275-L307
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 17, 18, 19, 20 ]
48.484848
[]
0
false
86.85259
33
5
100
0
def get_new_record_info(validated: _PathAndAlt, ctx: LektorContext) -> Response: pad = ctx.pad alt = validated.alt tree_item = ctx.tree.get(validated.path) def describe_model(model: DataModel) -> Dict[str, Any]: primary_field = None if model.primary_field is not None: f = model.field_map.get(model.primary_field) if f is not None: primary_field = f.to_json(pad) return { "id": model.id, "name": model.name, "name_i18n": model.name_i18n, "primary_field": primary_field, } implied_model = tree_item.implied_child_datamodel label_i18n = tree_item.get_record_label_i18n(alt) return jsonify( { "label_i18n": label_i18n, "label": label_i18n["en"], "can_have_children": tree_item.can_have_children, "implied_model": implied_model, "available_models": dict( (k, describe_model(v)) for k, v in pad.db.datamodels.items() if not v.hidden or k == implied_model ), } )
26,617
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
get_new_attachment_info
(validated: _PathAndAlt, ctx: LektorContext)
return jsonify( { "can_upload": tree_item.can_have_attachments, "label_i18n": label_i18n, "label": label_i18n["en"], } )
312
321
def get_new_attachment_info(validated: _PathAndAlt, ctx: LektorContext) -> Response: tree_item = ctx.tree.get(validated.path) label_i18n = tree_item.get_record_label_i18n(validated.alt) return jsonify( { "can_upload": tree_item.can_have_attachments, "label_i18n": label_i18n, "label": label_i18n["en"], } )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L312-L321
40
[ 0, 1, 2, 3 ]
40
[]
0
false
86.85259
10
1
100
0
def get_new_attachment_info(validated: _PathAndAlt, ctx: LektorContext) -> Response: tree_item = ctx.tree.get(validated.path) label_i18n = tree_item.get_record_label_i18n(validated.alt) return jsonify( { "can_upload": tree_item.can_have_attachments, "label_i18n": label_i18n, "label": label_i18n["en"], } )
26,618
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
upload_new_attachments
(validated: _PathAndAlt, ctx: LektorContext)
return jsonify( { "bad_upload": False, "path": validated.path, "buckets": buckets, } )
326
347
def upload_new_attachments(validated: _PathAndAlt, ctx: LektorContext) -> Response: ts = ctx.tree.edit(validated.path, alt=validated.alt) if not ts.exists or ts.is_attachment: return jsonify({"bad_upload": True}) buckets = [] for file in request.files.getlist("file"): buckets.append( { "original_filename": file.filename, "stored_filename": ts.add_attachment(file.filename, file), } ) return jsonify( { "bad_upload": False, "path": validated.path, "buckets": buckets, } )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L326-L347
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 14, 15 ]
50
[]
0
false
86.85259
22
4
100
0
def upload_new_attachments(validated: _PathAndAlt, ctx: LektorContext) -> Response: ts = ctx.tree.edit(validated.path, alt=validated.alt) if not ts.exists or ts.is_attachment: return jsonify({"bad_upload": True}) buckets = [] for file in request.files.getlist("file"): buckets.append( { "original_filename": file.filename, "stored_filename": ts.add_attachment(file.filename, file), } ) return jsonify( { "bad_upload": False, "path": validated.path, "buckets": buckets, } )
26,619
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
add_new_record
(validated: _NewRecordParams, ctx: LektorContext)
return jsonify({"valid_id": True, "exists": exists, "path": path})
361
376
def add_new_record(validated: _NewRecordParams, ctx: LektorContext) -> Response: exists = False if not is_valid_id(validated.id): return jsonify(valid_id=False, exists=False, path=None) path = posixpath.join(validated.path, validated.id) ts = ctx.tree.edit(path, datamodel=validated.model, alt=validated.alt) with ts: if ts.exists: exists = True else: ts.data.update(validated.data) return jsonify({"valid_id": True, "exists": exists, "path": path})
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L361-L376
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15 ]
93.75
[]
0
false
86.85259
16
4
100
0
def add_new_record(validated: _NewRecordParams, ctx: LektorContext) -> Response: exists = False if not is_valid_id(validated.id): return jsonify(valid_id=False, exists=False, path=None) path = posixpath.join(validated.path, validated.id) ts = ctx.tree.edit(path, datamodel=validated.model, alt=validated.alt) with ts: if ts.exists: exists = True else: ts.data.update(validated.data) return jsonify({"valid_id": True, "exists": exists, "path": path})
26,620
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
delete_record
(validated: _DeleteRecordParams, ctx: LektorContext)
return jsonify(okay=True)
388
393
def delete_record(validated: _DeleteRecordParams, ctx: LektorContext) -> Response: if validated.path != "/": ts = ctx.tree.edit(validated.path, alt=validated.alt) with ts: ts.delete(delete_master=validated.delete_master) return jsonify(okay=True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L388-L393
40
[ 0 ]
16.666667
[ 1, 2, 3, 4, 5 ]
83.333333
false
86.85259
6
3
16.666667
0
def delete_record(validated: _DeleteRecordParams, ctx: LektorContext) -> Response: if validated.path != "/": ts = ctx.tree.edit(validated.path, alt=validated.alt) with ts: ts.delete(delete_master=validated.delete_master) return jsonify(okay=True)
26,621
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
update_raw_record
( validated: _UpdateRawRecordParams, ctx: LektorContext )
return jsonify(path=ts.path)
405
411
def update_raw_record( validated: _UpdateRawRecordParams, ctx: LektorContext ) -> Response: ts = ctx.tree.edit(validated.path, alt=validated.alt) with ts: ts.data.update(validated.data) return jsonify(path=ts.path)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L405-L411
40
[ 0, 3, 4, 5, 6 ]
71.428571
[]
0
false
86.85259
7
2
100
0
def update_raw_record( validated: _UpdateRawRecordParams, ctx: LektorContext ) -> Response: ts = ctx.tree.edit(validated.path, alt=validated.alt) with ts: ts.data.update(validated.data) return jsonify(path=ts.path)
26,622
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
get_servers
(ctx: LektorContext)
return jsonify( servers=sorted( [x.to_json() for x in servers.values()], key=lambda x: x["name"].lower() ) )
415
421
def get_servers(ctx: LektorContext) -> Response: servers = ctx.config.get_servers(public=True) return jsonify( servers=sorted( [x.to_json() for x in servers.values()], key=lambda x: x["name"].lower() ) )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L415-L421
40
[ 0, 1, 2 ]
42.857143
[]
0
false
86.85259
7
2
100
0
def get_servers(ctx: LektorContext) -> Response: servers = ctx.config.get_servers(public=True) return jsonify( servers=sorted( [x.to_json() for x in servers.values()], key=lambda x: x["name"].lower() ) )
26,623
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
trigger_build
(ctx: LektorContext)
return jsonify(okay=True)
425
429
def trigger_build(ctx: LektorContext) -> Response: builder = ctx.builder builder.build_all() builder.prune() return jsonify(okay=True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L425-L429
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
86.85259
5
1
20
0
def trigger_build(ctx: LektorContext) -> Response: builder = ctx.builder builder.build_all() builder.prune() return jsonify(okay=True)
26,624
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
trigger_clean
(ctx: LektorContext)
return jsonify(okay=True)
433
437
def trigger_clean(ctx: LektorContext) -> Response: builder = ctx.builder builder.prune(all=True) builder.touch_site_config() return jsonify(okay=True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L433-L437
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
86.85259
5
1
20
0
def trigger_clean(ctx: LektorContext) -> Response: builder = ctx.builder builder.prune(all=True) builder.touch_site_config() return jsonify(okay=True)
26,625
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
publish_build
(validated: _PublishBuildParams, ctx: LektorContext)
return generator()
447
465
def publish_build(validated: _PublishBuildParams, ctx: LektorContext) -> Response: @eventstream def generator() -> Iterator[Dict[str, str]]: try: event_iter = ( publish( ctx.env, validated.server_info.target, ctx.output_path, server_info=validated.server_info, ) or () ) for event in event_iter: yield {"msg": event} except PublishError as e: yield {"msg": "Error: %s" % e} return generator()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L447-L465
40
[ 0 ]
5.263158
[ 1, 2, 3, 4, 13, 14, 15, 16, 18 ]
47.368421
false
86.85259
19
5
52.631579
0
def publish_build(validated: _PublishBuildParams, ctx: LektorContext) -> Response: @eventstream def generator() -> Iterator[Dict[str, str]]: try: event_iter = ( publish( ctx.env, validated.server_info.target, ctx.output_path, server_info=validated.server_info, ) or () ) for event in event_iter: yield {"msg": event} except PublishError as e: yield {"msg": "Error: %s" % e} return generator()
26,626
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
ping
(ctx: LektorContext)
return jsonify(project_id=ctx.project_id, okay=True)
469
470
def ping(ctx: LektorContext) -> Response: return jsonify(project_id=ctx.project_id, okay=True)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L469-L470
40
[ 0, 1 ]
100
[]
0
true
86.85259
2
1
100
0
def ping(ctx: LektorContext) -> Response: return jsonify(project_id=ctx.project_id, okay=True)
26,627
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/api.py
_ServerInfoField._deserialize
( self, value: str, attr: Optional[str], data: Optional[Mapping[str, Any]], **kwargs: Any )
return server_info
50
62
def _deserialize( self, value: str, attr: Optional[str], data: Optional[Mapping[str, Any]], **kwargs: Any ) -> ServerInfo: lektor_config = self.context["lektor_config"] server_id = super()._deserialize(value, attr, data, **kwargs) server_info = lektor_config.get_server(server_id) if server_info is None: raise marshmallow.ValidationError("Invalid server id.") return server_info
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/api.py#L50-L62
40
[ 0, 7, 8, 9, 10, 11 ]
46.153846
[ 12 ]
7.692308
false
86.85259
13
2
92.307692
0
def _deserialize( self, value: str, attr: Optional[str], data: Optional[Mapping[str, Any]], **kwargs: Any ) -> ServerInfo: lektor_config = self.context["lektor_config"] server_id = super()._deserialize(value, attr, data, **kwargs) server_info = lektor_config.get_server(server_id) if server_info is None: raise marshmallow.ValidationError("Invalid server id.") return server_info
26,628
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
_rewrite_html_for_editing
( html: bytes, edit_url: str, artifact_name: Optional[str] = None )
return re.sub(rb"(?i)</\s*head\s*>|\Z", extras, html, count=1)
Adds an "edit pencil" button to the text of an HTML page. The pencil will link to ``edit_url``.
Adds an "edit pencil" button to the text of an HTML page.
41
55
def _rewrite_html_for_editing( html: bytes, edit_url: str, artifact_name: Optional[str] = None ) -> bytes: """Adds an "edit pencil" button to the text of an HTML page. The pencil will link to ``edit_url``. """ button = render_template("edit-button.html", edit_url=edit_url) if "livereload" in current_app.blueprints: button += render_template("livereload.html", artifact_name=artifact_name) def extras(m: Match[bytes]) -> bytes: return button.encode("utf-8") + m.group(0) return re.sub(rb"(?i)</\s*head\s*>|\Z", extras, html, count=1)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L41-L55
40
[ 0, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
66.666667
[]
0
false
100
15
3
100
3
def _rewrite_html_for_editing( html: bytes, edit_url: str, artifact_name: Optional[str] = None ) -> bytes: button = render_template("edit-button.html", edit_url=edit_url) if "livereload" in current_app.blueprints: button += render_template("livereload.html", artifact_name=artifact_name) def extras(m: Match[bytes]) -> bytes: return button.encode("utf-8") + m.group(0) return re.sub(rb"(?i)</\s*head\s*>|\Z", extras, html, count=1)
26,629
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
_send_html_for_editing
( artifact: Artifact, edit_url: str, mimetype: str = "text/html" )
return resp
Serve an HTML file, after mangling it to add an "edit pencil" button.
Serve an HTML file, after mangling it to add an "edit pencil" button.
58
72
def _send_html_for_editing( artifact: Artifact, edit_url: str, mimetype: str = "text/html" ) -> Response: """Serve an HTML file, after mangling it to add an "edit pencil" button.""" try: with open(artifact.dst_filename, "rb") as fp: html = fp.read() st = os.stat(fp.fileno()) except (FileNotFoundError, IsADirectoryError, PermissionError): abort(404) html = _rewrite_html_for_editing(html, edit_url, artifact.artifact_name) check = adler32(f"{artifact.dst_filename}\0{edit_url}".encode("utf-8")) & 0xFFFFFFFF resp = Response(html, mimetype=mimetype) resp.set_etag(f"{st.st_mtime}-{st.st_size}-{check}") return resp
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L58-L72
40
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
86.666667
[]
0
false
100
15
3
100
1
def _send_html_for_editing( artifact: Artifact, edit_url: str, mimetype: str = "text/html" ) -> Response: try: with open(artifact.dst_filename, "rb") as fp: html = fp.read() st = os.stat(fp.fileno()) except (FileNotFoundError, IsADirectoryError, PermissionError): abort(404) html = _rewrite_html_for_editing(html, edit_url, artifact.artifact_name) check = adler32(f"{artifact.dst_filename}\0{edit_url}".encode("utf-8")) & 0xFFFFFFFF resp = Response(html, mimetype=mimetype) resp.set_etag(f"{st.st_mtime}-{st.st_size}-{check}") return resp
26,630
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
_deduce_mimetype
(filename: Filename)
return mimetype
75
79
def _deduce_mimetype(filename: Filename) -> str: mimetype = mimetypes.guess_type(filename)[0] if mimetype is None: mimetype = "application/octet-stream" return mimetype
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L75-L79
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
100
5
2
100
0
def _deduce_mimetype(filename: Filename) -> str: mimetype = mimetypes.guess_type(filename)[0] if mimetype is None: mimetype = "application/octet-stream" return mimetype
26,631
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
_checked_send_file
(filename: Filename, mimetype: Optional[str] = None)
return resp
Same as flask.send_file, except raises NotFound on file errors.
Same as flask.send_file, except raises NotFound on file errors.
82
90
def _checked_send_file(filename: Filename, mimetype: Optional[str] = None) -> Response: """Same as flask.send_file, except raises NotFound on file errors.""" # NB: flask.send_file interprets relative paths relative to # current_app.root_path. We don't want that. try: resp = send_file(os.path.abspath(filename), mimetype=mimetype) except (FileNotFoundError, IsADirectoryError, PermissionError): abort(404) return resp
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L82-L90
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
100
9
2
100
1
def _checked_send_file(filename: Filename, mimetype: Optional[str] = None) -> Response: # NB: flask.send_file interprets relative paths relative to # current_app.root_path. We don't want that. try: resp = send_file(os.path.abspath(filename), mimetype=mimetype) except (FileNotFoundError, IsADirectoryError, PermissionError): abort(404) return resp
26,632
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
serve_artifact
(path: str)
return ArtifactServer(lektor_context).serve_artifact(path)
217
219
def serve_artifact(path: str) -> Response: lektor_context = get_lektor_context() return ArtifactServer(lektor_context).serve_artifact(path)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L217-L219
40
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
0
def serve_artifact(path: str) -> Response: lektor_context = get_lektor_context() return ArtifactServer(lektor_context).serve_artifact(path)
26,633
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
serve_file
(path: str)
return _checked_send_file(filename, mimetype=_deduce_mimetype(filename.name))
Serve file directly from Lektor's output directory.
Serve file directly from Lektor's output directory.
222
240
def serve_file(path: str) -> Response: """Serve file directly from Lektor's output directory.""" assert isinstance(current_app, LektorApp) output_path = current_app.lektor_info.output_path safe_path = safe_join("", *(path.strip("/").split("/"))) if safe_path is None: abort(404) filename = Path(output_path, safe_path) # converts safe_path to native path seps if filename.is_dir(): if not path.endswith("/"): return append_slash_redirect(request.environ) for index in filename / "index.html", filename / "index.htm": if index.is_file(): return _checked_send_file(index, mimetype="text/html") abort(404) return _checked_send_file(filename, mimetype=_deduce_mimetype(filename.name))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L222-L240
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
100
[]
0
true
100
19
7
100
1
def serve_file(path: str) -> Response: assert isinstance(current_app, LektorApp) output_path = current_app.lektor_info.output_path safe_path = safe_join("", *(path.strip("/").split("/"))) if safe_path is None: abort(404) filename = Path(output_path, safe_path) # converts safe_path to native path seps if filename.is_dir(): if not path.endswith("/"): return append_slash_redirect(request.environ) for index in filename / "index.html", filename / "index.htm": if index.is_file(): return _checked_send_file(index, mimetype="text/html") abort(404) return _checked_send_file(filename, mimetype=_deduce_mimetype(filename.name))
26,634
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
serve_artifact_or_file
(path: str)
245
251
def serve_artifact_or_file(path: str) -> Response: try: return serve_artifact(path) except HiddenRecordException: raise except NotFound: return serve_file(path)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L245-L251
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
100
7
3
100
0
def serve_artifact_or_file(path: str) -> Response: try: return serve_artifact(path) except HiddenRecordException: raise except NotFound: return serve_file(path)
26,635
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
serve_error_page
(error: NotFound)
255
259
def serve_error_page(error: NotFound) -> ResponseReturnValue: try: return serve_artifact("404.html"), 404 except NotFound: return error
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L255-L259
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
100
5
2
100
0
def serve_error_page(error: NotFound) -> ResponseReturnValue: try: return serve_artifact("404.html"), 404 except NotFound: return error
26,636
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
HiddenRecordException.__init__
(self, source: SourceObject)
96
98
def __init__(self, source: SourceObject) -> None: super().__init__(description=f"Record is hidden: {source!r}") self.source = source
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L96-L98
40
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
0
def __init__(self, source: SourceObject) -> None: super().__init__(description=f"Record is hidden: {source!r}") self.source = source
26,637
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.__init__
(self, lektor_context: LektorContext)
111
112
def __init__(self, lektor_context: LektorContext) -> None: self.lektor_ctx = lektor_context
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L111-L112
40
[ 0, 1 ]
100
[]
0
true
100
2
1
100
0
def __init__(self, lektor_context: LektorContext) -> None: self.lektor_ctx = lektor_context
26,638
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.resolve_url_path
(self, url_path: str)
return source
Resolve URL path to a source object. Raise NotFound if resolution fails.
Resolve URL path to a source object.
114
122
def resolve_url_path(self, url_path: str) -> SourceObject: """Resolve URL path to a source object. Raise NotFound if resolution fails. """ source = self.lektor_ctx.pad.resolve_url_path(url_path, include_invisible=True) if source is None: abort(404) return source
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L114-L122
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
100
9
2
100
3
def resolve_url_path(self, url_path: str) -> SourceObject: source = self.lektor_ctx.pad.resolve_url_path(url_path, include_invisible=True) if source is None: abort(404) return source
26,639
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.resolve_directory_index
(directory: Directory)
return index
Find an index.html (or equivalent) asset for a Directory asset Raise NotFound if no index is found.
Find an index.html (or equivalent) asset for a Directory asset
125
136
def resolve_directory_index(directory: Directory) -> Asset: """Find an index.html (or equivalent) asset for a Directory asset Raise NotFound if no index is found. """ for name in "index.html", "index.htm": index = directory.get_child(name, from_url=True) if index is not None: break else: abort(404) return index
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L125-L136
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
100
12
3
100
3
def resolve_directory_index(directory: Directory) -> Asset: for name in "index.html", "index.htm": index = directory.get_child(name, from_url=True) if index is not None: break else: abort(404) return index
26,640
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.build_primary_artifact
( self, source: SourceObject )
return artifact, failure
Build source object, return primary artifact. If the build was successfull, returns a tuple of (artifact, ``None``). If the build failed, returns a tuple of (artifact, failure), where failure is an instance of ``BuildFailure`` which contains information regarding the failure. Raises NotFound if no primary artifact is produced by the build process.
Build source object, return primary artifact.
138
158
def build_primary_artifact( self, source: SourceObject ) -> Tuple[Artifact, Optional[BuildFailure]]: """Build source object, return primary artifact. If the build was successfull, returns a tuple of (artifact, ``None``). If the build failed, returns a tuple of (artifact, failure), where failure is an instance of ``BuildFailure`` which contains information regarding the failure. Raises NotFound if no primary artifact is produced by the build process. """ lektor_ctx = self.lektor_ctx with lektor_ctx.cli_reporter(): prog, _ = lektor_ctx.builder.build(source) artifact = prog.primary_artifact if artifact is None: abort(404) failure = lektor_ctx.failure_controller.lookup_failure(artifact.artifact_name) return artifact, failure
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L138-L158
40
[ 0, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
47.619048
[]
0
false
100
21
3
100
9
def build_primary_artifact( self, source: SourceObject ) -> Tuple[Artifact, Optional[BuildFailure]]: lektor_ctx = self.lektor_ctx with lektor_ctx.cli_reporter(): prog, _ = lektor_ctx.builder.build(source) artifact = prog.primary_artifact if artifact is None: abort(404) failure = lektor_ctx.failure_controller.lookup_failure(artifact.artifact_name) return artifact, failure
26,641
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.handle_build_failure
( failure: BuildFailure, edit_url: Optional[str] = None )
return Response(html, mimetype="text/html")
Format build failure to an HTML response.
Format build failure to an HTML response.
161
168
def handle_build_failure( failure: BuildFailure, edit_url: Optional[str] = None ) -> Response: """Format build failure to an HTML response.""" html = render_template("build-failure.html", **failure.data).encode("utf-8") if edit_url is not None: html = _rewrite_html_for_editing(html, edit_url) return Response(html, mimetype="text/html")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L161-L168
40
[ 0, 3, 4, 5, 6, 7 ]
75
[]
0
false
100
8
2
100
1
def handle_build_failure( failure: BuildFailure, edit_url: Optional[str] = None ) -> Response: html = render_template("build-failure.html", **failure.data).encode("utf-8") if edit_url is not None: html = _rewrite_html_for_editing(html, edit_url) return Response(html, mimetype="text/html")
26,642
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.get_edit_url
(self, source: SourceObject)
return url_for("url.edit", path=record.path, alt=alt)
170
179
def get_edit_url(self, source: SourceObject) -> Optional[str]: primary_alternative = self.lektor_ctx.config.primary_alternative if not isinstance(source, Record): # Asset or VirtualSourceObject — not editable return None record = source.record alt = ( record.alt if record.alt not in (PRIMARY_ALT, primary_alternative) else None ) return url_for("url.edit", path=record.path, alt=alt)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L170-L179
40
[ 0, 1, 2, 3, 4, 5, 6, 9 ]
80
[]
0
false
100
10
2
100
0
def get_edit_url(self, source: SourceObject) -> Optional[str]: primary_alternative = self.lektor_ctx.config.primary_alternative if not isinstance(source, Record): # Asset or VirtualSourceObject — not editable return None record = source.record alt = ( record.alt if record.alt not in (PRIMARY_ALT, primary_alternative) else None ) return url_for("url.edit", path=record.path, alt=alt)
26,643
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/serve.py
ArtifactServer.serve_artifact
(self, url_path: str)
return _checked_send_file(artifact.dst_filename, mimetype=mimetype)
181
214
def serve_artifact(self, url_path: str) -> Response: source = self.resolve_url_path(url_path) # If the request path does not end with a slash but we # requested a URL that actually wants a trailing slash, we # append it. This is consistent with what apache and nginx do # and it ensures our relative urls work. if ( not url_path.endswith("/") and source.url_path.endswith("/") and source.url_path != "/" ): return append_slash_redirect(request.environ) if source.is_hidden: raise HiddenRecordException(source) if isinstance(source, Directory): # Special case for asset directories: resolve to index.html source = self.resolve_directory_index(source) edit_url = self.get_edit_url(source) artifact, failure = self.build_primary_artifact(source) # If there was a build failure for the given artifact, we want # to render this instead of sending the (most likely missing or # corrupted) file. if failure is not None: return self.handle_build_failure(failure, edit_url) mimetype = _deduce_mimetype(artifact.dst_filename) if mimetype == "text/html" and edit_url is not None: return _send_html_for_editing(artifact, edit_url, mimetype) return _checked_send_file(artifact.dst_filename, mimetype=mimetype)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/serve.py#L181-L214
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 ]
88.235294
[]
0
false
100
34
9
100
0
def serve_artifact(self, url_path: str) -> Response: source = self.resolve_url_path(url_path) # If the request path does not end with a slash but we # requested a URL that actually wants a trailing slash, we # append it. This is consistent with what apache and nginx do # and it ensures our relative urls work. if ( not url_path.endswith("/") and source.url_path.endswith("/") and source.url_path != "/" ): return append_slash_redirect(request.environ) if source.is_hidden: raise HiddenRecordException(source) if isinstance(source, Directory): # Special case for asset directories: resolve to index.html source = self.resolve_directory_index(source) edit_url = self.get_edit_url(source) artifact, failure = self.build_primary_artifact(source) # If there was a build failure for the given artifact, we want # to render this instead of sending the (most likely missing or # corrupted) file. if failure is not None: return self.handle_build_failure(failure, edit_url) mimetype = _deduce_mimetype(artifact.dst_filename) if mimetype == "text/html" and edit_url is not None: return _send_html_for_editing(artifact, edit_url, mimetype) return _checked_send_file(artifact.dst_filename, mimetype=mimetype)
26,644
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/admin/modules/dash.py
app_view
(**kwargs: Any)
return render_template( "dash.html", lektor_config={ "admin_root": request.root_path, "site_root": request.environ["lektor.site_root"], "lang": current_app.config.get("lektor.ui_lang", "en"), }, )
Render the React admin GUI app.
Render the React admin GUI app.
14
24
def app_view(**kwargs: Any) -> str: """Render the React admin GUI app.""" # Note: client side app handles redirect from page='' to page='edit' return render_template( "dash.html", lektor_config={ "admin_root": request.root_path, "site_root": request.environ["lektor.site_root"], "lang": current_app.config.get("lektor.ui_lang", "en"), }, )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/admin/modules/dash.py#L14-L24
40
[ 0, 1, 2 ]
27.272727
[ 3 ]
9.090909
false
90
11
1
90.909091
1
def app_view(**kwargs: Any) -> str: # Note: client side app handles redirect from page='' to page='edit' return render_template( "dash.html", lektor_config={ "admin_root": request.root_path, "site_root": request.environ["lektor.site_root"], "lang": current_app.config.get("lektor.ui_lang", "en"), }, )
26,645
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/fake.py
FakeType.value_from_raw
(self, raw)
return None
7
8
def value_from_raw(self, raw): return None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/fake.py#L7-L8
40
[ 0 ]
50
[ 1 ]
50
false
68.181818
2
1
50
0
def value_from_raw(self, raw): return None
26,646
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/fake.py
FakeType.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return rv
10
13
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["is_fake_type"] = True return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/fake.py#L10-L13
40
[ 0 ]
25
[ 1, 2, 3 ]
75
false
68.181818
4
1
25
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["is_fake_type"] = True return rv
26,647
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/fake.py
HeadingType.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return rv
31
34
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = FakeType.to_json(self, pad, record, alt) rv["heading_i18n"] = get_i18n_block(self.options, "heading") return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/fake.py#L31-L34
40
[ 0 ]
25
[ 1, 2, 3 ]
75
false
68.181818
4
1
25
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = FakeType.to_json(self, pad, record, alt) rv["heading_i18n"] = get_i18n_block(self.options, "heading") return rv
26,648
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
SingleInputType.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return rv
17
20
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["addon_label_i18n"] = get_i18n_block(self.options, "addon_label") or None return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L17-L20
40
[ 0, 1, 2, 3 ]
100
[]
0
true
95.327103
4
2
100
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["addon_label_i18n"] = get_i18n_block(self.options, "addon_label") or None return rv
26,649
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
StringType.value_from_raw
(self, raw)
24
30
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing string") try: return raw.value.splitlines()[0].strip() except IndexError: return ""
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L24-L30
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
95.327103
7
3
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing string") try: return raw.value.splitlines()[0].strip() except IndexError: return ""
26,650
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
StringsType.value_from_raw
(self, raw)
return [x.strip() for x in (raw.value or "").splitlines()]
36
37
def value_from_raw(self, raw): return [x.strip() for x in (raw.value or "").splitlines()]
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L36-L37
40
[ 0, 1 ]
100
[]
0
true
95.327103
2
3
100
0
def value_from_raw(self, raw): return [x.strip() for x in (raw.value or "").splitlines()]
26,651
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
TextType.value_from_raw
(self, raw)
return raw.value
43
46
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing text") return raw.value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L43-L46
40
[ 0, 1, 2, 3 ]
100
[]
0
true
95.327103
4
2
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing text") return raw.value
26,652
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
HtmlType.value_from_raw
(self, raw)
return Markup(raw.value)
52
55
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing HTML") return Markup(raw.value)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L52-L55
40
[ 0 ]
25
[ 1, 2, 3 ]
75
false
95.327103
4
2
25
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing HTML") return Markup(raw.value)
26,653
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
IntegerType.value_from_raw
(self, raw)
61
70
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing integer value") try: return int(raw.value.strip()) except ValueError: try: return int(float(raw.value.strip())) except ValueError: return raw.bad_value("Not an integer")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L61-L70
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
95.327103
10
4
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing integer value") try: return int(raw.value.strip()) except ValueError: try: return int(float(raw.value.strip())) except ValueError: return raw.bad_value("Not an integer")
26,654
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
FloatType.value_from_raw
(self, raw)
76
82
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing float value") try: return float(raw.value.strip()) except ValueError: return raw.bad_value("Not an integer")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L76-L82
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
95.327103
7
3
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing float value") try: return float(raw.value.strip()) except ValueError: return raw.bad_value("Not an integer")
26,655
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
BooleanType.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return rv
88
91
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["checkbox_label_i18n"] = get_i18n_block(self.options, "checkbox_label") return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L88-L91
40
[ 0, 1, 2, 3 ]
100
[]
0
true
95.327103
4
1
100
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["checkbox_label_i18n"] = get_i18n_block(self.options, "checkbox_label") return rv
26,656
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
BooleanType.value_from_raw
(self, raw)
return val
93
99
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing boolean") val = bool_from_string(raw.value.strip().lower()) if val is None: return raw.bad_value("Bad boolean value") return val
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L93-L99
40
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
95.327103
7
3
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing boolean") val = bool_from_string(raw.value.strip().lower()) if val is None: return raw.bad_value("Bad boolean value") return val
26,657
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
DateType.value_from_raw
(self, raw)
105
111
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing date") try: return date(*map(int, raw.value.split("-"))) except Exception: return raw.bad_value("Bad date format")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L105-L111
40
[ 0, 1, 2, 3, 4 ]
71.428571
[ 5, 6 ]
28.571429
false
95.327103
7
3
71.428571
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing date") try: return date(*map(int, raw.value.split("-"))) except Exception: return raw.bad_value("Bad date format")
26,658
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/primitives.py
DateTimeType.value_from_raw
(self, raw)
117
141
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing datetime") try: chunks = raw.value.split(" ") date_info = [int(bit) for bit in chunks[0].split("-")] time_info = [int(bit) for bit in chunks[1].split(":")] datetime_info = date_info + time_info result = datetime(*datetime_info) if len(chunks) > 2: try: tz = get_timezone(chunks[-1]) except LookupError: if len(chunks[-1]) > 5: chunks[-1] = chunks[-1][-5:] delta = int(chunks[-1][1:3]) * 60 + int(chunks[-1][3:]) if chunks[-1][0] == "-": delta *= -1 tz = FixedOffset(delta) return tz.localize(result) return result except Exception: return raw.bad_value("Bad date format")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/primitives.py#L117-L141
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 ]
100
[]
0
true
95.327103
25
9
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing datetime") try: chunks = raw.value.split(" ") date_info = [int(bit) for bit in chunks[0].split("-")] time_info = [int(bit) for bit in chunks[1].split(":")] datetime_info = date_info + time_info result = datetime(*datetime_info) if len(chunks) > 2: try: tz = get_timezone(chunks[-1]) except LookupError: if len(chunks[-1]) > 5: chunks[-1] = chunks[-1][-5:] delta = int(chunks[-1][1:3]) * 60 + int(chunks[-1][3:]) if chunks[-1][0] == "-": delta *= -1 tz = FixedOffset(delta) return tz.localize(result) return result except Exception: return raw.bad_value("Bad date format")
26,659
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
discover_relevant_flowblock_models
(flow, pad, record, alt)
return rv
Returns a dictionary of all relevant flow blocks. If no list of flow block names is provided all flow blocks are returned. Otherwise only flow blocks that are in the list or are children of flowblocks in the list are returned.
Returns a dictionary of all relevant flow blocks. If no list of flow block names is provided all flow blocks are returned. Otherwise only flow blocks that are in the list or are children of flowblocks in the list are returned.
17
51
def discover_relevant_flowblock_models(flow, pad, record, alt): """Returns a dictionary of all relevant flow blocks. If no list of flow block names is provided all flow blocks are returned. Otherwise only flow blocks that are in the list or are children of flowblocks in the list are returned. """ flow_blocks = flow.flow_blocks all_blocks = pad.db.flowblocks if flow_blocks is None: return dict((k, v.to_json(pad, record, alt)) for k, v in all_blocks.items()) wanted_blocks = set() to_process = flow_blocks[:] while to_process: block_name = to_process.pop() flowblock = all_blocks.get(block_name) if block_name in wanted_blocks or flowblock is None: continue wanted_blocks.add(block_name) for field in flowblock.fields: if isinstance(field.type, FlowType): if field.type.flow_blocks is None: raise RuntimeError( "Nested flow-blocks require explicit " "list of involved blocks." ) to_process.extend(field.type.flow_blocks) rv = {} for block_name in wanted_blocks: rv[block_name] = all_blocks[block_name].to_json(pad, record, alt) return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L17-L51
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
34.285714
[ 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 28, 30, 31, 32, 34 ]
48.571429
false
79.861111
35
9
51.428571
4
def discover_relevant_flowblock_models(flow, pad, record, alt): flow_blocks = flow.flow_blocks all_blocks = pad.db.flowblocks if flow_blocks is None: return dict((k, v.to_json(pad, record, alt)) for k, v in all_blocks.items()) wanted_blocks = set() to_process = flow_blocks[:] while to_process: block_name = to_process.pop() flowblock = all_blocks.get(block_name) if block_name in wanted_blocks or flowblock is None: continue wanted_blocks.add(block_name) for field in flowblock.fields: if isinstance(field.type, FlowType): if field.type.flow_blocks is None: raise RuntimeError( "Nested flow-blocks require explicit " "list of involved blocks." ) to_process.extend(field.type.flow_blocks) rv = {} for block_name in wanted_blocks: rv[block_name] = all_blocks[block_name].to_json(pad, record, alt) return rv
26,660
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
process_flowblock_data
(raw_value)
return blocks
155
182
def process_flowblock_data(raw_value): lineiter = iter(raw_value.splitlines(True)) block = None buf = [] blocks = [] for line in lineiter: # Until we found the first block, we ignore leading whitespace. if block is None and not line.strip(): continue # Find a new block start block_start = _block_re.match(line) if block_start is None: if block is None: raise BadFlowBlock("Did not find beginning of flow block") else: if block is not None: blocks.append((block, buf)) buf = [] block = block_start.group(1) continue buf.append(_line_unescape_re.sub("####\\1####\\2", line)) if block is not None: blocks.append((block, buf)) return blocks
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L155-L182
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
89.285714
[ 9 ]
3.571429
false
79.861111
28
8
96.428571
0
def process_flowblock_data(raw_value): lineiter = iter(raw_value.splitlines(True)) block = None buf = [] blocks = [] for line in lineiter: # Until we found the first block, we ignore leading whitespace. if block is None and not line.strip(): continue # Find a new block start block_start = _block_re.match(line) if block_start is None: if block is None: raise BadFlowBlock("Did not find beginning of flow block") else: if block is not None: blocks.append((block, buf)) buf = [] block = block_start.group(1) continue buf.append(_line_unescape_re.sub("####\\1####\\2", line)) if block is not None: blocks.append((block, buf)) return blocks
26,661
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowBlock.__init__
(self, data, pad, record)
61
65
def __init__(self, data, pad, record): self._data = data self._bound_data = {} self.pad = pad self.record = record
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L61-L65
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
79.861111
5
1
100
0
def __init__(self, data, pad, record): self._data = data self._bound_data = {} self.pad = pad self.record = record
26,662
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowBlock.flowblockmodel
(self)
return self.pad.db.flowblocks[self._data["_flowblock"]]
The flowblock model that created this flow block.
The flowblock model that created this flow block.
68
70
def flowblockmodel(self): """The flowblock model that created this flow block.""" return self.pad.db.flowblocks[self._data["_flowblock"]]
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L68-L70
40
[ 0, 1, 2 ]
100
[]
0
true
79.861111
3
1
100
1
def flowblockmodel(self): return self.pad.db.flowblocks[self._data["_flowblock"]]
26,663
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowBlock.__contains__
(self, name)
return name in self._data and not is_undefined(self._data[name])
72
73
def __contains__(self, name): return name in self._data and not is_undefined(self._data[name])
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L72-L73
40
[ 0 ]
50
[ 1 ]
50
false
79.861111
2
2
50
0
def __contains__(self, name): return name in self._data and not is_undefined(self._data[name])
26,664
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowBlock.__getitem__
(self, name)
return rv
75
89
def __getitem__(self, name): # If any data of a flowblock is accessed, we record that we need # this dependency. ctx = get_ctx() if ctx is not None: ctx.record_dependency(self.flowblockmodel.filename) rv = self._bound_data.get(name, Ellipsis) if rv is not Ellipsis: return rv rv = self._data[name] if hasattr(rv, "__get__"): rv = rv.__get__(self.record) self._bound_data[name] = rv return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L75-L89
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14 ]
93.333333
[ 9 ]
6.666667
false
79.861111
15
4
93.333333
0
def __getitem__(self, name): # If any data of a flowblock is accessed, we record that we need # this dependency. ctx = get_ctx() if ctx is not None: ctx.record_dependency(self.flowblockmodel.filename) rv = self._bound_data.get(name, Ellipsis) if rv is not Ellipsis: return rv rv = self._data[name] if hasattr(rv, "__get__"): rv = rv.__get__(self.record) self._bound_data[name] = rv return rv
26,665
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowBlock.__html__
(self)
91
115
def __html__(self): ctx = get_ctx() # If we're in a nested render, we disable the rendering here or we # risk a recursion error. if ctx is None or self in ctx.flow_block_render_stack: return Markup.escape(repr(self)) ctx.flow_block_render_stack.append(self) try: try: return self.pad.db.env.render_template( [ "blocks/%s.html" % self._data["_flowblock"], "blocks/default.html", ], pad=self.pad, this=self, alt=self.record.alt, values={"record": self.record}, ) except TemplateNotFound: return Markup("[could not find snippet template]") finally: ctx.flow_block_render_stack.pop()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L91-L115
40
[ 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 24 ]
48
[ 6, 21, 22 ]
12
false
79.861111
25
4
88
0
def __html__(self): ctx = get_ctx() # If we're in a nested render, we disable the rendering here or we # risk a recursion error. if ctx is None or self in ctx.flow_block_render_stack: return Markup.escape(repr(self)) ctx.flow_block_render_stack.append(self) try: try: return self.pad.db.env.render_template( [ "blocks/%s.html" % self._data["_flowblock"], "blocks/default.html", ], pad=self.pad, this=self, alt=self.record.alt, values={"record": self.record}, ) except TemplateNotFound: return Markup("[could not find snippet template]") finally: ctx.flow_block_render_stack.pop()
26,666
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowBlock.__repr__
(self)
return "<%s %r>" % ( self.__class__.__name__, self["_flowblock"], )
117
121
def __repr__(self): return "<%s %r>" % ( self.__class__.__name__, self["_flowblock"], )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L117-L121
40
[ 0 ]
20
[ 1 ]
20
false
79.861111
5
1
80
0
def __repr__(self): return "<%s %r>" % ( self.__class__.__name__, self["_flowblock"], )
26,667
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
Flow.__init__
(self, blocks, record)
125
127
def __init__(self, blocks, record): self.blocks = blocks self.record = record
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L125-L127
40
[ 0, 1, 2 ]
100
[]
0
true
79.861111
3
1
100
0
def __init__(self, blocks, record): self.blocks = blocks self.record = record
26,668
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
Flow.__html__
(self)
return Markup("\n\n".join(x.__html__() for x in self.blocks))
129
130
def __html__(self): return Markup("\n\n".join(x.__html__() for x in self.blocks))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L129-L130
40
[ 0, 1 ]
100
[]
0
true
79.861111
2
1
100
0
def __html__(self): return Markup("\n\n".join(x.__html__() for x in self.blocks))
26,669
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
Flow.__bool__
(self)
return bool(self.blocks)
132
133
def __bool__(self): return bool(self.blocks)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L132-L133
40
[ 0 ]
50
[ 1 ]
50
false
79.861111
2
1
50
0
def __bool__(self): return bool(self.blocks)
26,670
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
Flow.__repr__
(self)
return "<%s %r>" % ( self.__class__.__name__, self.blocks, )
137
141
def __repr__(self): return "<%s %r>" % ( self.__class__.__name__, self.blocks, )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L137-L141
40
[ 0 ]
20
[ 1 ]
20
false
79.861111
5
1
80
0
def __repr__(self): return "<%s %r>" % ( self.__class__.__name__, self.blocks, )
26,671
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowDescriptor.__init__
(self, blocks, pad)
145
147
def __init__(self, blocks, pad): self._blocks = blocks self._pad = pad
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L145-L147
40
[ 0, 1, 2 ]
100
[]
0
true
79.861111
3
1
100
0
def __init__(self, blocks, pad): self._blocks = blocks self._pad = pad
26,672
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowDescriptor.__get__
(self, obj, type=None)
return Flow([FlowBlock(data, self._pad, obj) for data in self._blocks], obj)
149
152
def __get__(self, obj, type=None): if obj is None: return self return Flow([FlowBlock(data, self._pad, obj) for data in self._blocks], obj)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L149-L152
40
[ 0, 1, 3 ]
75
[ 2 ]
25
false
79.861111
4
3
75
0
def __get__(self, obj, type=None): if obj is None: return self return Flow([FlowBlock(data, self._pad, obj) for data in self._blocks], obj)
26,673
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowType.__init__
(self, env, options)
188
192
def __init__(self, env, options): Type.__init__(self, env, options) self.flow_blocks = [ x.strip() for x in options.get("flow_blocks", "").split(",") if x.strip() ] or None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L188-L192
40
[ 0, 1, 2 ]
60
[]
0
false
79.861111
5
3
100
0
def __init__(self, env, options): Type.__init__(self, env, options) self.flow_blocks = [ x.strip() for x in options.get("flow_blocks", "").split(",") if x.strip() ] or None
26,674
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowType.value_from_raw
(self, raw)
return FlowDescriptor(rv, raw.pad)
194
223
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing flow") if raw.pad is None: return raw.missing_value( "Flow value was technically present " "but used in a place where it cannot " "be used." ) db = raw.pad.db rv = [] try: for block, block_lines in process_flowblock_data(raw.value): # Unknown flow blocks are skipped for the moment if self.flow_blocks is not None and block not in self.flow_blocks: continue flowblock = db.flowblocks.get(block) if flowblock is None: continue d = {} for key, lines in tokenize(block_lines): d[key] = "".join(lines) rv.append(flowblock.process_raw_data(d, pad=raw.pad)) except BadFlowBlock as e: return raw.bad_value(str(e)) return FlowDescriptor(rv, raw.pad)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L194-L223
40
[ 0, 1, 2, 3, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ]
80
[ 4, 17 ]
6.666667
false
79.861111
30
9
93.333333
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing flow") if raw.pad is None: return raw.missing_value( "Flow value was technically present " "but used in a place where it cannot " "be used." ) db = raw.pad.db rv = [] try: for block, block_lines in process_flowblock_data(raw.value): # Unknown flow blocks are skipped for the moment if self.flow_blocks is not None and block not in self.flow_blocks: continue flowblock = db.flowblocks.get(block) if flowblock is None: continue d = {} for key, lines in tokenize(block_lines): d[key] = "".join(lines) rv.append(flowblock.process_raw_data(d, pad=raw.pad)) except BadFlowBlock as e: return raw.bad_value(str(e)) return FlowDescriptor(rv, raw.pad)
26,675
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/flow.py
FlowType.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return rv
225
238
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["flowblocks"] = discover_relevant_flowblock_models(self, pad, record, alt) block_order = self.flow_blocks if block_order is None: block_order = [ k for k, v in sorted(pad.db.flowblocks.items(), key=lambda x: x[1].order) ] rv["flowblock_order"] = block_order return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/flow.py#L225-L238
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13 ]
78.571429
[]
0
false
79.861111
14
3
100
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) rv["flowblocks"] = discover_relevant_flowblock_models(self, pad, record, alt) block_order = self.flow_blocks if block_order is None: block_order = [ k for k, v in sorted(pad.db.flowblocks.items(), key=lambda x: x[1].order) ] rv["flowblock_order"] = block_order return rv
26,676
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
get_undefined_info
(undefined)
return "defined value"
10
16
def get_undefined_info(undefined): if isinstance(undefined, Undefined): try: undefined._fail_with_undefined_error() except Exception as e: return str(e) return "defined value"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L10-L16
40
[ 0 ]
14.285714
[ 1, 2, 3, 4, 5, 6 ]
85.714286
false
82.758621
7
3
14.285714
0
def get_undefined_info(undefined): if isinstance(undefined, Undefined): try: undefined._fail_with_undefined_error() except Exception as e: return str(e) return "defined value"
26,677
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
RawValue.__init__
(self, name, value=None, field=None, pad=None)
22
26
def __init__(self, name, value=None, field=None, pad=None): self.name = name self.value = value self.field = field self.pad = pad
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L22-L26
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
82.758621
5
1
100
0
def __init__(self, name, value=None, field=None, pad=None): self.name = name self.value = value self.field = field self.pad = pad
26,678
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
RawValue._get_hint
(self, prefix, reason)
return "%s: %s" % (prefix, reason)
28
31
def _get_hint(self, prefix, reason): if self.field is not None: return "%s in field '%s': %s" % (prefix, self.field.name, reason) return "%s: %s" % (prefix, reason)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L28-L31
40
[ 0, 1, 2 ]
75
[ 3 ]
25
false
82.758621
4
2
75
0
def _get_hint(self, prefix, reason): if self.field is not None: return "%s in field '%s': %s" % (prefix, self.field.name, reason) return "%s: %s" % (prefix, reason)
26,679
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
RawValue.bad_value
(self, reason)
return BadValue(hint=self._get_hint("Bad value", reason), obj=self.value)
33
34
def bad_value(self, reason): return BadValue(hint=self._get_hint("Bad value", reason), obj=self.value)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L33-L34
40
[ 0, 1 ]
100
[]
0
true
82.758621
2
1
100
0
def bad_value(self, reason): return BadValue(hint=self._get_hint("Bad value", reason), obj=self.value)
26,680
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
RawValue.missing_value
(self, reason)
return Undefined(hint=self._get_hint("Missing value", reason), obj=self.value)
36
37
def missing_value(self, reason): return Undefined(hint=self._get_hint("Missing value", reason), obj=self.value)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L36-L37
40
[ 0, 1 ]
100
[]
0
true
82.758621
2
1
100
0
def missing_value(self, reason): return Undefined(hint=self._get_hint("Missing value", reason), obj=self.value)
26,681
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
_NameDescriptor.__get__
(self, obj, type)
return rv.lower()
41
45
def __get__(self, obj, type): rv = type.__name__ if rv.endswith("Type"): rv = rv[:-4] return rv.lower()
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L41-L45
40
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
82.758621
5
2
100
0
def __get__(self, obj, type): rv = type.__name__ if rv.endswith("Type"): rv = rv[:-4] return rv.lower()
26,682
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.__init__
(self, env, options)
51
53
def __init__(self, env, options): self.env = env self.options = options
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L51-L53
40
[ 0, 1, 2 ]
100
[]
0
true
82.758621
3
1
100
0
def __init__(self, env, options): self.env = env self.options = options
26,683
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.size
(self)
return size
56
60
def size(self): size = self.options.get("size") or "normal" if size not in ("normal", "small", "large"): size = "normal" return size
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L56-L60
40
[ 0, 1, 2, 4 ]
80
[ 3 ]
20
false
82.758621
5
3
80
0
def size(self): size = self.options.get("size") or "normal" if size not in ("normal", "small", "large"): size = "normal" return size
26,684
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.width
(self)
return self.options.get("width") or "1/1"
63
64
def width(self): return self.options.get("width") or "1/1"
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L63-L64
40
[ 0, 1 ]
100
[]
0
true
82.758621
2
2
100
0
def width(self): return self.options.get("width") or "1/1"
26,685
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return { "name": self.name, "widget": self.widget, "size": self.size, "width": self.width, }
68
74
def to_json(self, pad, record=None, alt=PRIMARY_ALT): return { "name": self.name, "widget": self.widget, "size": self.size, "width": self.width, }
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L68-L74
40
[ 0, 1 ]
28.571429
[]
0
false
82.758621
7
1
100
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): return { "name": self.name, "widget": self.widget, "size": self.size, "width": self.width, }
26,686
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.value_from_raw
(self, raw)
return raw
76
78
def value_from_raw(self, raw): # pylint: disable=no-self-use return raw
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L76-L78
40
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
82.758621
3
1
66.666667
0
def value_from_raw(self, raw): # pylint: disable=no-self-use return raw
26,687
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.value_from_raw_with_default
(self, raw)
return value
80
90
def value_from_raw_with_default(self, raw): value = self.value_from_raw(raw) if ( isinstance(value, Undefined) and raw.field is not None and raw.field.default is not None ): return self.value_from_raw( RawValue(raw.name, raw.field.default, field=raw.field, pad=raw.pad) ) return value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L80-L90
40
[ 0, 1, 2, 7, 10 ]
45.454545
[]
0
false
82.758621
11
4
100
0
def value_from_raw_with_default(self, raw): value = self.value_from_raw(raw) if ( isinstance(value, Undefined) and raw.field is not None and raw.field.default is not None ): return self.value_from_raw( RawValue(raw.name, raw.field.default, field=raw.field, pad=raw.pad) ) return value
26,688
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/base.py
Type.__repr__
(self)
return "%s()" % self.__class__.__name__
92
93
def __repr__(self): return "%s()" % self.__class__.__name__
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/base.py#L92-L93
40
[ 0 ]
50
[ 1 ]
50
false
82.758621
2
1
50
0
def __repr__(self): return "%s()" % self.__class__.__name__
26,689
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
_reflow_and_split_labels
(labels)
return rv
10
20
def _reflow_and_split_labels(labels): rv = [] for lang, string in labels.items(): for idx, item in enumerate(string.split(",")): try: d = rv[idx] except LookupError: d = {} rv.append(d) d[lang] = item.strip() return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L10-L20
40
[ 0 ]
9.090909
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
90.909091
false
22.330097
11
4
9.090909
0
def _reflow_and_split_labels(labels): rv = [] for lang, string in labels.items(): for idx, item in enumerate(string.split(",")): try: d = rv[idx] except LookupError: d = {} rv.append(d) d[lang] = item.strip() return rv
26,690
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
_parse_choices
(options)
return rv
23
50
def _parse_choices(options): s = options.get("choices") if not s: return None choices = [] items = s.split(",") user_labels = get_i18n_block(options, "choice_labels") implied_labels = [] for item in items: if "=" in item: choice, value = item.split("=", 1) choice = choice.strip() if choice.isdigit(): choice = int(choice) implied_labels.append(value.strip()) choices.append(choice) else: choices.append(item.strip()) implied_labels.append(item.strip()) if user_labels: rv = list(zip(choices, _reflow_and_split_labels(user_labels))) else: rv = [(key, {"en": label}) for key, label in zip(choices, implied_labels)] return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L23-L50
40
[ 0 ]
3.571429
[ 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 22, 23, 25, 27 ]
75
false
22.330097
28
7
25
0
def _parse_choices(options): s = options.get("choices") if not s: return None choices = [] items = s.split(",") user_labels = get_i18n_block(options, "choice_labels") implied_labels = [] for item in items: if "=" in item: choice, value = item.split("=", 1) choice = choice.strip() if choice.isdigit(): choice = int(choice) implied_labels.append(value.strip()) choices.append(choice) else: choices.append(item.strip()) implied_labels.append(item.strip()) if user_labels: rv = list(zip(choices, _reflow_and_split_labels(user_labels))) else: rv = [(key, {"en": label}) for key, label in zip(choices, implied_labels)] return rv
26,691
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
ChoiceSource.__init__
(self, env, options)
54
69
def __init__(self, env, options): source = options.get("source") if source is not None: self.source = Expression(env, source) self.choices = None item_key = options.get("item_key") or "{{ this._id }}" item_label = options.get("item_label") else: self.source = None self.choices = _parse_choices(options) item_key = options.get("item_key") or "{{ this.0 }}" item_label = options.get("item_label") self.item_key = FormatExpression(env, item_key) if item_label is not None: item_label = FormatExpression(env, item_label) self.item_label = item_label
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L54-L69
40
[ 0 ]
6.25
[ 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15 ]
87.5
false
22.330097
16
5
12.5
0
def __init__(self, env, options): source = options.get("source") if source is not None: self.source = Expression(env, source) self.choices = None item_key = options.get("item_key") or "{{ this._id }}" item_label = options.get("item_label") else: self.source = None self.choices = _parse_choices(options) item_key = options.get("item_key") or "{{ this.0 }}" item_label = options.get("item_label") self.item_key = FormatExpression(env, item_key) if item_label is not None: item_label = FormatExpression(env, item_label) self.item_label = item_label
26,692
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
ChoiceSource.has_choices
(self)
return self.source is not None or self.choices is not None
72
73
def has_choices(self): return self.source is not None or self.choices is not None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L72-L73
40
[ 0 ]
50
[ 1 ]
50
false
22.330097
2
2
50
0
def has_choices(self): return self.source is not None or self.choices is not None
26,693
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
ChoiceSource.iter_choices
(self, pad, record=None, alt=PRIMARY_ALT)
75
111
def iter_choices(self, pad, record=None, alt=PRIMARY_ALT): values = {} if record is not None: values["record"] = record if self.choices is not None: iterable = self.choices else: try: iterable = self.source.evaluate(pad, alt=alt, values=values) except Exception: traceback.print_exc() iterable = () for item in iterable or (): key = self.item_key.evaluate(pad, this=item, alt=alt, values=values) # If there is a label expression, use it. Since in that case # we only have one language to fill in, we fill it in for the # default language if self.item_label is not None: label = { "en": self.item_label.evaluate( pad, this=item, alt=alt, values=values ) } # Otherwise we create a proper internationalized key out of # our target label else: if isinstance(item, (tuple, list)) and len(item) == 2: label = item[1] elif hasattr(item, "get_record_label_i18n"): label = item.get_record_label_i18n() else: label = {"en": item["_id"]} yield key, label
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L75-L111
40
[ 0 ]
2.702703
[ 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 19, 20, 29, 30, 31, 32, 34, 36 ]
54.054054
false
22.330097
37
10
45.945946
0
def iter_choices(self, pad, record=None, alt=PRIMARY_ALT): values = {} if record is not None: values["record"] = record if self.choices is not None: iterable = self.choices else: try: iterable = self.source.evaluate(pad, alt=alt, values=values) except Exception: traceback.print_exc() iterable = () for item in iterable or (): key = self.item_key.evaluate(pad, this=item, alt=alt, values=values) # If there is a label expression, use it. Since in that case # we only have one language to fill in, we fill it in for the # default language if self.item_label is not None: label = { "en": self.item_label.evaluate( pad, this=item, alt=alt, values=values ) } # Otherwise we create a proper internationalized key out of # our target label else: if isinstance(item, (tuple, list)) and len(item) == 2: label = item[1] elif hasattr(item, "get_record_label_i18n"): label = item.get_record_label_i18n() else: label = {"en": item["_id"]} yield key, label
26,694
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
MultiType.__init__
(self, env, options)
115
117
def __init__(self, env, options): Type.__init__(self, env, options) self.source = ChoiceSource(env, options)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L115-L117
40
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
22.330097
3
1
33.333333
0
def __init__(self, env, options): Type.__init__(self, env, options) self.source = ChoiceSource(env, options)
26,695
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
MultiType.get_labels
(self, pad, record=None, alt=PRIMARY_ALT)
return dict(self.source.iter_choices(pad, record, alt))
119
120
def get_labels(self, pad, record=None, alt=PRIMARY_ALT): return dict(self.source.iter_choices(pad, record, alt))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L119-L120
40
[ 0 ]
50
[ 1 ]
50
false
22.330097
2
1
50
0
def get_labels(self, pad, record=None, alt=PRIMARY_ALT): return dict(self.source.iter_choices(pad, record, alt))
26,696
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
MultiType.to_json
(self, pad, record=None, alt=PRIMARY_ALT)
return rv
122
126
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) if self.source.has_choices: rv["choices"] = list(self.source.iter_choices(pad, record, alt)) return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L122-L126
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
22.330097
5
2
20
0
def to_json(self, pad, record=None, alt=PRIMARY_ALT): rv = Type.to_json(self, pad, record, alt) if self.source.has_choices: rv["choices"] = list(self.source.iter_choices(pad, record, alt)) return rv
26,697
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
SelectType.value_from_raw
(self, raw)
return raw.value
132
135
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing select value") return raw.value
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L132-L135
40
[ 0 ]
25
[ 1, 2, 3 ]
75
false
22.330097
4
2
25
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing select value") return raw.value
26,698
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/multi.py
CheckboxesType.value_from_raw
(self, raw)
return rv
141
145
def value_from_raw(self, raw): rv = [x.strip() for x in (raw.value or "").split(",")] if rv == [""]: rv = [] return rv
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/multi.py#L141-L145
40
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
22.330097
5
4
20
0
def value_from_raw(self, raw): rv = [x.strip() for x in (raw.value or "").split(",")] if rv == [""]: rv = [] return rv
26,699
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/formats.py
_check_option
(options, name, choices)
29
35
def _check_option(options, name, choices): value = options.get(name) if value is not None and value not in choices: warn( f"Unrecognized value {value!r} for the {name!r} markdown field option. " f"Valid values are: {', '.join(repr(_) for _ in choices)}." )
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/formats.py#L29-L35
40
[ 0, 1, 2, 3 ]
57.142857
[]
0
false
95.454545
7
3
100
0
def _check_option(options, name, choices): value = options.get(name) if value is not None and value not in choices: warn( f"Unrecognized value {value!r} for the {name!r} markdown field option. " f"Valid values are: {', '.join(repr(_) for _ in choices)}." )
26,700
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/formats.py
MarkdownDescriptor.__init__
(self, source, options)
8
10
def __init__(self, source, options): self.source = source self.options = options
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/formats.py#L8-L10
40
[ 0, 1, 2 ]
100
[]
0
true
95.454545
3
1
100
0
def __init__(self, source, options): self.source = source self.options = options
26,701
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/formats.py
MarkdownDescriptor.__get__
(self, obj, type=None)
return Markdown(self.source, record=obj, field_options=self.options)
12
15
def __get__(self, obj, type=None): if obj is None: return self return Markdown(self.source, record=obj, field_options=self.options)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/formats.py#L12-L15
40
[ 0, 1, 3 ]
75
[ 2 ]
25
false
95.454545
4
2
75
0
def __get__(self, obj, type=None): if obj is None: return self return Markdown(self.source, record=obj, field_options=self.options)
26,702
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/formats.py
MarkdownType.__init__
(self, env, options)
21
23
def __init__(self, env, options): super().__init__(env, options) _check_option(options, "resolve_links", ("always", "never", "when-possible"))
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/formats.py#L21-L23
40
[ 0, 1, 2 ]
100
[]
0
true
95.454545
3
1
100
0
def __init__(self, env, options): super().__init__(env, options) _check_option(options, "resolve_links", ("always", "never", "when-possible"))
26,703
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/formats.py
MarkdownType.value_from_raw
(self, raw)
return MarkdownDescriptor(raw.value or "", self.options)
25
26
def value_from_raw(self, raw): return MarkdownDescriptor(raw.value or "", self.options)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/formats.py#L25-L26
40
[ 0, 1 ]
100
[]
0
true
95.454545
2
2
100
0
def value_from_raw(self, raw): return MarkdownDescriptor(raw.value or "", self.options)
26,704
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/special.py
SortKeyType.value_from_raw
(self, raw)
9
15
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing sort key") try: return int(raw.value.strip()) except ValueError: return raw.bad_value("Bad sort key value")
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/special.py#L9-L15
40
[ 0 ]
14.285714
[ 1, 2, 3, 4, 5, 6 ]
85.714286
false
70.833333
7
3
14.285714
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing sort key") try: return int(raw.value.strip()) except ValueError: return raw.bad_value("Bad sort key value")
26,705
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/special.py
SlugType.value_from_raw
(self, raw)
return slugify(raw.value)
21
24
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing slug") return slugify(raw.value)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/special.py#L21-L24
40
[ 0, 1, 2, 3 ]
100
[]
0
true
70.833333
4
2
100
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing slug") return slugify(raw.value)
26,706
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/types/special.py
UrlType.value_from_raw
(self, raw)
return Url(raw.value)
30
33
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing URL") return Url(raw.value)
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/types/special.py#L30-L33
40
[ 0, 1, 3 ]
75
[ 2 ]
25
false
70.833333
4
2
75
0
def value_from_raw(self, raw): if raw.value is None: return raw.missing_value("Missing URL") return Url(raw.value)
26,707
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/markdown/controller.py
require_ctx
()
return ctx
Get Lektor build context, raising error if there is no current context.
Get Lektor build context, raising error if there is no current context.
37
42
def require_ctx() -> Context: """Get Lektor build context, raising error if there is no current context.""" ctx = get_ctx() if ctx is None: raise RuntimeError("Context is required for markdown rendering") return ctx
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/markdown/controller.py#L37-L42
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
100
6
2
100
1
def require_ctx() -> Context: ctx = get_ctx() if ctx is None: raise RuntimeError("Context is required for markdown rendering") return ctx
26,708
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/markdown/controller.py
get_renderer_context
()
return _threadlocal.renderer_context
61
64
def get_renderer_context() -> RendererContext: if _threadlocal.renderer_context is None: raise RuntimeError("RendererContext is required for markdown rendering") return _threadlocal.renderer_context
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/markdown/controller.py#L61-L64
40
[ 0, 1, 2, 3 ]
100
[]
0
true
100
4
2
100
0
def get_renderer_context() -> RendererContext: if _threadlocal.renderer_context is None: raise RuntimeError("RendererContext is required for markdown rendering") return _threadlocal.renderer_context
26,709
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/markdown/controller.py
RendererContext.__enter__
(self)
return self
52
55
def __enter__(self) -> "RendererContext": assert _threadlocal.renderer_context is None _threadlocal.renderer_context = self return self
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/markdown/controller.py#L52-L55
40
[ 0, 1, 2, 3 ]
100
[]
0
true
100
4
2
100
0
def __enter__(self) -> "RendererContext": assert _threadlocal.renderer_context is None _threadlocal.renderer_context = self return self
26,710
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/markdown/controller.py
RendererContext.__exit__
(self, *__: Any)
57
58
def __exit__(self, *__: Any) -> None: _threadlocal.renderer_context = None
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/markdown/controller.py#L57-L58
40
[ 0, 1 ]
100
[]
0
true
100
2
1
100
0
def __exit__(self, *__: Any) -> None: _threadlocal.renderer_context = None
26,711
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/markdown/controller.py
RendererHelper.record
(self)
return get_renderer_context().record
The record that owns the markdown field being rendered. This is used as the base for resolving relative URLs in the Markdown text.
The record that owns the markdown field being rendered.
71
76
def record(self) -> SourceObject: """The record that owns the markdown field being rendered. This is used as the base for resolving relative URLs in the Markdown text. """ return get_renderer_context().record
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/markdown/controller.py#L71-L76
40
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
100
6
1
100
3
def record(self) -> SourceObject: return get_renderer_context().record
26,712
lektor/lektor
74bce9096116caffe27ab69327ed4ba274e66e1e
lektor/markdown/controller.py
RendererHelper.meta
(self)
return get_renderer_context().meta
The metadata for the current render. This is a dict and is used to return metadata from the rendering process. Currently, Lektor itself never generates any metadata, but custom Lektor plugins can do so by updating this dict. Values inserted into this dict during the rendering process may be accessed in jinja templates via the ``.meta`` attribute of the _markdown_ field.
The metadata for the current render.
79
91
def meta(self) -> Meta: """The metadata for the current render. This is a dict and is used to return metadata from the rendering process. Currently, Lektor itself never generates any metadata, but custom Lektor plugins can do so by updating this dict. Values inserted into this dict during the rendering process may be accessed in jinja templates via the ``.meta`` attribute of the _markdown_ field. """ return get_renderer_context().meta
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/markdown/controller.py#L79-L91
40
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
100
13
1
100
10
def meta(self) -> Meta: return get_renderer_context().meta
26,713