'Resolve a ``fragment`` within the referenced ``document``.
:argument document: the referrant document
:argument str fragment: a URI fragment to resolve within it'

def resolve_fragment(self, document, fragment):

    fragment = fragment.lstrip(u'/')
    parts = (unquote(fragment).split(u'/') if fragment else [])
    for part in parts:
        part = part.replace(u'~1', u'/').replace(u'~0', u'~')
        if isinstance(document, Sequence):
            try:
                part = int(part)
            except ValueError:
                pass
        try:
            document = document[part]
        except (TypeError, LookupError):
            raise RefResolutionError(('Unresolvable    JSON    pointer:    %r' % fragment))
    return document
