本文整理匯總了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)