Skip to content

Commit

Permalink
pull-license-list: Update to Python 3.6
Browse files Browse the repository at this point in the history
Which adds support for parsing JSON directly from bytes without first
decoding to a string [1,2].  This allows interacting with
RFC-compliant servers, because RFC 7159 does not define a charset
parameter in its application/json registration [3].

Reported by Eric Searcy [4].

[1]: https://docs.python.org/3/whatsnew/3.6.html#json
[2]: https://bugs.python.org/issue17909
[3]: https://tools.ietf.org/html/rfc7159#page-11
[4]: spdx#10 (comment)
  • Loading branch information
wking authored and SantiagoTorres committed Jan 10, 2020
1 parent 60a1d8a commit 039bd8d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bin/pull-license-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
import json
import os.path
import re
import sys
import urllib.request


if sys.version_info < (3, 6):
raise RuntimeError('this script requires Python 3.6+')


VERSION_REGEXP = re.compile(
pattern='(.* SPDX License List, v)([^ ]*)( which was released )([^.]*)(\..*)',
flags=re.DOTALL)


def get_json(url):
with urllib.request.urlopen(url=url) as response:
charset = response.headers.get_content_charset('UTF-8')
reader = codecs.getreader(charset)
return json.load(reader(response))
return json.load(body)


def format_table(headers, rows):
Expand Down

0 comments on commit 039bd8d

Please sign in to comment.