/usr/lib/python3/dist-packages/pafy/util.py is in python3-pafy 0.5.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 31 32 33 34 35 36 37 | import json
import sys
if sys.version_info[:2] >= (3, 0):
# pylint: disable=E0611,F0401,I0011
from urllib.error import HTTPError
from urllib.parse import urlencode
else:
from urllib2 import HTTPError
from urllib import urlencode
from . import g
class GdataError(Exception):
"""Gdata query failed."""
pass
def call_gdata(api, qs):
"""Make a request to the youtube gdata api."""
qs = dict(qs)
qs['key'] = g.api_key
url = g.urls['gdata'] + api + '?' + urlencode(qs)
try:
data = g.opener.open(url).read().decode('utf-8')
except HTTPError as e:
try:
errdata = e.file.read().decode()
error = json.loads(errdata)['error']['message']
errmsg = 'Youtube Error %d: %s' % (e.getcode(), error)
except:
errmsg = str(e)
raise GdataError(errmsg)
return json.loads(data)
|