本文整理汇总了Python中mapproxy.compat.iteritems函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems函数的具体用法?Python iteritems怎么用?Python iteritems使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iteritems函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_config
def update_config(conf, overwrites):
wildcard_keys = []
for k, v in iteritems(overwrites):
if k == '__all__':
continue
if k.startswith('___') or k.endswith('___'):
wildcard_keys.append(k)
continue
if k.endswith('__extend__'):
k = k[:-len('__extend__')]
if k not in conf:
conf[k] = v
elif isinstance(v, list):
conf[k].extend(v)
else:
raise ValueError('cannot extend non-list:', v)
elif k not in conf:
conf[k] = copy(v)
else:
if isinstance(conf[k], dict) and isinstance(v, dict):
conf[k] = update_config(conf[k], v)
else:
conf[k] = copy(v)
if '__all__' in overwrites:
v = overwrites['__all__']
for conf_k, conf_v in iteritems(conf):
if isinstance(conf_v, dict):
conf[conf_k] = update_config(conf_v, v)
else:
conf[conf_k] = v
if wildcard_keys:
for key in wildcard_keys:
v = overwrites[key]
if key.startswith('___'):
key = key[3:]
key_check = lambda x: x.endswith(key)
else:
key = key[:-3]
key_check = lambda x: x.startswith(key)
for conf_k, conf_v in iteritems(conf):
if not key_check(conf_k):
continue
if isinstance(conf_v, dict):
conf[conf_k] = update_config(conf_v, v)
else:
conf[conf_k] = v
return conf
示例2: is_cached
def is_cached(self, tile):
if tile.source or tile.coord is None:
return True
for bundle_file, bundle_tiles in iteritems(self._get_bundle_tiles([tile])):
with BundleDataV2(bundle_file) as bundledata:
for tile in bundle_tiles:
return bundledata.tile_size(tile.coord) != 0
示例3: adapt_params_to_version
def adapt_params_to_version(self):
params = self.params.copy()
for key, value in iteritems(self.fixed_params):
params[key] = value
if 'styles' not in params:
params['styles'] = ''
return params
示例4: __repr__
def __repr__(self):
items = [
(k, v) for k, v in iteritems(self)]
items.sort()
return '<%s %s>' % (
self.__class__.__name__,
' '.join(['%s=%r' % (k, v) for k, v in items]))
示例5: remove_tile
def remove_tile(self, tile):
if tile.coord is None:
return True
for bundle_file, bundle_tiles in iteritems(self._get_bundle_tiles([tile])):
with BundleDataV2(bundle_file, mode="write") as bundledata:
for tile in bundle_tiles:
return bundledata.remove_tile(tile)
示例6: restart_with_reloader
def restart_with_reloader():
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log('info', ' * Restarting with reloader')
args = [sys.executable] + sys.argv
# pip installs commands as .exe, but sys.argv[0]
# can miss the prefix. add .exe to avoid file-not-found
# in subprocess call
if os.name == 'nt' and '.' not in args[1]:
args[1] = args[1] + '.exe'
new_environ = os.environ.copy()
new_environ['WERKZEUG_RUN_MAIN'] = 'true'
# a weird bug on windows. sometimes unicode strings end up in the
# environment and subprocess.call does not like this, encode them
# to latin1 and continue.
if os.name == 'nt' and PY2:
for key, value in iteritems(new_environ):
if isinstance(value, text_type):
new_environ[key] = value.encode('iso-8859-1')
exit_code = subprocess.call(args, env=new_environ)
if exit_code != 3:
return exit_code
示例7: layer_srs_bbox
def layer_srs_bbox(self, layer, epsg_axis_order=False):
for srs, extent in iteritems(self.srs_extents):
# is_default is True when no explicit bbox is defined for this srs
# use layer extent
if extent.is_default:
bbox = layer.extent.bbox_for(SRS(srs))
elif layer.extent.is_default:
bbox = extent.bbox_for(SRS(srs))
else:
# Use intersection of srs_extent and layer.extent.
bbox = extent.intersection(layer.extent).bbox_for(SRS(srs))
if epsg_axis_order:
bbox = switch_bbox_epsg_axis_order(bbox, srs)
if srs in self.srs:
yield srs, bbox
# add native srs
layer_srs_code = layer.extent.srs.srs_code
if layer_srs_code not in self.srs_extents:
bbox = layer.extent.bbox
if epsg_axis_order:
bbox = switch_bbox_epsg_axis_order(bbox, layer_srs_code)
if layer_srs_code in self.srs:
yield layer_srs_code, bbox
示例8: print_layers
def print_layers(self, capabilities, indent=None, root=False):
if root:
print("# Note: This is not a valid MapProxy configuration!")
print('Capabilities Document Version %s' % (self.version,))
print('Root-Layer:')
layer_list = capabilities.layers()['layers']
else:
layer_list = capabilities['layers']
indent = indent or self.indent
for layer in layer_list:
marked_first = False
# print ordered items first
for item in self.print_order:
if layer.get(item, False):
if not marked_first:
marked_first = True
self._format_output(item, layer[item], indent, mark_first=marked_first)
else:
self._format_output(item, layer[item], indent)
# print remaining items except sublayers
for key, value in iteritems(layer):
if key in self.print_order or key == 'layers':
continue
self._format_output(key, value, indent)
# print the sublayers now
if layer.get('layers', False):
self.print_line(indent, 'layers')
self.print_layers(layer, indent=indent+self.indent)
示例9: load_base_config
def load_base_config(config_file=None, clear_existing=False):
"""
Load system wide base configuration.
:param config_file: the file name of the mapproxy.yaml configuration.
if ``None``, load the internal proxylib/default.yaml conf
:param clear_existing: if ``True`` remove the existing configuration settings,
else overwrite the settings.
"""
if config_file is None:
from mapproxy.config import defaults
config_dict = {}
for k, v in iteritems(defaults.__dict__):
if k.startswith('_'): continue
config_dict[k] = v
conf_base_dir = os.getcwd()
load_config(base_config(), config_dict=config_dict, clear_existing=clear_existing)
else:
conf_base_dir = os.path.abspath(os.path.dirname(config_file))
load_config(base_config(), config_file=config_file, clear_existing=clear_existing)
bc = base_config()
finish_base_config(bc)
bc.conf_base_dir = conf_base_dir
示例10: restart_with_reloader
def restart_with_reloader():
"""Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.
"""
while 1:
_log('info', ' * Restarting with reloader')
args = [sys.executable] + sys.argv
if os.name == 'nt':
# pip installs commands as .exe, but sys.argv[0]
# can miss the prefix.
# Add .exe to avoid file-not-found in subprocess call.
# Also, recent pip versions create .exe commands that are not
# executable by Python, but there is a -script.py which
# we need to call in this case. Check for this first.
if os.path.exists(args[1] + '-script.py'):
args[1] = args[1] + '-script.py'
elif not args[1].endswith('.exe'):
args[1] = args[1] + '.exe'
new_environ = os.environ.copy()
new_environ['WERKZEUG_RUN_MAIN'] = 'true'
# a weird bug on windows. sometimes unicode strings end up in the
# environment and subprocess.call does not like this, encode them
# to latin1 and continue.
if os.name == 'nt' and PY2:
for key, value in iteritems(new_environ):
if isinstance(value, text_type):
new_environ[key] = value.encode('iso-8859-1')
exit_code = subprocess.call(args, env=new_environ)
if exit_code != 3:
return exit_code
示例11: __getitem__
def __getitem__(self, key):
if self.defaults is None:
defaults = {}
for epsg, bbox in iteritems(self._defaults):
defaults[SRS(epsg)] = bbox
self.defaults = defaults
return self.defaults[key]
示例12: __init__
def __init__(self, seed_conf, mapproxy_conf):
self.conf = seed_conf
self.mapproxy_conf = mapproxy_conf
self.grids = bidict((name, grid_conf.tile_grid()) for name, grid_conf in iteritems(self.mapproxy_conf.grids))
self.seed_tasks = []
self.cleanup_tasks = []
self._init_tasks()
示例13: seed_tasks
def seed_tasks(self):
for grid_name in self.grids:
for cache_name, cache in iteritems(self.caches):
tile_manager = cache[grid_name]
grid = self.seeding_conf.grids[grid_name]
if self.coverage is False:
coverage = False
elif self.coverage:
coverage = self.coverage.transform_to(grid.srs)
else:
coverage = BBOXCoverage(grid.bbox, grid.srs)
try:
if coverage is not False:
coverage.extent.llbbox
except TransformationError:
raise SeedConfigurationError('%s: coverage transformation error' % self.name)
if self.levels:
levels = self.levels.for_grid(grid)
else:
levels = list(range(0, grid.levels))
if not tile_manager.cache.supports_timestamp:
if self.refresh_timestamp:
# remove everything
self.refresh_timestamp = 0
md = dict(name=self.name, cache_name=cache_name, grid_name=grid_name)
yield SeedTask(md, tile_manager, levels, self.refresh_timestamp, coverage)
示例14: adapt_params_to_version
def adapt_params_to_version(self):
params = self.params.copy()
for key, value in iteritems(self.fixed_params):
params[key] = value
if "styles" not in params:
params["styles"] = ""
return params
示例15: fixed_headers
def fixed_headers(self):
headers = []
for key, value in iteritems(self.headers):
if PY2 and isinstance(value, unicode):
value = value.encode('utf-8')
headers.append((key, value))
return headers