util
Functions:
-
context_from_urlinputsource–Please note that JSON-LD documents served with the
application/ld+jsonmedia type -
norm_url–```python
-
source_to_json–Extract JSON from a source document.
-
split_iri–
__all__
module-attribute
__all__ = ['json', 'source_to_json', 'split_iri', 'norm_url', 'context_from_urlinputsource', 'orjson', '_HAS_ORJSON']
HTMLJSONParser
Bases: HTMLParser
Methods:
-
get_base– -
get_json– -
handle_data– -
handle_starttag–
Attributes:
-
base– -
contains_json– -
extract_all_scripts– -
fragment_id– -
fragment_id_does_not_match– -
json(List[Dict]) – -
script_count–
Source code in rdflib/plugins/shared/jsonld/util.py
get_base
get_json
handle_data
Source code in rdflib/plugins/shared/jsonld/util.py
handle_starttag
Source code in rdflib/plugins/shared/jsonld/util.py
context_from_urlinputsource
context_from_urlinputsource(source: URLInputSource) -> Optional[str]
Please note that JSON-LD documents served with the application/ld+json media type
MUST have all context information, including references to external contexts,
within the body of the document. Contexts linked via a
http://www.w3.org/ns/json-ld#context HTTP Link Header MUST be
ignored for such documents.
Source code in rdflib/plugins/shared/jsonld/util.py
norm_url
>>> norm_url('http://example.org/', '/one')
'http://example.org/one'
>>> norm_url('http://example.org/', '/one#')
'http://example.org/one#'
>>> norm_url('http://example.org/one', 'two')
'http://example.org/two'
>>> norm_url('http://example.org/one/', 'two')
'http://example.org/one/two'
>>> norm_url('http://example.org/', 'http://example.net/one')
'http://example.net/one'
>>> norm_url('http://example.org/', 'http://example.org//one')
'http://example.org//one'
Source code in rdflib/plugins/shared/jsonld/util.py
source_to_json
source_to_json(source: Optional[Union[IO[bytes], TextIO, InputSource, str, bytes, PurePath]], fragment_id: Optional[str] = None, extract_all_scripts: Optional[bool] = False) -> Tuple[Union[Dict, List[Dict]], Any]
Extract JSON from a source document.
The source document can be JSON or HTML with embedded JSON script elements (type attribute = “application/ld+json”).
To process as HTML source.content_type must be set to “text/html” or “application/xhtml+xml”.
Parameters:
-
(sourceOptional[Union[IO[bytes], TextIO, InputSource, str, bytes, PurePath]]) –the input source document (JSON or HTML)
-
(fragment_idOptional[str], default:None) –if source is an HTML document then extract only the script element with matching id attribute, defaults to None
-
(extract_all_scriptsOptional[bool], default:False) –if source is an HTML document then extract all script elements (unless fragment_id is provided), defaults to False (extract only the first script element)
Returns:
-
Tuple[Union[Dict, List[Dict]], Any]–Tuple with the extracted JSON document and value of the HTML base element
Source code in rdflib/plugins/shared/jsonld/util.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |