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/datamodel.py
|
PaginationConfig.slice_query_for_page
|
(self, record, page)
|
return query.limit(self.per_page).offset((page - 1) * self.per_page)
|
Slices the query so it returns the children for a given page.
|
Slices the query so it returns the children for a given page.
| 80 | 85 |
def slice_query_for_page(self, record, page):
"""Slices the query so it returns the children for a given page."""
query = self.get_pagination_query(record)
if not self.enabled or page is None:
return query
return query.limit(self.per_page).offset((page - 1) * self.per_page)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L80-L85
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 93.783784 | 6 | 3 | 100 | 1 |
def slice_query_for_page(self, record, page):
query = self.get_pagination_query(record)
if not self.enabled or page is None:
return query
return query.limit(self.per_page).offset((page - 1) * self.per_page)
| 26,014 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
PaginationConfig.get_record_for_page
|
(record, page_num)
|
return rv
|
Given a normal record this one returns the version specific
for a page.
|
Given a normal record this one returns the version specific
for a page.
| 88 | 106 |
def get_record_for_page(record, page_num):
"""Given a normal record this one returns the version specific
for a page.
"""
# If we already have the right version, return it.
if record.page_num == page_num:
return record
# Check if we have a cached version
pad = record.pad
rv = pad.cache.get(record.path, record.alt, str(page_num))
if rv is not Ellipsis:
return rv
# Make what we need out of what we have and put it into the cache.
cls = record.__class__
rv = cls(record.pad, record._data, page_num=page_num)
pad.cache.remember(rv)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L88-L106
| 40 |
[
0,
1,
2,
3,
4,
5,
8,
9,
10,
11,
14,
15,
16,
17,
18
] | 78.947368 |
[
6,
12
] | 10.526316 | false | 93.783784 | 19 | 3 | 89.473684 | 2 |
def get_record_for_page(record, page_num):
# If we already have the right version, return it.
if record.page_num == page_num:
return record
# Check if we have a cached version
pad = record.pad
rv = pad.cache.get(record.path, record.alt, str(page_num))
if rv is not Ellipsis:
return rv
# Make what we need out of what we have and put it into the cache.
cls = record.__class__
rv = cls(record.pad, record._data, page_num=page_num)
pad.cache.remember(rv)
return rv
| 26,015 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
PaginationConfig.match_pagination
|
(self, record, url_path)
|
return None
|
Matches the pagination from the URL path.
|
Matches the pagination from the URL path.
| 108 | 130 |
def match_pagination(self, record, url_path):
"""Matches the pagination from the URL path."""
if not self.enabled:
return None
suffixes = self.url_suffix.strip("/").split("/")
if url_path[: len(suffixes)] != suffixes:
return None
try:
page_num = int(url_path[len(suffixes)])
except (ValueError, IndexError):
return None
# It's important we do not allow "1" here as the first page is always
# on the root. Changing this would mean the URLs are incorrectly
# generated if someone manually went to /page/1/.
if page_num == 1 or len(url_path) != len(suffixes) + 1:
return None
# Page needs to have at least a single child.
rv = self.get_record_for_page(record, page_num)
if rv.pagination.items.first() is not None:
return rv
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L108-L130
| 40 |
[
0,
1,
2,
4,
5,
6,
7,
8,
14,
15,
16,
17,
18,
19,
20,
21
] | 69.565217 |
[
3,
9,
10,
22
] | 17.391304 | false | 93.783784 | 23 | 7 | 82.608696 | 1 |
def match_pagination(self, record, url_path):
if not self.enabled:
return None
suffixes = self.url_suffix.strip("/").split("/")
if url_path[: len(suffixes)] != suffixes:
return None
try:
page_num = int(url_path[len(suffixes)])
except (ValueError, IndexError):
return None
# It's important we do not allow "1" here as the first page is always
# on the root. Changing this would mean the URLs are incorrectly
# generated if someone manually went to /page/1/.
if page_num == 1 or len(url_path) != len(suffixes) + 1:
return None
# Page needs to have at least a single child.
rv = self.get_record_for_page(record, page_num)
if rv.pagination.items.first() is not None:
return rv
return None
| 26,016 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
PaginationConfig.get_pagination_controller
|
(self, record)
|
return Pagination(record, self)
| 132 | 135 |
def get_pagination_controller(self, record):
if not self.enabled:
raise RuntimeError("Pagination is disabled")
return Pagination(record, self)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L132-L135
| 40 |
[
0,
1,
3
] | 75 |
[
2
] | 25 | false | 93.783784 | 4 | 2 | 75 | 0 |
def get_pagination_controller(self, record):
if not self.enabled:
raise RuntimeError("Pagination is disabled")
return Pagination(record, self)
| 26,017 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
PaginationConfig.get_pagination_query
|
(self, record)
|
return self._items_tmpl[1].evaluate(record.pad, this=record)
| 137 | 144 |
def get_pagination_query(self, record):
items_expr = self.items
if items_expr is None:
return record.children
if self._items_tmpl is None or self._items_tmpl[0] != items_expr:
self._items_tmpl = (items_expr, Expression(self.env, items_expr))
return self._items_tmpl[1].evaluate(record.pad, this=record)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L137-L144
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 93.783784 | 8 | 4 | 100 | 0 |
def get_pagination_query(self, record):
items_expr = self.items
if items_expr is None:
return record.children
if self._items_tmpl is None or self._items_tmpl[0] != items_expr:
self._items_tmpl = (items_expr, Expression(self.env, items_expr))
return self._items_tmpl[1].evaluate(record.pad, this=record)
| 26,018 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
PaginationConfig.to_json
|
(self)
|
return {
"enabled": self.enabled,
"per_page": self.per_page,
"url_suffix": self.url_suffix,
"items": self.items,
}
| 146 | 152 |
def to_json(self):
return {
"enabled": self.enabled,
"per_page": self.per_page,
"url_suffix": self.url_suffix,
"items": self.items,
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L146-L152
| 40 |
[
0,
1
] | 28.571429 |
[] | 0 | false | 93.783784 | 7 | 1 | 100 | 0 |
def to_json(self):
return {
"enabled": self.enabled,
"per_page": self.per_page,
"url_suffix": self.url_suffix,
"items": self.items,
}
| 26,019 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
AttachmentConfig.__init__
|
(self, enabled=None, model=None, order_by=None, hidden=None)
| 156 | 164 |
def __init__(self, enabled=None, model=None, order_by=None, hidden=None):
if enabled is None:
enabled = True
if hidden is None:
hidden = False
self.enabled = enabled
self.model = model
self.order_by = order_by
self.hidden = hidden
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L156-L164
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 93.783784 | 9 | 3 | 100 | 0 |
def __init__(self, enabled=None, model=None, order_by=None, hidden=None):
if enabled is None:
enabled = True
if hidden is None:
hidden = False
self.enabled = enabled
self.model = model
self.order_by = order_by
self.hidden = hidden
| 26,020 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
AttachmentConfig.to_json
|
(self)
|
return {
"enabled": self.enabled,
"model": self.model,
"order_by": self.order_by,
"hidden": self.hidden,
}
| 166 | 172 |
def to_json(self):
return {
"enabled": self.enabled,
"model": self.model,
"order_by": self.order_by,
"hidden": self.hidden,
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L166-L172
| 40 |
[
0,
1
] | 28.571429 |
[] | 0 | false | 93.783784 | 7 | 1 | 100 | 0 |
def to_json(self):
return {
"enabled": self.enabled,
"model": self.model,
"order_by": self.order_by,
"hidden": self.hidden,
}
| 26,021 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
Field.__init__
|
(self, env, name, type=None, options=None)
| 176 | 189 |
def __init__(self, env, name, type=None, options=None):
if type is None:
type = env.types["string"]
if options is None:
options = {}
self.options = options
self.name = name
label_i18n = get_i18n_block(options, "label")
if not label_i18n:
label_i18n = {"en": name.replace("_", " ").strip().capitalize()}
self.label_i18n = label_i18n
self.description_i18n = get_i18n_block(options, "description") or None
self.default = options.get("default")
self.type = type(env, options)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L176-L189
| 40 |
[
0,
1,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
] | 92.857143 |
[
2
] | 7.142857 | false | 93.783784 | 14 | 5 | 92.857143 | 0 |
def __init__(self, env, name, type=None, options=None):
if type is None:
type = env.types["string"]
if options is None:
options = {}
self.options = options
self.name = name
label_i18n = get_i18n_block(options, "label")
if not label_i18n:
label_i18n = {"en": name.replace("_", " ").strip().capitalize()}
self.label_i18n = label_i18n
self.description_i18n = get_i18n_block(options, "description") or None
self.default = options.get("default")
self.type = type(env, options)
| 26,022 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
Field.label
|
(self)
|
return self.label_i18n.get("en")
| 192 | 193 |
def label(self):
return self.label_i18n.get("en")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L192-L193
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.783784 | 2 | 1 | 100 | 0 |
def label(self):
return self.label_i18n.get("en")
| 26,023 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
Field.to_json
|
(self, pad, record=None, alt=PRIMARY_ALT)
|
return {
"name": self.name,
"label": self.label,
"label_i18n": self.label_i18n,
"hide_label": bool_from_string(
self.options.get("hide_label"), default=False
),
"description_i18n": self.description_i18n,
"type": self.type.to_json(pad, record, alt),
"default": self.default,
"alts_enabled": bool_from_string(
self.options.get("alts_enabled"), default=None
),
}
| 195 | 209 |
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
"name": self.name,
"label": self.label,
"label_i18n": self.label_i18n,
"hide_label": bool_from_string(
self.options.get("hide_label"), default=False
),
"description_i18n": self.description_i18n,
"type": self.type.to_json(pad, record, alt),
"default": self.default,
"alts_enabled": bool_from_string(
self.options.get("alts_enabled"), default=None
),
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L195-L209
| 40 |
[
0,
1
] | 13.333333 |
[] | 0 | false | 93.783784 | 15 | 1 | 100 | 0 |
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
"name": self.name,
"label": self.label,
"label_i18n": self.label_i18n,
"hide_label": bool_from_string(
self.options.get("hide_label"), default=False
),
"description_i18n": self.description_i18n,
"type": self.type.to_json(pad, record, alt),
"default": self.default,
"alts_enabled": bool_from_string(
self.options.get("alts_enabled"), default=None
),
}
| 26,024 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
Field.deserialize_value
|
(self, value, pad=None)
|
return self.type.value_from_raw_with_default(raw_value)
| 211 | 213 |
def deserialize_value(self, value, pad=None):
raw_value = RawValue(self.name, value, field=self, pad=pad)
return self.type.value_from_raw_with_default(raw_value)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L211-L213
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.783784 | 3 | 1 | 100 | 0 |
def deserialize_value(self, value, pad=None):
raw_value = RawValue(self.name, value, field=self, pad=pad)
return self.type.value_from_raw_with_default(raw_value)
| 26,025 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
Field.serialize_value
|
(self, value)
|
return self.type.value_to_raw(value)
| 215 | 216 |
def serialize_value(self, value):
return self.type.value_to_raw(value)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L215-L216
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 93.783784 | 2 | 1 | 50 | 0 |
def serialize_value(self, value):
return self.type.value_to_raw(value)
| 26,026 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
Field.__repr__
|
(self)
|
return "<%s %r type=%r>" % (
self.__class__.__name__,
self.name,
self.type,
)
| 218 | 223 |
def __repr__(self):
return "<%s %r type=%r>" % (
self.__class__.__name__,
self.name,
self.type,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L218-L223
| 40 |
[
0
] | 16.666667 |
[
1
] | 16.666667 | false | 93.783784 | 6 | 1 | 83.333333 | 0 |
def __repr__(self):
return "<%s %r type=%r>" % (
self.__class__.__name__,
self.name,
self.type,
)
| 26,027 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.__init__
|
(
self,
env,
id,
name_i18n,
label_i18n=None,
filename=None,
hidden=None,
protected=None,
child_config=None,
attachment_config=None,
pagination_config=None,
fields=None,
primary_field=None,
parent=None,
)
| 234 | 287 |
def __init__(
self,
env,
id,
name_i18n,
label_i18n=None,
filename=None,
hidden=None,
protected=None,
child_config=None,
attachment_config=None,
pagination_config=None,
fields=None,
primary_field=None,
parent=None,
):
self.env = env
self.filename = filename
self.id = id
self.name_i18n = name_i18n
self.label_i18n = label_i18n
if hidden is None:
hidden = False
self.hidden = hidden
if protected is None:
protected = False
self.protected = protected
if child_config is None:
child_config = ChildConfig()
self.child_config = child_config
if attachment_config is None:
attachment_config = AttachmentConfig()
self.attachment_config = attachment_config
if pagination_config is None:
pagination_config = PaginationConfig(env)
self.pagination_config = pagination_config
if fields is None:
fields = []
self.fields = fields
if primary_field is None and fields:
primary_field = fields[0].name
self.primary_field = primary_field
self.parent = parent
# This is a mapping of the key names to the actual field which
# also includes the system fields. This is primarily used for
# fast internal operations but also the admin.
self.field_map = dict((x.name, x) for x in fields)
for key, (ty, opts) in system_fields.items():
self.field_map[key] = Field(env, name=key, type=ty, options=opts)
self._child_slug_tmpl = None
self._child_replacements = None
self._label_tmpls = {}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L234-L287
| 40 |
[
0,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53
] | 72.222222 |
[] | 0 | false | 93.783784 | 54 | 10 | 100 | 0 |
def __init__(
self,
env,
id,
name_i18n,
label_i18n=None,
filename=None,
hidden=None,
protected=None,
child_config=None,
attachment_config=None,
pagination_config=None,
fields=None,
primary_field=None,
parent=None,
):
self.env = env
self.filename = filename
self.id = id
self.name_i18n = name_i18n
self.label_i18n = label_i18n
if hidden is None:
hidden = False
self.hidden = hidden
if protected is None:
protected = False
self.protected = protected
if child_config is None:
child_config = ChildConfig()
self.child_config = child_config
if attachment_config is None:
attachment_config = AttachmentConfig()
self.attachment_config = attachment_config
if pagination_config is None:
pagination_config = PaginationConfig(env)
self.pagination_config = pagination_config
if fields is None:
fields = []
self.fields = fields
if primary_field is None and fields:
primary_field = fields[0].name
self.primary_field = primary_field
self.parent = parent
# This is a mapping of the key names to the actual field which
# also includes the system fields. This is primarily used for
# fast internal operations but also the admin.
self.field_map = dict((x.name, x) for x in fields)
for key, (ty, opts) in system_fields.items():
self.field_map[key] = Field(env, name=key, type=ty, options=opts)
self._child_slug_tmpl = None
self._child_replacements = None
self._label_tmpls = {}
| 26,028 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.name
|
(self)
|
return name or self.id.title().replace("_", " ")
| 290 | 292 |
def name(self):
name = (self.name_i18n or {}).get("en")
return name or self.id.title().replace("_", " ")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L290-L292
| 40 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 93.783784 | 3 | 3 | 100 | 0 |
def name(self):
name = (self.name_i18n or {}).get("en")
return name or self.id.title().replace("_", " ")
| 26,029 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.label
|
(self)
|
return (self.label_i18n or {}).get("en")
| 295 | 296 |
def label(self):
return (self.label_i18n or {}).get("en")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L295-L296
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.783784 | 2 | 2 | 100 | 0 |
def label(self):
return (self.label_i18n or {}).get("en")
| 26,030 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.to_json
|
(self, pad, record=None, alt=PRIMARY_ALT)
|
return {
"filename": self.filename,
"alt": alt,
"id": self.id,
"name": self.name,
"name_i18n": self.name_i18n,
"primary_field": self.primary_field,
"label": self.label,
"label_i18n": self.label_i18n,
"hidden": self.hidden,
"protected": self.protected,
"child_config": self.child_config.to_json(),
"attachment_config": self.attachment_config.to_json(),
"pagination_config": self.pagination_config.to_json(),
"fields": [x.to_json(pad, record, alt) for x in _iter_all_fields(self)],
}
|
Describes the datamodel as JSON data.
|
Describes the datamodel as JSON data.
| 298 | 315 |
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
"""Describes the datamodel as JSON data."""
return {
"filename": self.filename,
"alt": alt,
"id": self.id,
"name": self.name,
"name_i18n": self.name_i18n,
"primary_field": self.primary_field,
"label": self.label,
"label_i18n": self.label_i18n,
"hidden": self.hidden,
"protected": self.protected,
"child_config": self.child_config.to_json(),
"attachment_config": self.attachment_config.to_json(),
"pagination_config": self.pagination_config.to_json(),
"fields": [x.to_json(pad, record, alt) for x in _iter_all_fields(self)],
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L298-L315
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
] | 100 |
[] | 0 | true | 93.783784 | 18 | 2 | 100 | 1 |
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
"filename": self.filename,
"alt": alt,
"id": self.id,
"name": self.name,
"name_i18n": self.name_i18n,
"primary_field": self.primary_field,
"label": self.label,
"label_i18n": self.label_i18n,
"hidden": self.hidden,
"protected": self.protected,
"child_config": self.child_config.to_json(),
"attachment_config": self.attachment_config.to_json(),
"pagination_config": self.pagination_config.to_json(),
"fields": [x.to_json(pad, record, alt) for x in _iter_all_fields(self)],
}
| 26,031 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.format_record_label
|
(self, record, lang="en")
|
Returns the label for a given record.
|
Returns the label for a given record.
| 317 | 332 |
def format_record_label(self, record, lang="en"):
"""Returns the label for a given record."""
label = self.label_i18n.get(lang)
if label is None:
return None
tmpl = self._label_tmpls.get(lang)
if tmpl is None:
tmpl = (label, FormatExpression(self.env, label))
self._label_tmpls[lang] = tmpl
try:
return tmpl[1].evaluate(record.pad, this=record)
except Exception:
# XXX: log
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L317-L332
| 40 |
[
0,
1,
2,
3,
5,
6,
7,
8,
9,
10,
11,
12
] | 75 |
[
4,
13,
15
] | 18.75 | false | 93.783784 | 16 | 4 | 81.25 | 1 |
def format_record_label(self, record, lang="en"):
label = self.label_i18n.get(lang)
if label is None:
return None
tmpl = self._label_tmpls.get(lang)
if tmpl is None:
tmpl = (label, FormatExpression(self.env, label))
self._label_tmpls[lang] = tmpl
try:
return tmpl[1].evaluate(record.pad, this=record)
except Exception:
# XXX: log
return None
| 26,032 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.get_default_child_slug
|
(self, pad, data)
|
Formats out the child slug.
|
Formats out the child slug.
| 334 | 352 |
def get_default_child_slug(self, pad, data):
"""Formats out the child slug."""
slug_format = self.child_config.slug_format
if slug_format is None:
return data["_id"]
if self._child_slug_tmpl is None or self._child_slug_tmpl[0] != slug_format:
self._child_slug_tmpl = (
slug_format,
FormatExpression(self.env, slug_format),
)
try:
return "_".join(
self._child_slug_tmpl[1].evaluate(pad, this=data).strip().split()
).strip("/")
except Exception as exc:
reporter.report_generic("Failed to expand child slug_format: %s" % exc)
return "temp-" + slugify(data["_id"])
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L334-L352
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18
] | 100 |
[] | 0 | true | 93.783784 | 19 | 5 | 100 | 1 |
def get_default_child_slug(self, pad, data):
slug_format = self.child_config.slug_format
if slug_format is None:
return data["_id"]
if self._child_slug_tmpl is None or self._child_slug_tmpl[0] != slug_format:
self._child_slug_tmpl = (
slug_format,
FormatExpression(self.env, slug_format),
)
try:
return "_".join(
self._child_slug_tmpl[1].evaluate(pad, this=data).strip().split()
).strip("/")
except Exception as exc:
reporter.report_generic("Failed to expand child slug_format: %s" % exc)
return "temp-" + slugify(data["_id"])
| 26,033 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.get_default_template_name
|
(self)
|
return self.id + ".html"
| 354 | 355 |
def get_default_template_name(self):
return self.id + ".html"
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L354-L355
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.783784 | 2 | 1 | 100 | 0 |
def get_default_template_name(self):
return self.id + ".html"
| 26,034 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.has_own_children
|
(self)
|
return self.child_config.replaced_with is None and self.child_config.enabled
| 358 | 359 |
def has_own_children(self):
return self.child_config.replaced_with is None and self.child_config.enabled
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L358-L359
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.783784 | 2 | 2 | 100 | 0 |
def has_own_children(self):
return self.child_config.replaced_with is None and self.child_config.enabled
| 26,035 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.has_own_attachments
|
(self)
|
return self.attachment_config.enabled
| 362 | 363 |
def has_own_attachments(self):
return self.attachment_config.enabled
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L362-L363
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.783784 | 2 | 1 | 100 | 0 |
def has_own_attachments(self):
return self.attachment_config.enabled
| 26,036 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.get_child_replacements
|
(self, record)
|
return self._child_replacements[1].evaluate(record.pad, this=record)
|
Returns the query that should be used as replacement for the
actual children.
|
Returns the query that should be used as replacement for the
actual children.
| 365 | 382 |
def get_child_replacements(self, record):
"""Returns the query that should be used as replacement for the
actual children.
"""
replaced_with = self.child_config.replaced_with
if replaced_with is None:
return None
if (
self._child_replacements is None
or self._child_replacements[0] != replaced_with
):
self._child_replacements = (
replaced_with,
Expression(self.env, replaced_with),
)
return self._child_replacements[1].evaluate(record.pad, this=record)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L365-L382
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 44.444444 |
[
8,
12,
17
] | 16.666667 | false | 93.783784 | 18 | 4 | 83.333333 | 2 |
def get_child_replacements(self, record):
replaced_with = self.child_config.replaced_with
if replaced_with is None:
return None
if (
self._child_replacements is None
or self._child_replacements[0] != replaced_with
):
self._child_replacements = (
replaced_with,
Expression(self.env, replaced_with),
)
return self._child_replacements[1].evaluate(record.pad, this=record)
| 26,037 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.process_raw_data
|
(self, raw_data, pad=None)
|
return rv
| 384 | 390 |
def process_raw_data(self, raw_data, pad=None):
rv = {}
for field in self.field_map.values():
value = raw_data.get(field.name)
rv[field.name] = field.deserialize_value(value, pad=pad)
rv["_model"] = self.id
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L384-L390
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 93.783784 | 7 | 2 | 100 | 0 |
def process_raw_data(self, raw_data, pad=None):
rv = {}
for field in self.field_map.values():
value = raw_data.get(field.name)
rv[field.name] = field.deserialize_value(value, pad=pad)
rv["_model"] = self.id
return rv
| 26,038 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
DataModel.__repr__
|
(self)
|
return "<%s %r>" % (
self.__class__.__name__,
self.id,
)
| 392 | 396 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.id,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L392-L396
| 40 |
[
0
] | 20 |
[
1
] | 20 | false | 93.783784 | 5 | 1 | 80 | 0 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.id,
)
| 26,039 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
FlowBlockModel.__init__
|
(
self,
env,
id,
name_i18n,
filename=None,
fields=None,
order=None,
button_label=None,
)
| 400 | 425 |
def __init__(
self,
env,
id,
name_i18n,
filename=None,
fields=None,
order=None,
button_label=None,
):
self.env = env
self.id = id
self.name_i18n = name_i18n
self.filename = filename
if fields is None:
fields = []
self.fields = fields
if order is None:
order = 100
self.order = order
self.button_label = button_label
self.field_map = dict((x.name, x) for x in fields)
self.field_map["_flowblock"] = Field(
env, name="_flowblock", type=env.types["string"]
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L400-L425
| 40 |
[
0,
10,
11,
12,
13,
14,
16,
17,
18,
19,
20,
21,
22,
23
] | 53.846154 |
[
15
] | 3.846154 | false | 93.783784 | 26 | 3 | 96.153846 | 0 |
def __init__(
self,
env,
id,
name_i18n,
filename=None,
fields=None,
order=None,
button_label=None,
):
self.env = env
self.id = id
self.name_i18n = name_i18n
self.filename = filename
if fields is None:
fields = []
self.fields = fields
if order is None:
order = 100
self.order = order
self.button_label = button_label
self.field_map = dict((x.name, x) for x in fields)
self.field_map["_flowblock"] = Field(
env, name="_flowblock", type=env.types["string"]
)
| 26,040 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
FlowBlockModel.name
|
(self)
|
return self.name_i18n.get("en") or self.id.title().replace("_", " ")
| 428 | 429 |
def name(self):
return self.name_i18n.get("en") or self.id.title().replace("_", " ")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L428-L429
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 93.783784 | 2 | 2 | 100 | 0 |
def name(self):
return self.name_i18n.get("en") or self.id.title().replace("_", " ")
| 26,041 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
FlowBlockModel.to_json
|
(self, pad, record=None, alt=PRIMARY_ALT)
|
return {
"id": self.id,
"name": self.name,
"name_i18n": self.name_i18n,
"filename": self.filename,
"fields": [
x.to_json(pad, record, alt)
for x in _iter_all_fields(self)
if x.name != "_flowblock"
],
"order": self.order,
"button_label": self.button_label,
}
| 431 | 444 |
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
"id": self.id,
"name": self.name,
"name_i18n": self.name_i18n,
"filename": self.filename,
"fields": [
x.to_json(pad, record, alt)
for x in _iter_all_fields(self)
if x.name != "_flowblock"
],
"order": self.order,
"button_label": self.button_label,
}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L431-L444
| 40 |
[
0,
1
] | 14.285714 |
[] | 0 | false | 93.783784 | 14 | 2 | 100 | 0 |
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
"id": self.id,
"name": self.name,
"name_i18n": self.name_i18n,
"filename": self.filename,
"fields": [
x.to_json(pad, record, alt)
for x in _iter_all_fields(self)
if x.name != "_flowblock"
],
"order": self.order,
"button_label": self.button_label,
}
| 26,042 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
FlowBlockModel.process_raw_data
|
(self, raw_data, pad=None)
|
return rv
| 446 | 452 |
def process_raw_data(self, raw_data, pad=None):
rv = {}
for field in self.field_map.values():
value = raw_data.get(field.name)
rv[field.name] = field.deserialize_value(value, pad=pad)
rv["_flowblock"] = self.id
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L446-L452
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 93.783784 | 7 | 2 | 100 | 0 |
def process_raw_data(self, raw_data, pad=None):
rv = {}
for field in self.field_map.values():
value = raw_data.get(field.name)
rv[field.name] = field.deserialize_value(value, pad=pad)
rv["_flowblock"] = self.id
return rv
| 26,043 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/datamodel.py
|
FlowBlockModel.__repr__
|
(self)
|
return "<%s %r>" % (
self.__class__.__name__,
self.id,
)
| 454 | 458 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.id,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/datamodel.py#L454-L458
| 40 |
[
0
] | 20 |
[
1
] | 20 | false | 93.783784 | 5 | 1 | 80 | 0 |
def __repr__(self):
return "<%s %r>" % (
self.__class__.__name__,
self.id,
)
| 26,044 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
_convert_gps
|
(coords, hem)
|
return sign * (deg + min / 60.0 + sec / 3600.0)
| 53 | 56 |
def _convert_gps(coords, hem):
deg, min, sec = [float(x.num) / float(x.den) for x in coords]
sign = -1 if hem in "SW" else 1
return sign * (deg + min / 60.0 + sec / 3600.0)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L53-L56
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 81.971831 | 4 | 2 | 100 | 0 |
def _convert_gps(coords, hem):
deg, min, sec = [float(x.num) / float(x.den) for x in coords]
sign = -1 if hem in "SW" else 1
return sign * (deg + min / 60.0 + sec / 3600.0)
| 26,045 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
_combine_make
|
(make, model)
|
return " ".join([make, model]).strip()
| 59 | 64 |
def _combine_make(make, model):
make = make or ""
model = model or ""
if make and model.startswith(make):
return make
return " ".join([make, model]).strip()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L59-L64
| 40 |
[
0,
1,
2,
3,
5
] | 83.333333 |
[
4
] | 16.666667 | false | 81.971831 | 6 | 5 | 83.333333 | 0 |
def _combine_make(make, model):
make = make or ""
model = model or ""
if make and model.startswith(make):
return make
return " ".join([make, model]).strip()
| 26,046 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
_parse_svg_units_px
|
(length)
| 72 | 82 |
def _parse_svg_units_px(length):
match = _parse_svg_units_re.match(length)
if not match:
return None
match = match.groupdict()
if match["unit"] and match["unit"] != "px":
return None
try:
return float(match["value"])
except ValueError:
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L72-L82
| 40 |
[
0,
1,
2,
4,
5,
7,
8
] | 63.636364 |
[
3,
6,
9,
10
] | 36.363636 | false | 81.971831 | 11 | 5 | 63.636364 | 0 |
def _parse_svg_units_px(length):
match = _parse_svg_units_re.match(length)
if not match:
return None
match = match.groupdict()
if match["unit"] and match["unit"] != "px":
return None
try:
return float(match["value"])
except ValueError:
return None
| 26,047 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
get_suffix
|
(width, height, mode, quality=None)
|
return suffix
| 299 | 307 |
def get_suffix(width, height, mode, quality=None):
suffix = "" if width is None else str(width)
if height is not None:
suffix += "x%s" % height
if mode != ThumbnailMode.DEFAULT:
suffix += "_%s" % mode.value
if quality is not None:
suffix += "_q%s" % quality
return suffix
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L299-L307
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 81.971831 | 9 | 4 | 100 | 0 |
def get_suffix(width, height, mode, quality=None):
suffix = "" if width is None else str(width)
if height is not None:
suffix += "x%s" % height
if mode != ThumbnailMode.DEFAULT:
suffix += "_%s" % mode.value
if quality is not None:
suffix += "_q%s" % quality
return suffix
| 26,048 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
get_svg_info
|
(fp)
|
return "svg", width, height
| 310 | 317 |
def get_svg_info(fp):
_, svg = next(etree.iterparse(fp, ["start"]), (None, None))
fp.seek(0)
width, height = None, None
if svg is not None and svg.tag == "{http://www.w3.org/2000/svg}svg":
width = _parse_svg_units_px(svg.attrib.get("width", ""))
height = _parse_svg_units_px(svg.attrib.get("height", ""))
return "svg", width, height
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L310-L317
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 81.971831 | 8 | 3 | 100 | 0 |
def get_svg_info(fp):
_, svg = next(etree.iterparse(fp, ["start"]), (None, None))
fp.seek(0)
width, height = None, None
if svg is not None and svg.tag == "{http://www.w3.org/2000/svg}svg":
width = _parse_svg_units_px(svg.attrib.get("width", ""))
height = _parse_svg_units_px(svg.attrib.get("height", ""))
return "svg", width, height
| 26,049 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
get_image_info
|
(fp)
|
return fmt, width, height
|
Reads some image info from a file descriptor.
|
Reads some image info from a file descriptor.
| 343 | 422 |
def get_image_info(fp):
"""Reads some image info from a file descriptor."""
head = fp.read(32)
fp.seek(0)
if len(head) < 24:
return "unknown", None, None
magic_bytes = b"<?xml", b"<svg"
if any(map(head.strip().startswith, magic_bytes)):
return get_svg_info(fp)
_type = filetype.image_match(bytearray(head))
fmt = _type.mime.split("/")[1] if _type else None
width = None
height = None
if fmt == "png":
check = struct.unpack(">i", head[4:8])[0]
if check == 0x0D0A1A0A:
width, height = struct.unpack(">ii", head[16:24])
elif fmt == "gif":
width, height = struct.unpack("<HH", head[6:10])
elif fmt == "jpeg":
# specification available under
# http://www.w3.org/Graphics/JPEG/itu-t81.pdf
# Annex B (page 31/35)
# we are looking for a SOF marker ("start of frame").
# skip over the "start of image" marker
# (filetype detection took care of that).
fp.seek(2)
while True:
byte = fp.read(1)
# "All markers are assigned two-byte codes: an X’FF’ byte
# followed by a byte which is not equal to 0 or X’FF’."
if not byte or ord(byte) != 0xFF:
raise Exception("Malformed JPEG image.")
# "Any marker may optionally be preceded by any number
# of fill bytes, which are bytes assigned code X’FF’."
while ord(byte) == 0xFF:
byte = fp.read(1)
if ord(byte) not in _JPEG_SOF_MARKERS:
# header length parameter takes 2 bytes for all markers
length = struct.unpack(">H", fp.read(2))[0]
fp.seek(length - 2, 1)
continue
# else...
# see Figure B.3 – Frame header syntax (page 35/39) and
# Table B.2 – Frame header parameter sizes and values
# (page 36/40)
fp.seek(3, 1) # skip header length and precision parameters
height, width = struct.unpack(">HH", fp.read(4))
if height == 0:
# "Value 0 indicates that the number of lines shall be
# defined by the DNL marker [...]"
#
# DNL is not supported by most applications,
# so we won't support it either.
raise Exception("JPEG with DNL not supported.")
break
# if the file is rotated, we want, for all intents and purposes,
# to return the dimensions swapped. (all client apps will display
# the image rotated, and any template computations are likely to want
# to make decisions based on the "visual", not the "real" dimensions.
# thumbnail code also depends on this behaviour.)
fp.seek(0)
if is_rotated(fp):
width, height = height, width
else:
fmt = None
return fmt, width, height
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L343-L422
| 40 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
20,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79
] | 88.75 |
[
5,
17,
18,
19,
21,
38,
64
] | 8.75 | false | 81.971831 | 80 | 14 | 91.25 | 1 |
def get_image_info(fp):
head = fp.read(32)
fp.seek(0)
if len(head) < 24:
return "unknown", None, None
magic_bytes = b"<?xml", b"<svg"
if any(map(head.strip().startswith, magic_bytes)):
return get_svg_info(fp)
_type = filetype.image_match(bytearray(head))
fmt = _type.mime.split("/")[1] if _type else None
width = None
height = None
if fmt == "png":
check = struct.unpack(">i", head[4:8])[0]
if check == 0x0D0A1A0A:
width, height = struct.unpack(">ii", head[16:24])
elif fmt == "gif":
width, height = struct.unpack("<HH", head[6:10])
elif fmt == "jpeg":
# specification available under
# http://www.w3.org/Graphics/JPEG/itu-t81.pdf
# Annex B (page 31/35)
# we are looking for a SOF marker ("start of frame").
# skip over the "start of image" marker
# (filetype detection took care of that).
fp.seek(2)
while True:
byte = fp.read(1)
# "All markers are assigned two-byte codes: an X’FF’ byte
# followed by a byte which is not equal to 0 or X’FF’."
if not byte or ord(byte) != 0xFF:
raise Exception("Malformed JPEG image.")
# "Any marker may optionally be preceded by any number
# of fill bytes, which are bytes assigned code X’FF’."
while ord(byte) == 0xFF:
byte = fp.read(1)
if ord(byte) not in _JPEG_SOF_MARKERS:
# header length parameter takes 2 bytes for all markers
length = struct.unpack(">H", fp.read(2))[0]
fp.seek(length - 2, 1)
continue
# else...
# see Figure B.3 – Frame header syntax (page 35/39) and
# Table B.2 – Frame header parameter sizes and values
# (page 36/40)
fp.seek(3, 1) # skip header length and precision parameters
height, width = struct.unpack(">HH", fp.read(4))
if height == 0:
# "Value 0 indicates that the number of lines shall be
# defined by the DNL marker [...]"
#
# DNL is not supported by most applications,
# so we won't support it either.
raise Exception("JPEG with DNL not supported.")
break
# if the file is rotated, we want, for all intents and purposes,
# to return the dimensions swapped. (all client apps will display
# the image rotated, and any template computations are likely to want
# to make decisions based on the "visual", not the "real" dimensions.
# thumbnail code also depends on this behaviour.)
fp.seek(0)
if is_rotated(fp):
width, height = height, width
else:
fmt = None
return fmt, width, height
| 26,050 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
read_exif
|
(fp)
|
return EXIFInfo(exif)
|
Reads exif data from a file pointer of an image and returns it.
|
Reads exif data from a file pointer of an image and returns it.
| 425 | 428 |
def read_exif(fp):
"""Reads exif data from a file pointer of an image and returns it."""
exif = exifread.process_file(fp)
return EXIFInfo(exif)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L425-L428
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 81.971831 | 4 | 1 | 100 | 1 |
def read_exif(fp):
exif = exifread.process_file(fp)
return EXIFInfo(exif)
| 26,051 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
is_rotated
|
(fp)
|
return EXIFInfo(exif).is_rotated
|
Fast version of read_exif(fp).is_rotated, using an exif header subset.
|
Fast version of read_exif(fp).is_rotated, using an exif header subset.
| 431 | 434 |
def is_rotated(fp):
"""Fast version of read_exif(fp).is_rotated, using an exif header subset."""
exif = exifread.process_file(fp, stop_tag="Orientation", details=False)
return EXIFInfo(exif).is_rotated
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L431-L434
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 81.971831 | 4 | 1 | 100 | 1 |
def is_rotated(fp):
exif = exifread.process_file(fp, stop_tag="Orientation", details=False)
return EXIFInfo(exif).is_rotated
| 26,052 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
find_imagemagick
|
(im=None)
|
Finds imagemagick and returns the path to it.
|
Finds imagemagick and returns the path to it.
| 437 | 452 |
def find_imagemagick(im=None):
"""Finds imagemagick and returns the path to it."""
# If it's provided explicitly and it's valid, we go with that one.
if im is not None and os.path.isfile(im):
return im
# On windows, imagemagick was renamed to magick, because
# convert is system utility for fs manipulation.
imagemagick_exe = "convert" if os.name != "nt" else "magick"
rv = locate_executable(imagemagick_exe)
if rv is not None:
return rv
# Give up.
raise RuntimeError("Could not locate imagemagick.")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L437-L452
| 40 |
[
0,
1,
2,
3,
7,
8,
9,
10,
11,
14,
15
] | 68.75 |
[
4,
12
] | 12.5 | false | 81.971831 | 16 | 4 | 87.5 | 1 |
def find_imagemagick(im=None):
# If it's provided explicitly and it's valid, we go with that one.
if im is not None and os.path.isfile(im):
return im
# On windows, imagemagick was renamed to magick, because
# convert is system utility for fs manipulation.
imagemagick_exe = "convert" if os.name != "nt" else "magick"
rv = locate_executable(imagemagick_exe)
if rv is not None:
return rv
# Give up.
raise RuntimeError("Could not locate imagemagick.")
| 26,053 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
get_thumbnail_ext
|
(source_filename)
|
return ".jpeg"
| 455 | 462 |
def get_thumbnail_ext(source_filename):
ext = source_filename.rsplit(".", 1)[-1].lower()
# if the extension is already of a format that a browser understands
# we will roll with it.
if ext.lower() in ("png", "jpg", "jpeg", "gif"):
return None
# Otherwise we roll with JPEG as default.
return ".jpeg"
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L455-L462
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 87.5 |
[
7
] | 12.5 | false | 81.971831 | 8 | 2 | 87.5 | 0 |
def get_thumbnail_ext(source_filename):
ext = source_filename.rsplit(".", 1)[-1].lower()
# if the extension is already of a format that a browser understands
# we will roll with it.
if ext.lower() in ("png", "jpg", "jpeg", "gif"):
return None
# Otherwise we roll with JPEG as default.
return ".jpeg"
| 26,054 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
get_quality
|
(source_filename)
|
return 85
| 465 | 469 |
def get_quality(source_filename):
ext = source_filename.rsplit(".", 1)[-1].lower()
if ext.lower() == "png":
return 75
return 85
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L465-L469
| 40 |
[
0
] | 20 |
[
1,
2,
3,
4
] | 80 | false | 81.971831 | 5 | 2 | 20 | 0 |
def get_quality(source_filename):
ext = source_filename.rsplit(".", 1)[-1].lower()
if ext.lower() == "png":
return 75
return 85
| 26,055 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
compute_dimensions
|
(width, height, source_width, source_height)
|
return computed_width, computed_height
|
computes the bounding dimensions
|
computes the bounding dimensions
| 472 | 492 |
def compute_dimensions(width, height, source_width, source_height):
"""computes the bounding dimensions"""
computed_width, computed_height = width, height
width, height, source_width, source_height = (
None if v is None else float(v)
for v in (width, height, source_width, source_height)
)
source_ratio = source_width / source_height
def _round(x):
# make sure things get top-rounded, to be consistent with imagemagick
return int(decimal.Decimal(x).to_integral(decimal.ROUND_HALF_UP))
if width is None or (height is not None and width / height > source_ratio):
computed_width = _round(height * source_ratio)
else:
computed_height = _round(width / source_ratio)
return computed_width, computed_height
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L472-L492
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20
] | 100 |
[] | 0 | true | 81.971831 | 21 | 5 | 100 | 1 |
def compute_dimensions(width, height, source_width, source_height):
computed_width, computed_height = width, height
width, height, source_width, source_height = (
None if v is None else float(v)
for v in (width, height, source_width, source_height)
)
source_ratio = source_width / source_height
def _round(x):
# make sure things get top-rounded, to be consistent with imagemagick
return int(decimal.Decimal(x).to_integral(decimal.ROUND_HALF_UP))
if width is None or (height is not None and width / height > source_ratio):
computed_width = _round(height * source_ratio)
else:
computed_height = _round(width / source_ratio)
return computed_width, computed_height
| 26,056 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
process_image
|
(
ctx,
source_image,
dst_filename,
width=None,
height=None,
mode=ThumbnailMode.DEFAULT,
quality=None,
)
|
Build image from source image, optionally compressing and resizing.
"source_image" is the absolute path of the source in the content directory,
"dst_filename" is the absolute path of the target in the output directory.
|
Build image from source image, optionally compressing and resizing.
| 495 | 543 |
def process_image(
ctx,
source_image,
dst_filename,
width=None,
height=None,
mode=ThumbnailMode.DEFAULT,
quality=None,
):
"""Build image from source image, optionally compressing and resizing.
"source_image" is the absolute path of the source in the content directory,
"dst_filename" is the absolute path of the target in the output directory.
"""
if width is None and height is None:
raise ValueError("Must specify at least one of width or height.")
im = find_imagemagick(ctx.build_state.config["IMAGEMAGICK_EXECUTABLE"])
if quality is None:
quality = get_quality(source_image)
resize_key = ""
if width is not None:
resize_key += str(width)
if height is not None:
resize_key += "x" + str(height)
if mode == ThumbnailMode.STRETCH:
resize_key += "!"
cmdline = [im, source_image, "-auto-orient"]
if mode == ThumbnailMode.CROP:
cmdline += [
"-resize",
resize_key + "^",
"-gravity",
"Center",
"-extent",
resize_key,
]
else:
cmdline += ["-resize", resize_key]
cmdline += ["-strip", "-colorspace", "sRGB"]
cmdline += ["-quality", str(quality), dst_filename]
reporter.report_debug_info("imagemagick cmd line", cmdline)
portable_popen(cmdline).wait()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L495-L543
| 40 |
[
0,
13,
14,
16,
17,
18
] | 12.244898 |
[
15,
19,
20,
22,
23,
24,
25,
26,
28,
29,
31,
32,
33,
42,
44,
45,
47,
48
] | 36.734694 | false | 81.971831 | 49 | 8 | 63.265306 | 4 |
def process_image(
ctx,
source_image,
dst_filename,
width=None,
height=None,
mode=ThumbnailMode.DEFAULT,
quality=None,
):
if width is None and height is None:
raise ValueError("Must specify at least one of width or height.")
im = find_imagemagick(ctx.build_state.config["IMAGEMAGICK_EXECUTABLE"])
if quality is None:
quality = get_quality(source_image)
resize_key = ""
if width is not None:
resize_key += str(width)
if height is not None:
resize_key += "x" + str(height)
if mode == ThumbnailMode.STRETCH:
resize_key += "!"
cmdline = [im, source_image, "-auto-orient"]
if mode == ThumbnailMode.CROP:
cmdline += [
"-resize",
resize_key + "^",
"-gravity",
"Center",
"-extent",
resize_key,
]
else:
cmdline += ["-resize", resize_key]
cmdline += ["-strip", "-colorspace", "sRGB"]
cmdline += ["-quality", str(quality), dst_filename]
reporter.report_debug_info("imagemagick cmd line", cmdline)
portable_popen(cmdline).wait()
| 26,057 |
|
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
make_image_thumbnail
|
(
ctx,
source_image,
source_url_path,
width=None,
height=None,
mode=ThumbnailMode.DEFAULT,
upscale=None,
quality=None,
)
|
return Thumbnail(dst_url_path, computed_width, computed_height)
|
Helper method that can create thumbnails from within the build process
of an artifact.
|
Helper method that can create thumbnails from within the build process
of an artifact.
| 546 | 620 |
def make_image_thumbnail(
ctx,
source_image,
source_url_path,
width=None,
height=None,
mode=ThumbnailMode.DEFAULT,
upscale=None,
quality=None,
):
"""Helper method that can create thumbnails from within the build process
of an artifact.
"""
if width is None and height is None:
raise ValueError("Must specify at least one of width or height.")
# temporarily fallback to "fit" in case of erroneous arguments
# to preserve backward-compatibility.
# this needs to change to an exception in the future.
if mode != ThumbnailMode.FIT and (width is None or height is None):
warnings.warn(
f'"{mode.value}" mode requires both `width` and `height` '
'to be specified. Falling back to "fit" mode.'
)
mode = ThumbnailMode.FIT
if upscale is None and mode in (ThumbnailMode.CROP, ThumbnailMode.STRETCH):
upscale = True
with open(source_image, "rb") as f:
format, source_width, source_height = get_image_info(f)
if format is None:
raise RuntimeError("Cannot process unknown images")
# If we are dealing with an actual svg image, we do not actually
# resize anything, we just return it. This is not ideal but it's
# better than outright failing.
if format == "svg":
return Thumbnail(source_url_path, width, height)
if mode == ThumbnailMode.FIT:
computed_width, computed_height = compute_dimensions(
width, height, source_width, source_height
)
else:
computed_width, computed_height = width, height
would_upscale = computed_width > source_width or computed_height > source_height
if would_upscale and not upscale:
return Thumbnail(source_url_path, source_width, source_height)
suffix = get_suffix(width, height, mode, quality=quality)
dst_url_path = get_dependent_url(
source_url_path, suffix, ext=get_thumbnail_ext(source_image)
)
def build_thumbnail_artifact(artifact):
artifact.ensure_dir()
process_image(
ctx,
source_image,
artifact.dst_filename,
width,
height,
mode,
quality=quality,
)
ctx.sub_artifact(artifact_name=dst_url_path, sources=[source_image])(
build_thumbnail_artifact
)
return Thumbnail(dst_url_path, computed_width, computed_height)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L546-L620
| 40 |
[
0,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74
] | 85.333333 |
[] | 0 | false | 81.971831 | 75 | 16 | 100 | 2 |
def make_image_thumbnail(
ctx,
source_image,
source_url_path,
width=None,
height=None,
mode=ThumbnailMode.DEFAULT,
upscale=None,
quality=None,
):
if width is None and height is None:
raise ValueError("Must specify at least one of width or height.")
# temporarily fallback to "fit" in case of erroneous arguments
# to preserve backward-compatibility.
# this needs to change to an exception in the future.
if mode != ThumbnailMode.FIT and (width is None or height is None):
warnings.warn(
f'"{mode.value}" mode requires both `width` and `height` '
'to be specified. Falling back to "fit" mode.'
)
mode = ThumbnailMode.FIT
if upscale is None and mode in (ThumbnailMode.CROP, ThumbnailMode.STRETCH):
upscale = True
with open(source_image, "rb") as f:
format, source_width, source_height = get_image_info(f)
if format is None:
raise RuntimeError("Cannot process unknown images")
# If we are dealing with an actual svg image, we do not actually
# resize anything, we just return it. This is not ideal but it's
# better than outright failing.
if format == "svg":
return Thumbnail(source_url_path, width, height)
if mode == ThumbnailMode.FIT:
computed_width, computed_height = compute_dimensions(
width, height, source_width, source_height
)
else:
computed_width, computed_height = width, height
would_upscale = computed_width > source_width or computed_height > source_height
if would_upscale and not upscale:
return Thumbnail(source_url_path, source_width, source_height)
suffix = get_suffix(width, height, mode, quality=quality)
dst_url_path = get_dependent_url(
source_url_path, suffix, ext=get_thumbnail_ext(source_image)
)
def build_thumbnail_artifact(artifact):
artifact.ensure_dir()
process_image(
ctx,
source_image,
artifact.dst_filename,
width,
height,
mode,
quality=quality,
)
ctx.sub_artifact(artifact_name=dst_url_path, sources=[source_image])(
build_thumbnail_artifact
)
return Thumbnail(dst_url_path, computed_width, computed_height)
| 26,058 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
ThumbnailMode.label
|
(self)
|
return self.value
|
The mode's label as used in templates.
|
The mode's label as used in templates.
| 33 | 39 |
def label(self):
"""The mode's label as used in templates."""
warnings.warn(
"ThumbnailMode.label is deprecated. (Use ThumbnailMode.value instead.)",
DeprecationWarning,
)
return self.value
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L33-L39
| 40 |
[
0,
1
] | 28.571429 |
[
2,
6
] | 28.571429 | false | 81.971831 | 7 | 1 | 71.428571 | 1 |
def label(self):
warnings.warn(
"ThumbnailMode.label is deprecated. (Use ThumbnailMode.value instead.)",
DeprecationWarning,
)
return self.value
| 26,059 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
ThumbnailMode.from_label
|
(cls, label)
|
return cls(label)
|
Looks up the thumbnail mode by its textual representation.
|
Looks up the thumbnail mode by its textual representation.
| 42 | 50 |
def from_label(cls, label):
"""Looks up the thumbnail mode by its textual representation."""
warnings.warn(
"ThumbnailMode.from_label is deprecated. "
"Use the ThumbnailMode constructor, "
'e.g. "ThumbnailMode(label)", instead.',
DeprecationWarning,
)
return cls(label)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L42-L50
| 40 |
[
0,
1
] | 22.222222 |
[
2,
8
] | 22.222222 | false | 81.971831 | 9 | 1 | 77.777778 | 1 |
def from_label(cls, label):
warnings.warn(
"ThumbnailMode.from_label is deprecated. "
"Use the ThumbnailMode constructor, "
'e.g. "ThumbnailMode(label)", instead.',
DeprecationWarning,
)
return cls(label)
| 26,060 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.__init__
|
(self, d)
| 86 | 87 |
def __init__(self, d):
self._mapping = d
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L86-L87
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def __init__(self, d):
self._mapping = d
| 26,061 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.__bool__
|
(self)
|
return bool(self._mapping)
| 89 | 90 |
def __bool__(self):
return bool(self._mapping)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L89-L90
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def __bool__(self):
return bool(self._mapping)
| 26,062 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.to_dict
|
(self)
|
return rv
| 94 | 99 |
def to_dict(self):
rv = {}
for key, value in self.__class__.__dict__.items():
if key[:1] != "_" and isinstance(value, property):
rv[key] = getattr(self, key)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L94-L99
| 40 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 81.971831 | 6 | 4 | 100 | 0 |
def to_dict(self):
rv = {}
for key, value in self.__class__.__dict__.items():
if key[:1] != "_" and isinstance(value, property):
rv[key] = getattr(self, key)
return rv
| 26,063 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo._get_string
|
(self, key)
|
return value.decode("utf-8", "replace")
| 101 | 108 |
def _get_string(self, key):
try:
value = self._mapping[key].values
except KeyError:
return None
if isinstance(value, str):
return value
return value.decode("utf-8", "replace")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L101-L108
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 87.5 |
[
7
] | 12.5 | false | 81.971831 | 8 | 3 | 87.5 | 0 |
def _get_string(self, key):
try:
value = self._mapping[key].values
except KeyError:
return None
if isinstance(value, str):
return value
return value.decode("utf-8", "replace")
| 26,064 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo._get_int
|
(self, key)
| 110 | 114 |
def _get_int(self, key):
try:
return self._mapping[key].values[0]
except LookupError:
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L110-L114
| 40 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 81.971831 | 5 | 2 | 100 | 0 |
def _get_int(self, key):
try:
return self._mapping[key].values[0]
except LookupError:
return None
| 26,065 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo._get_float
|
(self, key, precision=4)
| 116 | 123 |
def _get_float(self, key, precision=4):
try:
val = self._mapping[key].values[0]
if isinstance(val, int):
return float(val)
return round(float(val.num) / float(val.den), precision)
except LookupError:
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L116-L123
| 40 |
[
0,
1,
2,
3,
4,
5
] | 75 |
[
6,
7
] | 25 | false | 81.971831 | 8 | 3 | 75 | 0 |
def _get_float(self, key, precision=4):
try:
val = self._mapping[key].values[0]
if isinstance(val, int):
return float(val)
return round(float(val.num) / float(val.den), precision)
except LookupError:
return None
| 26,066 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo._get_frac_string
|
(self, key)
| 125 | 130 |
def _get_frac_string(self, key):
try:
val = self._mapping[key].values[0]
return "%s/%s" % (val.num, val.den)
except LookupError:
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L125-L130
| 40 |
[
0,
1,
2,
3
] | 66.666667 |
[
4,
5
] | 33.333333 | false | 81.971831 | 6 | 2 | 66.666667 | 0 |
def _get_frac_string(self, key):
try:
val = self._mapping[key].values[0]
return "%s/%s" % (val.num, val.den)
except LookupError:
return None
| 26,067 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.artist
|
(self)
|
return self._get_string("Image Artist")
| 133 | 134 |
def artist(self):
return self._get_string("Image Artist")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L133-L134
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def artist(self):
return self._get_string("Image Artist")
| 26,068 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.copyright
|
(self)
|
return self._get_string("Image Copyright")
| 137 | 138 |
def copyright(self):
return self._get_string("Image Copyright")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L137-L138
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def copyright(self):
return self._get_string("Image Copyright")
| 26,069 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.camera_make
|
(self)
|
return self._get_string("Image Make")
| 141 | 142 |
def camera_make(self):
return self._get_string("Image Make")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L141-L142
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def camera_make(self):
return self._get_string("Image Make")
| 26,070 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.camera_model
|
(self)
|
return self._get_string("Image Model")
| 145 | 146 |
def camera_model(self):
return self._get_string("Image Model")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L145-L146
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def camera_model(self):
return self._get_string("Image Model")
| 26,071 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.camera
|
(self)
|
return _combine_make(self.camera_make, self.camera_model)
| 149 | 150 |
def camera(self):
return _combine_make(self.camera_make, self.camera_model)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L149-L150
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def camera(self):
return _combine_make(self.camera_make, self.camera_model)
| 26,072 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.lens_make
|
(self)
|
return self._get_string("EXIF LensMake")
| 153 | 154 |
def lens_make(self):
return self._get_string("EXIF LensMake")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L153-L154
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def lens_make(self):
return self._get_string("EXIF LensMake")
| 26,073 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.lens_model
|
(self)
|
return self._get_string("EXIF LensModel")
| 157 | 158 |
def lens_model(self):
return self._get_string("EXIF LensModel")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L157-L158
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def lens_model(self):
return self._get_string("EXIF LensModel")
| 26,074 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.lens
|
(self)
|
return _combine_make(self.lens_make, self.lens_model)
| 161 | 162 |
def lens(self):
return _combine_make(self.lens_make, self.lens_model)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L161-L162
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def lens(self):
return _combine_make(self.lens_make, self.lens_model)
| 26,075 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.aperture
|
(self)
|
return self._get_float("EXIF ApertureValue")
| 165 | 166 |
def aperture(self):
return self._get_float("EXIF ApertureValue")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L165-L166
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def aperture(self):
return self._get_float("EXIF ApertureValue")
| 26,076 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.f_num
|
(self)
|
return self._get_float("EXIF FNumber")
| 169 | 170 |
def f_num(self):
return self._get_float("EXIF FNumber")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L169-L170
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def f_num(self):
return self._get_float("EXIF FNumber")
| 26,077 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.f
|
(self)
|
return "ƒ/%s" % self.f_num
| 173 | 174 |
def f(self):
return "ƒ/%s" % self.f_num
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L173-L174
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def f(self):
return "ƒ/%s" % self.f_num
| 26,078 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.exposure_time
|
(self)
|
return self._get_frac_string("EXIF ExposureTime")
| 177 | 178 |
def exposure_time(self):
return self._get_frac_string("EXIF ExposureTime")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L177-L178
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def exposure_time(self):
return self._get_frac_string("EXIF ExposureTime")
| 26,079 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.shutter_speed
|
(self)
|
return None
| 181 | 187 |
def shutter_speed(self):
val = self._get_float("EXIF ShutterSpeedValue")
if val is not None:
return "1/%d" % round(
1 / (2**-val) # pylint: disable=invalid-unary-operand-type
)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L181-L187
| 40 |
[
0,
1,
2,
3
] | 57.142857 |
[
6
] | 14.285714 | false | 81.971831 | 7 | 2 | 85.714286 | 0 |
def shutter_speed(self):
val = self._get_float("EXIF ShutterSpeedValue")
if val is not None:
return "1/%d" % round(
1 / (2**-val) # pylint: disable=invalid-unary-operand-type
)
return None
| 26,080 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.focal_length
|
(self)
|
return None
| 190 | 194 |
def focal_length(self):
val = self._get_float("EXIF FocalLength")
if val is not None:
return "%smm" % val
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L190-L194
| 40 |
[
0,
1,
2,
3
] | 80 |
[
4
] | 20 | false | 81.971831 | 5 | 2 | 80 | 0 |
def focal_length(self):
val = self._get_float("EXIF FocalLength")
if val is not None:
return "%smm" % val
return None
| 26,081 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.focal_length_35mm
|
(self)
|
return None
| 197 | 201 |
def focal_length_35mm(self):
val = self._get_float("EXIF FocalLengthIn35mmFilm")
if val is not None:
return "%dmm" % val
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L197-L201
| 40 |
[
0,
1,
2,
3
] | 80 |
[
4
] | 20 | false | 81.971831 | 5 | 2 | 80 | 0 |
def focal_length_35mm(self):
val = self._get_float("EXIF FocalLengthIn35mmFilm")
if val is not None:
return "%dmm" % val
return None
| 26,082 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.flash_info
|
(self)
|
return value.decode("utf-8")
| 204 | 211 |
def flash_info(self):
try:
value = self._mapping["EXIF Flash"].printable
except KeyError:
return None
if isinstance(value, str):
return value
return value.decode("utf-8")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L204-L211
| 40 |
[
0,
1,
2,
5,
6
] | 62.5 |
[
3,
4,
7
] | 37.5 | false | 81.971831 | 8 | 3 | 62.5 | 0 |
def flash_info(self):
try:
value = self._mapping["EXIF Flash"].printable
except KeyError:
return None
if isinstance(value, str):
return value
return value.decode("utf-8")
| 26,083 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.iso
|
(self)
|
return None
| 214 | 218 |
def iso(self):
val = self._get_int("EXIF ISOSpeedRatings")
if val is not None:
return val
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L214-L218
| 40 |
[
0,
1,
2,
3
] | 80 |
[
4
] | 20 | false | 81.971831 | 5 | 2 | 80 | 0 |
def iso(self):
val = self._get_int("EXIF ISOSpeedRatings")
if val is not None:
return val
return None
| 26,084 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.created_at
|
(self)
|
return None
| 221 | 236 |
def created_at(self):
date_tags = (
"GPS GPSDate",
"Image DateTimeOriginal",
"EXIF DateTimeOriginal",
"EXIF DateTimeDigitized",
"Image DateTime",
)
for tag in date_tags:
try:
return datetime.strptime(
self._mapping[tag].printable, "%Y:%m:%d %H:%M:%S"
)
except (KeyError, ValueError):
continue
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L221-L236
| 40 |
[
0,
1,
8,
9,
10,
13,
14
] | 43.75 |
[
15
] | 6.25 | false | 81.971831 | 16 | 3 | 93.75 | 0 |
def created_at(self):
date_tags = (
"GPS GPSDate",
"Image DateTimeOriginal",
"EXIF DateTimeOriginal",
"EXIF DateTimeDigitized",
"Image DateTime",
)
for tag in date_tags:
try:
return datetime.strptime(
self._mapping[tag].printable, "%Y:%m:%d %H:%M:%S"
)
except (KeyError, ValueError):
continue
return None
| 26,085 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.longitude
|
(self)
| 239 | 246 |
def longitude(self):
try:
return _convert_gps(
self._mapping["GPS GPSLongitude"].values,
self._mapping["GPS GPSLongitudeRef"].printable,
)
except KeyError:
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L239-L246
| 40 |
[
0,
1,
2
] | 37.5 |
[
6,
7
] | 25 | false | 81.971831 | 8 | 2 | 75 | 0 |
def longitude(self):
try:
return _convert_gps(
self._mapping["GPS GPSLongitude"].values,
self._mapping["GPS GPSLongitudeRef"].printable,
)
except KeyError:
return None
| 26,086 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.latitude
|
(self)
| 249 | 256 |
def latitude(self):
try:
return _convert_gps(
self._mapping["GPS GPSLatitude"].values,
self._mapping["GPS GPSLatitudeRef"].printable,
)
except KeyError:
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L249-L256
| 40 |
[
0,
1,
2
] | 37.5 |
[
6,
7
] | 25 | false | 81.971831 | 8 | 2 | 75 | 0 |
def latitude(self):
try:
return _convert_gps(
self._mapping["GPS GPSLatitude"].values,
self._mapping["GPS GPSLatitudeRef"].printable,
)
except KeyError:
return None
| 26,087 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.altitude
|
(self)
|
return None
| 259 | 269 |
def altitude(self):
val = self._get_float("GPS GPSAltitude")
if val is not None:
try:
ref = self._mapping["GPS GPSAltitudeRef"].values[0]
except LookupError:
ref = 0
if ref == 1:
val *= -1
return val
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L259-L269
| 40 |
[
0,
1,
2,
3,
4,
7,
9
] | 63.636364 |
[
5,
6,
8,
10
] | 36.363636 | false | 81.971831 | 11 | 4 | 63.636364 | 0 |
def altitude(self):
val = self._get_float("GPS GPSAltitude")
if val is not None:
try:
ref = self._mapping["GPS GPSAltitudeRef"].values[0]
except LookupError:
ref = 0
if ref == 1:
val *= -1
return val
return None
| 26,088 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.location
|
(self)
|
return None
| 272 | 277 |
def location(self):
lat = self.latitude
long = self.longitude
if lat is not None and long is not None:
return (lat, long)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L272-L277
| 40 |
[
0,
1,
2,
3,
4
] | 83.333333 |
[
5
] | 16.666667 | false | 81.971831 | 6 | 3 | 83.333333 | 0 |
def location(self):
lat = self.latitude
long = self.longitude
if lat is not None and long is not None:
return (lat, long)
return None
| 26,089 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.documentname
|
(self)
|
return self._get_string("Image DocumentName")
| 280 | 281 |
def documentname(self):
return self._get_string("Image DocumentName")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L280-L281
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def documentname(self):
return self._get_string("Image DocumentName")
| 26,090 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.description
|
(self)
|
return self._get_string("Image ImageDescription")
| 284 | 285 |
def description(self):
return self._get_string("Image ImageDescription")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L284-L285
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 81.971831 | 2 | 1 | 100 | 0 |
def description(self):
return self._get_string("Image ImageDescription")
| 26,091 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
EXIFInfo.is_rotated
|
(self)
|
return self._get_int("Image Orientation") in {5, 6, 7, 8}
|
Return if the image is rotated according to the Orientation header.
The Orientation header in EXIF stores an integer value between
1 and 8, where the values 5-8 represent "portrait" orientations
(rotated 90deg left, right, and mirrored versions of those), i.e.,
the image is rotated.
|
Return if the image is rotated according to the Orientation header.
| 288 | 296 |
def is_rotated(self):
"""Return if the image is rotated according to the Orientation header.
The Orientation header in EXIF stores an integer value between
1 and 8, where the values 5-8 represent "portrait" orientations
(rotated 90deg left, right, and mirrored versions of those), i.e.,
the image is rotated.
"""
return self._get_int("Image Orientation") in {5, 6, 7, 8}
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L288-L296
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 81.971831 | 9 | 1 | 100 | 6 |
def is_rotated(self):
return self._get_int("Image Orientation") in {5, 6, 7, 8}
| 26,092 |
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
Thumbnail.__init__
|
(self, url_path, width, height=None)
| 626 | 632 |
def __init__(self, url_path, width, height=None):
#: the `width` of the thumbnail in pixels.
self.width = width
#: the `height` of the thumbnail in pixels.
self.height = height
#: the URL path of the image.
self.url_path = url_path
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L626-L632
| 40 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 81.971831 | 7 | 1 | 100 | 0 |
def __init__(self, url_path, width, height=None):
#: the `width` of the thumbnail in pixels.
self.width = width
#: the `height` of the thumbnail in pixels.
self.height = height
#: the URL path of the image.
self.url_path = url_path
| 26,093 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/imagetools.py
|
Thumbnail.__str__
|
(self)
|
return posixpath.basename(self.url_path)
| 634 | 635 |
def __str__(self):
return posixpath.basename(self.url_path)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/imagetools.py#L634-L635
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 81.971831 | 2 | 1 | 50 | 0 |
def __str__(self):
return posixpath.basename(self.url_path)
| 26,094 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/databags.py
|
load_databag
|
(filename)
| 15 | 27 |
def load_databag(filename):
try:
if filename.endswith(".json"):
with open(filename, "r", encoding="utf-8") as f:
return json.load(f, object_pairs_hook=OrderedDict)
elif filename.endswith(".ini"):
return decode_flat_data(IniFile(filename).items(), dict_cls=OrderedDict)
else:
return None
except (OSError, IOError) as e:
if e.errno != errno.ENOENT:
raise
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/databags.py#L15-L27
| 40 |
[
0
] | 7.692308 |
[
1,
2,
3,
4,
5,
6,
8,
9,
10,
11,
12
] | 84.615385 | false | 37.704918 | 13 | 6 | 15.384615 | 0 |
def load_databag(filename):
try:
if filename.endswith(".json"):
with open(filename, "r", encoding="utf-8") as f:
return json.load(f, object_pairs_hook=OrderedDict)
elif filename.endswith(".ini"):
return decode_flat_data(IniFile(filename).items(), dict_cls=OrderedDict)
else:
return None
except (OSError, IOError) as e:
if e.errno != errno.ENOENT:
raise
return None
| 26,095 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/databags.py
|
Databags.__init__
|
(self, env)
| 31 | 43 |
def __init__(self, env):
self.env = env
self.root_path = os.path.join(self.env.root_path, "databags")
self._known_bags = {}
self._bags = {}
try:
for filename in os.listdir(self.root_path):
if filename.endswith((".ini", ".json")):
self._known_bags.setdefault(filename.rsplit(".", -1)[0], []).append(
filename
)
except OSError:
pass
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/databags.py#L31-L43
| 40 |
[
0,
1,
2,
3,
4,
5,
6,
11,
12
] | 69.230769 |
[
7,
8
] | 15.384615 | false | 37.704918 | 13 | 4 | 84.615385 | 0 |
def __init__(self, env):
self.env = env
self.root_path = os.path.join(self.env.root_path, "databags")
self._known_bags = {}
self._bags = {}
try:
for filename in os.listdir(self.root_path):
if filename.endswith((".ini", ".json")):
self._known_bags.setdefault(filename.rsplit(".", -1)[0], []).append(
filename
)
except OSError:
pass
| 26,096 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/databags.py
|
Databags.get_bag
|
(self, name)
|
return rv
| 45 | 66 |
def get_bag(self, name):
sources = self._known_bags.get(name)
if not sources:
return None
rv = self._bags.get(name)
if rv is None:
filenames = []
rv = OrderedDict()
for filename in sources:
filename = os.path.join(self.root_path, filename)
rv = merge(rv, load_databag(filename))
filenames.append(filename)
self._bags[name] = (rv, filenames)
else:
rv, filenames = rv
ctx = get_ctx()
if ctx is not None:
for filename in filenames:
ctx.record_dependency(filename)
return rv
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/databags.py#L45-L66
| 40 |
[
0
] | 4.545455 |
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
14,
16,
17,
18,
19,
21
] | 81.818182 | false | 37.704918 | 22 | 6 | 18.181818 | 0 |
def get_bag(self, name):
sources = self._known_bags.get(name)
if not sources:
return None
rv = self._bags.get(name)
if rv is None:
filenames = []
rv = OrderedDict()
for filename in sources:
filename = os.path.join(self.root_path, filename)
rv = merge(rv, load_databag(filename))
filenames.append(filename)
self._bags[name] = (rv, filenames)
else:
rv, filenames = rv
ctx = get_ctx()
if ctx is not None:
for filename in filenames:
ctx.record_dependency(filename)
return rv
| 26,097 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/databags.py
|
Databags.lookup
|
(self, key)
|
return None
| 68 | 75 |
def lookup(self, key):
for prefix, local_key in iter_dotted_path_prefixes(key):
bag = self.get_bag(prefix)
if bag is not None:
if local_key is None:
return bag
return resolve_dotted_value(bag, local_key)
return None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/databags.py#L68-L75
| 40 |
[
0
] | 12.5 |
[
1,
2,
3,
4,
5,
6,
7
] | 87.5 | false | 37.704918 | 8 | 4 | 12.5 | 0 |
def lookup(self, key):
for prefix, local_key in iter_dotted_path_prefixes(key):
bag = self.get_bag(prefix)
if bag is not None:
if local_key is None:
return bag
return resolve_dotted_value(bag, local_key)
return None
| 26,098 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.__init__
|
(self, filename)
| 9 | 14 |
def __init__(self, filename):
self.filename = filename
self._md5 = None
self._sha1 = None
self._integrity = None
self._mimetype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L9-L14
| 40 |
[
0
] | 16.666667 |
[
1,
2,
3,
4,
5
] | 83.333333 | false | 34.285714 | 6 | 2 | 16.666667 | 0 |
def __init__(self, filename):
self.filename = filename
self._md5 = None
self._sha1 = None
self._integrity = None
self._mimetype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
| 26,099 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.sha1
|
(self)
|
return self._sha1
| 17 | 19 |
def sha1(self):
self._ensure_hashes()
return self._sha1
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L17-L19
| 40 |
[
0
] | 33.333333 |
[
1,
2
] | 66.666667 | false | 34.285714 | 3 | 1 | 33.333333 | 0 |
def sha1(self):
self._ensure_hashes()
return self._sha1
| 26,100 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.md5
|
(self)
|
return self._md5
| 22 | 24 |
def md5(self):
self._ensure_hashes()
return self._md5
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L22-L24
| 40 |
[
0
] | 33.333333 |
[
1,
2
] | 66.666667 | false | 34.285714 | 3 | 1 | 33.333333 | 0 |
def md5(self):
self._ensure_hashes()
return self._md5
| 26,101 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.integrity
|
(self)
|
return self._integrity
| 27 | 29 |
def integrity(self):
self._ensure_hashes()
return self._integrity
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L27-L29
| 40 |
[
0
] | 33.333333 |
[
1,
2
] | 66.666667 | false | 34.285714 | 3 | 1 | 33.333333 | 0 |
def integrity(self):
self._ensure_hashes()
return self._integrity
| 26,102 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.mimetype
|
(self)
|
return self._mimetype
| 32 | 33 |
def mimetype(self):
return self._mimetype
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L32-L33
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 34.285714 | 2 | 1 | 50 | 0 |
def mimetype(self):
return self._mimetype
| 26,103 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.bytes
|
(self)
| 36 | 40 |
def bytes(self):
try:
return os.stat(self.filename).st_size
except (OSError, IOError):
return 0
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L36-L40
| 40 |
[
0
] | 20 |
[
1,
2,
3,
4
] | 80 | false | 34.285714 | 5 | 2 | 20 | 0 |
def bytes(self):
try:
return os.stat(self.filename).st_size
except (OSError, IOError):
return 0
| 26,104 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.as_data_url
|
(self, mediatype=None)
|
return "data:%s;base64,%s" % (
mediatype,
self.as_base64(),
)
| 42 | 48 |
def as_data_url(self, mediatype=None):
if mediatype is None:
mediatype = self.mimetype
return "data:%s;base64,%s" % (
mediatype,
self.as_base64(),
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L42-L48
| 40 |
[
0
] | 14.285714 |
[
1,
2,
3
] | 42.857143 | false | 34.285714 | 7 | 2 | 57.142857 | 0 |
def as_data_url(self, mediatype=None):
if mediatype is None:
mediatype = self.mimetype
return "data:%s;base64,%s" % (
mediatype,
self.as_base64(),
)
| 26,105 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.as_text
|
(self)
| 50 | 52 |
def as_text(self):
with self.open() as f:
return f.read()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L50-L52
| 40 |
[
0
] | 33.333333 |
[
1,
2
] | 66.666667 | false | 34.285714 | 3 | 2 | 33.333333 | 0 |
def as_text(self):
with self.open() as f:
return f.read()
| 26,106 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.as_bytes
|
(self)
| 54 | 56 |
def as_bytes(self):
with self.open("rb") as f:
return f.read()
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L54-L56
| 40 |
[
0
] | 33.333333 |
[
1,
2
] | 66.666667 | false | 34.285714 | 3 | 2 | 33.333333 | 0 |
def as_bytes(self):
with self.open("rb") as f:
return f.read()
| 26,107 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.as_base64
|
(self)
|
return base64.b64encode(self.as_bytes())
| 58 | 59 |
def as_base64(self):
return base64.b64encode(self.as_bytes())
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L58-L59
| 40 |
[
0
] | 50 |
[
1
] | 50 | false | 34.285714 | 2 | 1 | 50 | 0 |
def as_base64(self):
return base64.b64encode(self.as_bytes())
| 26,108 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.open
|
(self, mode="r", encoding=None)
|
return codecs.open(self.filename, encoding=encoding or "utf-8")
| 61 | 66 |
def open(self, mode="r", encoding=None):
if mode == "rb":
return open(self.filename, "rb")
if mode != "r":
raise TypeError("Can only open files for reading")
return codecs.open(self.filename, encoding=encoding or "utf-8")
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L61-L66
| 40 |
[
0
] | 16.666667 |
[
1,
2,
3,
4,
5
] | 83.333333 | false | 34.285714 | 6 | 4 | 16.666667 | 0 |
def open(self, mode="r", encoding=None):
if mode == "rb":
return open(self.filename, "rb")
if mode != "r":
raise TypeError("Can only open files for reading")
return codecs.open(self.filename, encoding=encoding or "utf-8")
| 26,109 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents._ensure_hashes
|
(self)
| 68 | 86 |
def _ensure_hashes(self):
if self._md5 is not None:
return
with self.open("rb") as f:
md5 = hashlib.md5()
sha1 = hashlib.sha1()
sha384 = hashlib.sha384()
while 1:
chunk = f.read(16384)
if not chunk:
break
md5.update(chunk)
sha1.update(chunk)
sha384.update(chunk)
self._md5 = md5.hexdigest()
self._sha1 = sha1.hexdigest()
self._integrity = "sha384-" + base64.b64encode(sha384.digest()).decode(
"ascii"
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L68-L86
| 40 |
[
0
] | 5.263158 |
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16
] | 84.210526 | false | 34.285714 | 19 | 5 | 15.789474 | 0 |
def _ensure_hashes(self):
if self._md5 is not None:
return
with self.open("rb") as f:
md5 = hashlib.md5()
sha1 = hashlib.sha1()
sha384 = hashlib.sha384()
while 1:
chunk = f.read(16384)
if not chunk:
break
md5.update(chunk)
sha1.update(chunk)
sha384.update(chunk)
self._md5 = md5.hexdigest()
self._sha1 = sha1.hexdigest()
self._integrity = "sha384-" + base64.b64encode(sha384.digest()).decode(
"ascii"
)
| 26,110 |
|||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/filecontents.py
|
FileContents.__repr__
|
(self)
|
return "<FileContents %r md5=%r>" % (
self.filename,
self.md5,
)
| 88 | 92 |
def __repr__(self):
return "<FileContents %r md5=%r>" % (
self.filename,
self.md5,
)
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/filecontents.py#L88-L92
| 40 |
[
0
] | 20 |
[
1
] | 20 | false | 34.285714 | 5 | 1 | 80 | 0 |
def __repr__(self):
return "<FileContents %r md5=%r>" % (
self.filename,
self.md5,
)
| 26,111 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/utils.py
|
split_virtual_path
|
(path)
|
return path, None
| 46 | 49 |
def split_virtual_path(path):
if "@" in path:
return path.split("@", 1)
return path, None
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L46-L49
| 40 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 63.731656 | 4 | 2 | 100 | 0 |
def split_virtual_path(path):
if "@" in path:
return path.split("@", 1)
return path, None
| 26,112 |
||
lektor/lektor
|
74bce9096116caffe27ab69327ed4ba274e66e1e
|
lektor/utils.py
|
_norm_join
|
(a, b)
|
return posixpath.normpath(posixpath.join(a, b))
| 52 | 53 |
def _norm_join(a, b):
return posixpath.normpath(posixpath.join(a, b))
|
https://github.com/lektor/lektor/blob/74bce9096116caffe27ab69327ed4ba274e66e1e/project40/lektor/utils.py#L52-L53
| 40 |
[
0,
1
] | 100 |
[] | 0 | true | 63.731656 | 2 | 1 | 100 | 0 |
def _norm_join(a, b):
return posixpath.normpath(posixpath.join(a, b))
| 26,113 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.