本文整理匯總了Python中types.MappingProxyType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.MappingProxyType方法的具體用法?Python types.MappingProxyType怎麽用?Python types.MappingProxyType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類types
的用法示例。
在下文中一共展示了types.MappingProxyType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: validate_query
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def validate_query(query, possible_columns):
q = validate_query_structure(query)
sort_field = q.get('_sortField')
filters = q.get('_filters', [])
columns = [field_name for field_name in filters]
if sort_field is not None:
columns.append(sort_field)
not_valid = set(columns).difference(
possible_columns + [MULTI_FIELD_TEXT_QUERY])
if not_valid:
column_list = ', '.join(not_valid)
msg = 'Columns: {} do not present in resource'.format(column_list)
raise JsonValidaitonError(msg)
return MappingProxyType(q)
示例2: _make_context_immutable
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def _make_context_immutable(context):
"""Best effort attempt at turning a properly formatted context
(either a string, dict, or array of strings and dicts) into an
immutable data structure.
If we get an array, make it immutable by creating a tuple; if we get
a dict, copy it into a MappingProxyType. Otherwise, return as-is.
"""
def make_immutable(val):
if isinstance(val, Mapping):
return MappingProxyType(val)
else:
return val
if not isinstance(context, (str, Mapping)):
try:
return tuple([make_immutable(val) for val in context])
except TypeError:
pass
return make_immutable(context)
示例3: __init_subclass__
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def __init_subclass__(cls):
if not hasattr(cls, 'states'):
return
re_states = {}
for state, rules in cls.states.items():
res = []
for rule in rules:
if cls.asbytes:
res.append(b'(?P<%b>%b)' % (rule.id.encode(), rule.regexp))
else:
res.append('(?P<{}>{})'.format(rule.id, rule.regexp))
if cls.asbytes:
res.append(b'(?P<err>.)')
else:
res.append('(?P<err>.)')
if cls.asbytes:
full_re = b' | '.join(res)
else:
full_re = ' | '.join(res)
re_states[state] = re.compile(full_re, cls.RE_FLAGS)
cls.re_states = types.MappingProxyType(re_states)
示例4: lint
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def lint(gdscript_code: str, config: MappingProxyType) -> List[Problem]:
disable = config["disable"]
checks_to_run_w_code = [
(
"max-line-length",
partial(_max_line_length_check, config["max-line-length"]),
),
("max-file-lines", partial(_max_file_lines_check, config["max-file-lines"]),),
("trailing-whitespace", _trailing_ws_check,),
("mixed-tabs-and-spaces", _mixed_tabs_and_spaces_check,),
] # type: List[Tuple[str, Callable]]
problem_clusters = map(
lambda x: x[1](gdscript_code) if x[0] not in disable else [],
checks_to_run_w_code,
)
problems = [problem for cluster in problem_clusters for problem in cluster]
return problems
示例5: write_sparse_as_dense
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def write_sparse_as_dense(f, key, value, dataset_kwargs=MappingProxyType({})):
real_key = None # Flag for if temporary key was used
if key in f:
if (
isinstance(value, (h5py.Group, h5py.Dataset, SparseDataset))
and value.file.filename == f.filename
): # Write to temporary key before overwriting
real_key = key
# Transform key to temporary, e.g. raw/X -> raw/_X, or X -> _X
key = re.sub(r"(.*)(\w(?!.*/))", r"\1_\2", key.rstrip("/"))
else:
del f[key] # Wipe before write
dset = f.create_dataset(key, shape=value.shape, dtype=value.dtype, **dataset_kwargs)
compressed_axis = int(isinstance(value, sparse.csc_matrix))
for idx in idx_chunks_along_axis(value.shape, compressed_axis, 1000):
dset[idx] = value[idx].toarray()
if real_key is not None:
del f[real_key]
f[real_key] = f[key]
del f[key]
示例6: save_mappingproxy
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def save_mappingproxy(self, obj):
self.save_reduce(types.MappingProxyType, (dict(obj),), obj=obj)
示例7: __init__
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def __init__(self, parameters=None, *, return_annotation=_empty,
__validate_parameters__=True):
'''Constructs Signature from the given list of Parameter
objects and 'return_annotation'. All arguments are optional.
'''
if parameters is None:
params = OrderedDict()
else:
if __validate_parameters__:
params = OrderedDict()
top_kind = _POSITIONAL_ONLY
for idx, param in enumerate(parameters):
kind = param.kind
if kind < top_kind:
msg = 'wrong parameter order: {} before {}'
msg = msg.format(top_kind, param.kind)
raise ValueError(msg)
else:
top_kind = kind
name = param.name
if name is None:
name = str(idx)
param = param.replace(name=name)
if name in params:
msg = 'duplicate parameter name: {!r}'.format(name)
raise ValueError(msg)
params[name] = param
else:
params = OrderedDict(((param.name, param)
for param in parameters))
self._parameters = types.MappingProxyType(params)
self._return_annotation = return_annotation
示例8: parameters
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def parameters(self):
try:
return types.MappingProxyType(self._parameters)
except AttributeError:
return OrderedDict(self._parameters.items())
示例9: _match_key_mapping
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def _match_key_mapping(
self, sequence: keyutils.KeySequence) -> MatchResult:
"""Try to match a key in bindings.key_mappings."""
self._debug_log("Trying match with key_mappings")
mapped = sequence.with_mappings(
types.MappingProxyType(config.cache['bindings.key_mappings']))
if sequence != mapped:
self._debug_log("Mapped {} -> {}".format(
sequence, mapped))
return self._match_key(mapped)
return MatchResult(match_type=QKeySequence.NoMatch,
command=None,
sequence=sequence)
示例10: pubsub_channels
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def pubsub_channels(self):
"""Returns read-only channels dict."""
return types.MappingProxyType(self._pubsub_channels)
示例11: pubsub_patterns
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def pubsub_patterns(self):
"""Returns read-only patterns dict."""
return types.MappingProxyType(self._pubsub_patterns)
示例12: channels
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def channels(self):
"""Read-only channels dict."""
return types.MappingProxyType({
ch.name: ch for ch in self._refs.values()
if not ch.is_pattern})
示例13: patterns
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def patterns(self):
"""Read-only patterns dict."""
return types.MappingProxyType({
ch.name: ch for ch in self._refs.values()
if ch.is_pattern})
示例14: pubsub_channels
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def pubsub_channels(self):
if self._pubsub_conn and not self._pubsub_conn.closed:
return self._pubsub_conn.pubsub_channels
return types.MappingProxyType({})
示例15: __init_subclass__
# 需要導入模塊: import types [as 別名]
# 或者: from types import MappingProxyType [as 別名]
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
if not hasattr(cls, "__schema_name__"):
raise TypeError("Entity type does not have a schema name")
schema_name = getattr(cls, "__schema_name__")
cls.subclasses[schema_name] = cls
# Handle base case (Entity)
if not schema_name:
return
# Set properties on metaclass by fetching from schema
(schema_props, validators, defaults, display_map) = get_schema_details(
schema_name
)
# Set validator dict on metaclass for each prop.
# To be used during __setattr__() to validate props.
# Look at validate() for details.
setattr(cls, "__validator_dict__", MappingProxyType(validators))
# Set defaults which will be used during serialization.
# Look at json_dumps() for details
setattr(cls, "__default_attrs__", MappingProxyType(defaults))
# Attach schema properties to metaclass
setattr(cls, "__schema_props__", MappingProxyType(schema_props))
# Attach display map for compile/decompile
setattr(cls, "__display_map__", MappingProxyType(display_map))