-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrequest.py
More file actions
22 lines (19 loc) · 750 Bytes
/
request.py
File metadata and controls
22 lines (19 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import json
from string import Template
from urllib import request
from urllib.parse import urljoin
from . import settings as conf
from . import defaults
def get_request(pathname):
webURL = request.urlopen(pathname)
data = webURL.read()
encoding = webURL.info().get_content_charset('utf-8')
return json.loads(data.decode(encoding))
def fetch_package_version(package, version, callback = None):
registry = conf.settings.get('registry', defaults.get_registry())
pathname = urljoin(registry, package.replace('/', '%2F'))
pathname = Template('$pathname?version=$version').substitute(pathname=pathname, version=version)
response = get_request(pathname)
if (callback):
callback(response['version'])