Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _reflow_and_split_labels(labels):
rv = []
for lang, string in iteritems(labels):
for idx, item in enumerate(string.split(',')):
try:
d = rv[idx]
except LookupError:
d = {}
rv.append(d)
d[lang] = item.strip()
return rv
def write_source_info(self, info):
"""Writes the source info into the database. The source info is
an instance of :class:`lektor.build_programs.SourceInfo`.
"""
reporter.report_write_source_info(info)
source = self.to_source_filename(info.filename)
con = self.connect_to_database()
try:
cur = con.cursor()
for lang, title in iteritems(info.title_i18n):
cur.execute('''
insert or replace into source_info
(path, alt, lang, type, source, title)
values (?, ?, ?, ?, ?, ?)
''', [info.path, info.alt, lang, info.type, source, title])
con.commit()
finally:
con.close()
def merge(a, b):
"""Merges two values together."""
if b is None and a is not None:
return a
if a is None:
return b
if isinstance(a, list) and isinstance(b, list):
for idx, (item_1, item_2) in enumerate(zip(a, b)):
a[idx] = merge(item_1, item_2)
if isinstance(a, dict) and isinstance(b, dict):
for key, value in iteritems(b):
a[key] = merge(a.get(key), value)
return a
return a
def remove_package_from_project(project, name):
cfg = project.open_config()
choices = (name.lower(), 'lektor-' + name.lower())
for pkg, version in iteritems(cfg.section_as_dict('packages')):
if pkg.lower() in choices:
del cfg['packages.%s' % pkg]
cfg.save()
return {
'name': pkg,
'version': version
}
return None
if _value_marker in container:
force_list = False
values = container.pop(_value_marker)
if container.pop(_list_marker, False):
force_list = True
values.extend(_convert(x[1]) for x in
sorted(container.items()))
if not force_list and len(values) == 1:
values = values[0]
if not container:
return values
return _convert(container)
elif container.pop(_list_marker, False):
return [_convert(x[1]) for x in sorted(container.items())]
return dict_cls((k, _convert(v)) for k, v in iteritems(container))
def __init__(self, path, filename, alt=PRIMARY_ALT,
type='unknown', title_i18n=None):
self.path = path
self.alt = alt
self.filename = filename
self.type = type
self.title_i18n = {}
en_title = self.path
if 'en' in title_i18n:
en_title = title_i18n['en']
for key, value in iteritems(title_i18n):
if key == 'en':
continue
if value != en_title:
self.title_i18n[key] = value
self.title_i18n['en'] = en_title
known_folders = set()
for artifact_name in iterkeys(current_artifacts):
known_folders.add(posixpath.dirname(artifact_name))
for artifact_name, checksum in iteritems(server_artifacts):
if artifact_name not in current_artifacts:
con.log_buffer.append('000 Deleting %s' % artifact_name)
con.delete_file(artifact_name)
folder = posixpath.dirname(artifact_name)
if folder not in known_folders:
con.log_buffer.append('000 Deleting %s' % folder)
con.delete_folder(folder)
if duplicates or server_artifacts != current_artifacts:
listing = []
for artifact_name, checksum in iteritems(current_artifacts):
listing.append('%s|%s\n' % (artifact_name, checksum))
listing.sort()
con.upload_file('.lektor/.listing.tmp', ''.join(listing))
con.rename_file('.lektor/.listing.tmp', '.lektor/listing')
def merge(a, b):
"""Merges two values together."""
if b is None and a is not None:
return a
if a is None:
return b
if isinstance(a, list) and isinstance(b, list):
for idx, (item_1, item_2) in enumerate(zip(a, b)):
a[idx] = merge(item_1, item_2)
if isinstance(a, dict) and isinstance(b, dict):
for key, value in iteritems(b):
a[key] = merge(a.get(key), value)
return a
return a
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
rv = Type.to_json(self, pad, record, alt)
rv['flowblocks'] = discover_relevant_flowblock_models(
self, pad, record, alt)
block_order = self.flow_blocks
if block_order is None:
block_order = [k for k, v in sorted(iteritems(pad.db.flowblocks),
key=lambda x: x[1].order)]
rv['flowblock_order'] = block_order
return rv