本文整理汇总了Python中lazy_object_proxy.Proxy方法的典型用法代码示例。如果您正苦于以下问题:Python lazy_object_proxy.Proxy方法的具体用法?Python lazy_object_proxy.Proxy怎么用?Python lazy_object_proxy.Proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lazy_object_proxy
的用法示例。
在下文中一共展示了lazy_object_proxy.Proxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: schemas
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def schemas(self):
"""
object: An object with attributes corresponding to the names of the schemas
in this database.
"""
from lazy_object_proxy import Proxy
def get_schemas():
if not getattr(self, '_schemas', None):
assert getattr(self, '_sqlalchemy_metadata', None) is not None, (
"`{class_name}` instances do not provide the required sqlalchemy metadata "
"for schema exploration.".format(class_name=self.__class__.__name__)
)
self._schemas = Schemas(self._sqlalchemy_metadata)
return self._schemas
return Proxy(get_schemas)
# Extend Table to support returning pandas description of table
示例2: decode
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def decode(content, parse_json=True, use_proxy=True):
if content is None:
return content
if content.startswith(constants.JUMBO_FIELDS_PREFIX):
def unwrap():
location, _size = content.split()
value = _pull_jumbo_field(location)
if parse_json:
return json_loads_or_raw(value)
return value
if use_proxy:
return lazy_object_proxy.Proxy(unwrap)
return unwrap()
if parse_json:
return json_loads_or_raw(content)
return content
示例3: lazy_descriptor
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def lazy_descriptor(obj):
class DescriptorProxy(lazy_object_proxy.Proxy):
def __get__(self, instance, owner=None):
return self.__class__.__get__(self, instance)
return DescriptorProxy(obj)
示例4: lazy_import
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def lazy_import(module_name):
return lazy_object_proxy.Proxy(
lambda: importlib.import_module('.' + module_name, 'astroid'))
示例5: proxy_alias
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def proxy_alias(alias_name, node_type):
"""Get a Proxy from the given name to the given node type."""
proxy = type(alias_name, (lazy_object_proxy.Proxy,),
{'__class__': object.__dict__['__class__'],
'__instancecheck__': _instancecheck})
return proxy(lambda: node_type)
# Backwards-compatibility aliases
示例6: lazy_descriptor
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def lazy_descriptor(obj):
class DescriptorProxy(lazy_object_proxy.Proxy):
def __get__(self, instance, owner=None):
return self.__class__.__get__(self, instance)
return DescriptorProxy(obj)
示例7: lazy_import
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def lazy_import(module_name):
return lazy_object_proxy.Proxy(
lambda: importlib.import_module("." + module_name, "astroid")
)
示例8: proxy_alias
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def proxy_alias(alias_name, node_type):
"""Get a Proxy from the given name to the given node type."""
proxy = type(
alias_name,
(lazy_object_proxy.Proxy,),
{
"__class__": object.__dict__["__class__"],
"__instancecheck__": _instancecheck,
},
)
return proxy(lambda: node_type)
示例9: render_template
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def render_template(self, *args, **kwargs):
return super().render_template(
*args,
# Cache this at most once per request, not for the lifetime of the view instance
scheduler_job=lazy_object_proxy.Proxy(SchedulerJob.most_recent_job),
**kwargs
)
示例10: get_project
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def get_project(self, url: str, get_project_kwargs: dict = None) -> GitProject:
return Proxy(partial(self._get_project, url, get_project_kwargs))
示例11: get_or_create
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def get_or_create(self, schema_spec):
schema_hash = dicthash(schema_spec)
schema_deref = self.dereferencer.dereference(schema_spec)
if schema_hash in self._schemas:
return self._schemas[schema_hash], False
if '$ref' in schema_spec:
schema = Proxy(lambda: self.create(schema_deref))
else:
schema = self.create(schema_deref)
self._schemas[schema_hash] = schema
return schema, True
示例12: serialize_complex_object
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def serialize_complex_object(obj):
if isinstance(obj, bytes): # Python 3 only (serialize_complex_object not called here in Python 2)
return obj.decode('utf-8', errors='replace')
if isinstance(obj, datetime.datetime):
r = obj.isoformat()
if obj.microsecond:
r = r[:23] + r[26:] # milliseconds only
if r.endswith('+00:00'):
r = r[:-6] + 'Z'
return r
elif isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, datetime.time):
r = obj.isoformat()
if obj.microsecond:
r = r[:12]
return r
elif isinstance(obj, types.GeneratorType):
return [i for i in obj]
elif isinstance(obj, Future):
return obj.result
elif isinstance(obj, UUID):
return str(obj)
elif isinstance(obj, lazy_object_proxy.Proxy):
return str(obj)
elif isinstance(obj, (set, frozenset)):
return list(obj)
raise TypeError(
"Type %s couldn't be serialized. This is a bug in simpleflow,"
" please file a new issue on GitHub!" % type(obj))
示例13: _resolve_proxy
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def _resolve_proxy(obj):
if isinstance(obj, dict):
return {k: _resolve_proxy(v) for k, v in iteritems(obj)}
if isinstance(obj, (list, tuple)):
return [_resolve_proxy(v) for v in obj]
if isinstance(obj, lazy_object_proxy.Proxy):
return str(obj)
return obj
示例14: json_dumps
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def json_dumps(obj, pretty=False, compact=True, **kwargs):
"""
JSON dump to string.
:param obj:
:type obj: Any
:param pretty:
:type pretty: bool
:param compact:
:type compact: bool
:return:
:rtype: str
"""
if "default" not in kwargs:
kwargs["default"] = serialize_complex_object
if pretty:
kwargs["indent"] = 4
kwargs["sort_keys"] = True
kwargs["separators"] = (",", ": ")
elif compact:
kwargs["separators"] = (",", ":")
kwargs["sort_keys"] = True
try:
return json.dumps(obj, **kwargs)
except TypeError:
# lazy_object_proxy.Proxy subclasses basestring: serialize_complex_object isn't called on python2
if PY2:
obj = _resolve_proxy(obj)
return json.dumps(obj, **kwargs)
raise
示例15: test_proxy
# 需要导入模块: import lazy_object_proxy [as 别名]
# 或者: from lazy_object_proxy import Proxy [as 别名]
def test_proxy(self):
from lazy_object_proxy import Proxy
def unwrap():
return "foo"
data = {
"args": [Proxy(unwrap)]
}
expected = '{"args":["foo"]}'
actual = json_dumps(data)
self.assertEqual(expected, actual)