本文整理汇总了Python中jsonpointer.resolve_pointer方法的典型用法代码示例。如果您正苦于以下问题:Python jsonpointer.resolve_pointer方法的具体用法?Python jsonpointer.resolve_pointer怎么用?Python jsonpointer.resolve_pointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonpointer
的用法示例。
在下文中一共展示了jsonpointer.resolve_pointer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_deferred_references
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def validate_deferred_references(schema, context, **kwargs):
try:
deferred_references = context['deferred_references']
except KeyError:
raise KeyError("`deferred_references` not found in context")
with ErrorDict() as errors:
for reference in deferred_references:
parts = urlparse.urlparse(reference)
if any((parts.scheme, parts.netloc, parts.path, parts.params, parts.query)):
errors.add_error(
reference,
MESSAGES['reference']['unsupported'].format(reference),
)
continue
try:
jsonpointer.resolve_pointer(schema, parts.fragment)
except jsonpointer.JsonPointerException:
errors.add_error(
reference,
MESSAGES['reference']['undefined'].format(reference),
)
示例2: __init__
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def __init__(self, directive, arguments, options, content, lineno, content_offset, block_text, state, state_machine):
assert directive == 'jsonschema'
#breakpoint()
self.options = options
self.state = state
self.lineno = lineno
self.statemachine = state_machine
if len(arguments) == 1:
filename, pointer = self._splitpointer(arguments[0])
if filename != '':
self._load_external(filename)
else:
self._load_internal(content)
if pointer:
self.schema = resolve_pointer(self.schema, pointer)
else:
self._load_internal(content)
示例3: get_identifiers
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get_identifiers(self):
if self.xml:
doc = lxml.etree.fromstring(self.xml)
for number_type, xpath in self.XML_IDENTIFIER_XPATH_MAP.items():
node = doc.xpath(xpath, namespaces=self.XML_NAMESPACES)
if node:
identifier = self.sanitize_value(node[0].text)
if identifier:
self.identifiers.setdefault(number_type, identifier)
if self.json:
data = json.loads(self.json)
for number_type, jpointer in self.JSON_IDENTIFIER_JSONPOINTER_MAP.items():
try:
identifier = self.sanitize_value(jsonpointer.resolve_pointer(data, jpointer))
if identifier:
self.identifiers.setdefault(number_type, identifier)
except jsonpointer.JsonPointerException:
pass
return self.identifiers
示例4: getConfigValue
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def getConfigValue(self, conf_key):
self._ensureConfig()
# jsonpointer, pip install jsonpointer, BSD 3 Clause
import jsonpointer
try:
return jsonpointer.resolve_pointer(self.config, conf_key)
except jsonpointer.JsonPointerException as e:
# fall back to legacy dot-separated pointers
key_path = conf_key.split('.');
c = self.config
for part in key_path:
if part in c:
c = c[part]
else:
return None
return c
示例5: __init__
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def __init__(self, reference, context):
if self.validators_constructor is None:
raise NotImplementedError(
"Subclasses of LazyReferenceValidator must specify a "
"`validators_constructor` function"
)
self.reference_fragment = urlparse.urlparse(reference).fragment
# TODO: something better than this which potentiall raises a
# JsonPointerException
jsonpointer.resolve_pointer(context, self.reference_fragment)
self.reference = reference
self.context = context
示例6: schema
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def schema(self):
return jsonpointer.resolve_pointer(self.context, self.reference_fragment)
示例7: dereference_reference
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def dereference_reference(reference, context):
parts = urlparse.urlparse(reference)
if any((parts.scheme, parts.netloc, parts.path, parts.params, parts.query)):
raise ValueError(
MESSAGES['reference']['unsupported'].format(reference),
)
return jsonpointer.resolve_pointer(context, parts.fragment)
示例8: validate_reference_pointer
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def validate_reference_pointer(reference, context, **kwargs):
parts = urlparse.urlparse(reference)
if any((parts.scheme, parts.netloc, parts.path, parts.params, parts.query)):
raise ValidationError(
MESSAGES['reference']['unsupported'].format(reference),
)
try:
jsonpointer.resolve_pointer(context, parts.fragment)
except jsonpointer.JsonPointerException:
raise ValidationError(
MESSAGES['reference']['undefined'].format(reference),
)
示例9: find
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def find(self, path, default=None):
"""
Retrieves a single value using JSON-Pointer syntax
"""
result = resolve_pointer(self.__d, path, default)
if isinstance(result, dict):
result = TDict(result)
return result
示例10: _without
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def _without(obj, attrs, path=None):
"""Returns patched object with attributes deleted."""
if path:
ptrval = copy.deepcopy(jsonpointer.resolve_pointer(obj, path))
return _patch(obj, path, _without(ptrval, attrs))
else:
updated = copy.deepcopy(obj)
for attr in attrs:
if attr in updated:
del updated[attr]
return updated
示例11: get
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get(self, selector=None):
"""Main function for get command
:param selector: the type selection for the get operation.
:type selector: str.
:returns: returns a list from get operation
"""
results = list()
instances = self.get_selection()
if not instances or len(instances) == 0:
raise NothingSelectedError()
for instance in instances:
currdict = instance.resp.dict
# apply patches to represent current edits
for patch in instance.patches:
currdict = jsonpatch.apply_patch(currdict, patch)
if selector:
jsonpath_expr = jsonpath_rw.parse(u'%s' % selector)
matches = jsonpath_expr.find(currdict)
temp_dict = OrderedDict()
for match in matches:
json_pstr = u'/%s' % match.full_path
json_node = jsonpointer.resolve_pointer(currdict, json_pstr)
temp_dict[str(match.full_path)] = json_node
results.append(temp_dict)
else:
results.append(currdict)
return results
示例12: get_version_diff
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get_version_diff(from_data, to_data):
"""Calculate the diff (a mangled JSON patch) between from_data and to_data"""
basic_patch = jsonpatch.make_patch(from_data, to_data)
result = []
for operation in sorted(basic_patch, key=lambda o: (o['op'], o['path'])):
op = operation['op']
ignore = False
# We deal with standing_in and party_memberships slightly
# differently so they can be presented in human-readable form,
# so match those cases first:
m = re.search(
r'(standing_in|party_memberships)(?:/([^/]+))?(?:/(\w+))?',
operation['path'],
)
if op in ('replace', 'remove'):
operation['previous_value'] = \
jsonpointer.resolve_pointer(
from_data,
operation['path'],
default=None
)
attribute, election, leaf = m.groups() if m else (None, None, None)
if attribute:
explain_standing_in_and_party_memberships(operation, attribute, election, leaf)
if op in ('replace', 'remove'):
if op == 'replace' and not operation['previous_value']:
if operation['value']:
operation['op'] = 'add'
else:
# Ignore replacing no data with no data:
ignore = True
elif op == 'add':
# It's important that we don't skip the case where a
# standing_in value is being set to None, because that's
# saying 'we *know* they're not standing then'
if (not operation['value']) and (attribute != 'standing_in'):
ignore = True
operation['path'] = re.sub(r'^/', '', operation['path'])
if not ignore:
result.append(operation)
# The operations generated by jsonpatch are incremental, so we
# need to apply each before going on to parse the next:
operation['path'] = '/' + operation['path']
from_data = jsonpatch.apply_patch(from_data, [operation])
for operation in result:
operation['path'] = operation['path'].lstrip('/')
return result
示例13: get_save
# 需要导入模块: import jsonpointer [as 别名]
# 或者: from jsonpointer import resolve_pointer [as 别名]
def get_save(self, selector=None, currentoverride=False, pluspath=False, \
onlypath=None):
"""Special main function for get in save command
:param selector: the type selection for the get operation.
:type selector: str.
:param currentoverride: flag to override current selection.
:type currentoverride: boolean.
:param pluspath: flag to add path to the results.
:type pluspath: boolean.
:param onlypath: flag to enable only that path selection.
:type onlypath: boolean.
:returns: returns a list from the get command
"""
results = list()
instances = self.get_selection()
if not instances or len(instances) == 0:
raise NothingSelectedError()
for instance in instances:
if self.get_save_helper(instance.resp.request.path, instances)\
and not currentoverride:
continue
elif onlypath:
if not onlypath == instance.resp.request.path:
continue
currdict = instance.resp.dict
# apply patches to represent current edits
for patch in instance.patches:
currdict = jsonpatch.apply_patch(currdict, patch)
if selector:
for item in currdict.iterkeys():
if selector.lower() == item.lower():
selector = item
break
try:
jsonpath_expr = jsonpath_rw.parse(u'"%s"' % selector)
except Exception, excp:
raise InvalidCommandLineError(excp)
matches = jsonpath_expr.find(currdict)
temp_dict = OrderedDict()
for match in matches:
json_pstr = u'/%s' % match.full_path
json_node = jsonpointer.resolve_pointer(currdict, json_pstr)
temp_dict[str(match.full_path)] = json_node
results.append(temp_dict)
else:
if pluspath:
results.append({instance.resp.request.path: currdict})
else:
results.append(currdict)