Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/npm/client.py
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | def _prepare_package_version(self, package_source_data, version_data): | ||||
package_source_data.update(hashes) | package_source_data.update(hashes) | ||||
# parse package.json file to add its content to revision metadata | # parse package.json file to add its content to revision metadata | ||||
package_json_path = os.path.join(package_path, 'package.json') | package_json_path = os.path.join(package_path, 'package.json') | ||||
package_json = {} | package_json = {} | ||||
with open(package_json_path, 'rb') as package_json_file: | with open(package_json_path, 'rb') as package_json_file: | ||||
package_json_bytes = package_json_file.read() | package_json_bytes = package_json_file.read() | ||||
file_encoding = chardet.detect(package_json_bytes)['encoding'] | file_encoding = chardet.detect(package_json_bytes)['encoding'] | ||||
package_json = json.loads(package_json_bytes.decode(file_encoding)) | package_json = json.loads(package_json_bytes.decode(file_encoding, | ||||
'replace')) | |||||
# extract author from package.json | # extract author from package.json | ||||
author = extract_npm_package_author(package_json) | author = extract_npm_package_author(package_json) | ||||
return (package_json, author, package_source_data, package_path) | return (package_json, author, package_source_data, package_path) | ||||
def _request(self, url, throw_error=True): | def _request(self, url, throw_error=True): | ||||
response = self.session.get(url, **self.params, stream=True) | response = self.session.get(url, **self.params, stream=True) | ||||
if response.status_code != 200 and throw_error: | if response.status_code != 200 and throw_error: | ||||
raise ValueError("Fail to query '%s'. Reason: %s" % ( | raise ValueError("Fail to query '%s'. Reason: %s" % ( | ||||
url, response.status_code)) | url, response.status_code)) | ||||
return response | return response |