本文整理汇总了Python中mapproxy.config.base_config函数的典型用法代码示例。如果您正苦于以下问题:Python base_config函数的具体用法?Python base_config怎么用?Python base_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了base_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_proj
def _init_proj():
global _proj_initalized
if not _proj_initalized and 'proj_data_dir' in base_config().srs:
proj_data_dir = base_config().srs['proj_data_dir']
log_system.info('loading proj data from %s', proj_data_dir)
set_datapath(proj_data_dir)
_proj_initalized = True
示例2: img_to_buf
def img_to_buf(img, image_opts):
defaults = {}
if image_opts.mode and img.mode[0] == "I" and img.mode != image_opts.mode:
img = img.convert(image_opts.mode)
if image_opts.colors is None and base_config().image.paletted and image_opts.format.endswith("png"):
# force 255 colors for png with globals.image.paletted
image_opts = image_opts.copy()
image_opts.colors = 255
if image_opts.colors:
quantizer = None
if "quantizer" in image_opts.encoding_options:
quantizer = image_opts.encoding_options["quantizer"]
if image_opts.transparent:
img = quantize(img, colors=image_opts.colors, alpha=True, defaults=defaults, quantizer=quantizer)
else:
img = quantize(img, colors=image_opts.colors, quantizer=quantizer)
if hasattr(Image, "RLE"):
defaults["compress_type"] = Image.RLE
format = filter_format(image_opts.format.ext)
buf = StringIO()
if format == "jpeg":
img = img.convert("RGB")
if "jpeg_quality" in image_opts.encoding_options:
defaults["quality"] = image_opts.encoding_options["jpeg_quality"]
else:
defaults["quality"] = base_config().image.jpeg_quality
img.save(buf, format, **defaults)
buf.seek(0)
return buf
示例3: test_defaults
def test_defaults(self):
with TempFiles() as tmp:
with open(tmp[0], 'wb') as f:
f.write(TestDefaultsLoading.defaults_yaml)
load_base_config(config_file=tmp[0], clear_existing=True)
assert base_config().biz == 'foobar'
assert base_config().wiz == 'foobar'
assert base_config().foo.bar.ham == 2
assert base_config().foo.bar.eggs == 4
assert not hasattr(base_config(), 'wms')
示例4: img_to_buf
def img_to_buf(img, image_opts):
defaults = {}
image_opts = image_opts.copy()
# convert I or L images to target mode
if image_opts.mode and img.mode[0] in ('I', 'L') and img.mode != image_opts.mode:
img = img.convert(image_opts.mode)
if (image_opts.colors is None and base_config().image.paletted
and image_opts.format.endswith('png')):
# force 255 colors for png with globals.image.paletted
image_opts.colors = 255
format = filter_format(image_opts.format.ext)
if format == 'mixed':
if img_has_transparency(img):
format = 'png'
else:
format = 'jpeg'
image_opts.colors = None
image_opts.transparent = False
# quantize if colors is set, but not if we already have a paletted image
if image_opts.colors and not (img.mode == 'P' and len(img.getpalette()) == image_opts.colors*3):
quantizer = None
if 'quantizer' in image_opts.encoding_options:
quantizer = image_opts.encoding_options['quantizer']
if image_opts.transparent:
img = quantize(img, colors=image_opts.colors, alpha=True,
defaults=defaults, quantizer=quantizer)
else:
img = quantize(img, colors=image_opts.colors,
quantizer=quantizer)
if hasattr(Image, 'RLE'):
defaults['compress_type'] = Image.RLE
buf = BytesIO()
if format == 'jpeg':
img = img.convert('RGB')
if 'jpeg_quality' in image_opts.encoding_options:
defaults['quality'] = image_opts.encoding_options['jpeg_quality']
else:
defaults['quality'] = base_config().image.jpeg_quality
# unsupported transparency tuple can still be in non-RGB img.infos
# see: https://github.com/python-pillow/Pillow/pull/2633
if format == 'png' and img.mode != 'RGB' and 'transparency' in img.info and isinstance(img.info['transparency'], tuple):
del img.info['transparency']
img.save(buf, format, **defaults)
buf.seek(0)
return buf
示例5: test_base_config
def test_base_config(self):
# test that all concurrent have access to their
# local base_config
from mapproxy.config import base_config
from mapproxy.config import local_base_config
from copy import deepcopy
# make two separate base_configs
conf1 = deepcopy(base_config())
conf1.conf = 1
conf2 = deepcopy(base_config())
conf2.conf = 2
base_config().bar = 'baz'
# run test in parallel, check1 and check2 should interleave
# each with their local conf
error_occured = False
def check1(x):
global error_occured
if base_config().conf != 1 or 'bar' in base_config():
error_occured = True
def check2(x):
global error_occured
if base_config().conf != 2 or 'bar' in base_config():
error_occured = True
assert 'bar' in base_config()
def test1():
with local_base_config(conf1):
pool1 = ThreadPool(5)
list(pool1.imap(check1, range(200)))
def test2():
with local_base_config(conf2):
pool2 = ThreadPool(5)
list(pool2.imap(check2, range(200)))
t1 = threading.Thread(target=test1)
t2 = threading.Thread(target=test2)
t1.start()
t2.start()
t1.join()
t2.join()
assert not error_occured
assert 'bar' in base_config()
示例6: test_user_srs_definitions
def test_user_srs_definitions(self):
user_yaml = b"""
srs:
axis_order_ne: ['EPSG:9999']
"""
with TempFiles() as tmp:
with open(tmp[0], 'wb') as f:
f.write(user_yaml)
load_base_config(config_file=tmp[0])
assert 'EPSG:9999' in base_config().srs.axis_order_ne
assert 'EPSG:9999' not in base_config().srs.axis_order_en
#defaults still there
assert 'EPSG:31468' in base_config().srs.axis_order_ne
assert 'CRS:84' in base_config().srs.axis_order_en
示例7: font_file
def font_file(font_name):
font_dir = base_config().image.font_dir
if font_dir:
abspath(font_dir)
else:
font_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fonts')
font_name = font_name.replace(' ', '')
path = os.path.join(font_dir, font_name + '.ttf')
return path
示例8: font_file
def font_file(font_name):
font_dir = base_config().image.font_dir
font_name = font_name.replace(' ', '')
if font_dir:
abspath(font_dir)
path = os.path.join(font_dir, font_name + '.ttf')
else:
path = pkg_resources.resource_filename(__name__, 'fonts/' + font_name + '.ttf')
return path
示例9: img_to_buf
def img_to_buf(img, image_opts):
defaults = {}
image_opts = image_opts.copy()
if image_opts.mode and img.mode[0] == 'I' and img.mode != image_opts.mode:
img = img.convert(image_opts.mode)
if (image_opts.colors is None and base_config().image.paletted
and image_opts.format.endswith('png')):
# force 255 colors for png with globals.image.paletted
image_opts.colors = 255
format = filter_format(image_opts.format.ext)
if format == 'mixed':
if img_has_transparency(img):
format = 'png'
else:
format = 'jpeg'
image_opts.colors = None
image_opts.transparent = False
if image_opts.colors:
quantizer = None
if 'quantizer' in image_opts.encoding_options:
quantizer = image_opts.encoding_options['quantizer']
if image_opts.transparent:
img = quantize(img, colors=image_opts.colors, alpha=True,
defaults=defaults, quantizer=quantizer)
else:
img = quantize(img, colors=image_opts.colors,
quantizer=quantizer)
if hasattr(Image, 'RLE'):
defaults['compress_type'] = Image.RLE
buf = StringIO()
if format == 'jpeg':
img = img.convert('RGB')
if 'jpeg_quality' in image_opts.encoding_options:
defaults['quality'] = image_opts.encoding_options['jpeg_quality']
else:
defaults['quality'] = base_config().image.jpeg_quality
img.save(buf, format, **defaults)
buf.seek(0)
return buf
示例10: __init__
def __init__(self, task, worker_class, size=2, dry_run=False, progress_logger=None):
self.tiles_queue = queue_class(size)
self.task = task
self.dry_run = dry_run
self.procs = []
self.progress_logger = progress_logger
conf = base_config()
for _ in xrange(size):
worker = worker_class(self.task, self.tiles_queue, conf)
worker.start()
self.procs.append(worker)
示例11: is_axis_order_ne
def is_axis_order_ne(self):
"""
Returns `True` if the axis order is North, then East
(i.e. y/x or lat/lon).
>>> SRS(4326).is_axis_order_ne
True
>>> SRS('CRS:84').is_axis_order_ne
False
>>> SRS(31468).is_axis_order_ne
True
>>> SRS(31463).is_axis_order_ne
False
>>> SRS(25831).is_axis_order_ne
False
"""
if self.srs_code in base_config().srs.axis_order_ne:
return True
if self.srs_code in base_config().srs.axis_order_en:
return False
if self.is_latlong:
return True
return False
示例12: test_defaults_overwrite
def test_defaults_overwrite(self):
with TempFiles(2) as tmp:
with open(tmp[0], 'wb') as f:
f.write(TestDefaultsLoading.defaults_yaml)
with open(tmp[1], 'wb') as f:
f.write(b"""
baz: [9, 2, 1, 4]
biz: 'barfoo'
foo:
bar:
eggs: 5
""")
load_base_config(config_file=tmp[0], clear_existing=True)
load_base_config(config_file=tmp[1])
assert base_config().biz == 'barfoo'
assert base_config().wiz == 'foobar'
assert base_config().baz == [9, 2, 1, 4]
assert base_config().foo.bar.ham == 2
assert base_config().foo.bar.eggs == 5
assert not hasattr(base_config(), 'wms')
示例13: __init__
def __init__(self, task_queue, result_queue):
threading.Thread.__init__(self)
self.task_queue = task_queue
self.result_queue = result_queue
self.base_config = base_config()
示例14: teardown
def teardown(self):
srs._proj_initalized = False
srs._srs_cache = {}
base_config().srs.proj_data_dir = None
示例15: check2
def check2(x):
global error_occured
if base_config().conf != 2 or 'bar' in base_config():
error_occured = True