-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathjsonld.py
More file actions
30 lines (28 loc) · 936 Bytes
/
jsonld.py
File metadata and controls
30 lines (28 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from .test import BaseTest
import ssl
try:
# python3
from urllib.request import Request, urlopen, HTTPError
except ImportError:
# fall back to python2
from urllib2 import Request, urlopen, HTTPError
class Test_Jsonld(BaseTest):
label = 'JSON-LD Media Type'
level = 1
category = 7
versions = [u'2.0']
validationInfo = None
def run(self, result):
url = result.make_info_url()
hdrs = {'Accept': 'application/ld+json'}
try:
r = Request(url, headers=hdrs)
context = ssl._create_unverified_context()
wh = urlopen(r, context=context)
img = wh.read()
wh.close()
except HTTPError as e:
wh = e
ct = wh.headers['content-type']
self.validationInfo.check('json-ld', ct.startswith('application/ld+json'), 1, result, "Content-Type to start with application/ld+json")
return result