Skip to content

Commit 4f3262d

Browse files
committed
No more warnings.
1 parent 1e6ff63 commit 4f3262d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

docs/jsonschema_role.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
from docutils import nodes
33
import errno
44
import os
5-
import urllib2
5+
6+
try:
7+
import urllib2 as urllib
8+
except ImportError:
9+
import urllib.request as urllib
610

711
from lxml import html
812

@@ -49,11 +53,11 @@ def fetch_or_load(spec_path):
4953
if error.errno != errno.ENOENT:
5054
raise
5155

52-
request = urllib2.Request(VALIDATION_SPEC, headers=headers)
53-
response = urllib2.urlopen(request)
56+
request = urllib.Request(VALIDATION_SPEC, headers=headers)
57+
response = urllib.urlopen(request)
5458

5559
if response.code == 200:
56-
with open(spec_path, "w+") as spec:
60+
with open(spec_path, "w+b") as spec:
5761
spec.writelines(response)
5862
spec.seek(0)
5963
return html.parse(spec)
@@ -72,6 +76,8 @@ def docutils_sucks(spec):
7276
"""
7377

7478
base_url = VALIDATION_SPEC
79+
ref_url = "http://json-schema.org/latest/json-schema-core.html#anchor25"
80+
schema_url = "http://json-schema.org/latest/json-schema-core.html#anchor22"
7581

7682
def validator(name, raw_text, text, lineno, inliner):
7783
"""
@@ -88,8 +94,14 @@ def validator(name, raw_text, text, lineno, inliner):
8894
8995
"""
9096

97+
if text == "$ref":
98+
return [nodes.reference(raw_text, text, refuri=ref_url)], []
99+
elif text == "$schema":
100+
return [nodes.reference(raw_text, text, refuri=schema_url)], []
101+
102+
xpath = "//h3[re:match(text(), '(^|\W)\"?{0}\"?($|\W,)', 'i')]"
91103
header = spec.xpath(
92-
"//h3[re:match(text(), '(^|\W){0}($|\W,)', 'i')]".format(text),
104+
xpath.format(text),
93105
namespaces={"re": "http://exslt.org/regular-expressions"},
94106
)
95107

@@ -100,7 +112,7 @@ def validator(name, raw_text, text, lineno, inliner):
100112
uri = base_url
101113
else:
102114
if len(header) > 1:
103-
inliner.reporter.warning(
115+
inliner.reporter.info(
104116
"Found multiple targets for {0}".format(text),
105117
)
106118
uri = base_url + "#" + header[0].getprevious().attrib["name"]

0 commit comments

Comments
 (0)