/usr/lib/python2.7/dist-packages/mygpoclient/json.py is in python-mygpoclient 1.8-1.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | # -*- coding: utf-8 -*-
# gpodder.net API Client
# Copyright (C) 2009-2013 Thomas Perl and the gPodder Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Fix gPodder bug 900 (so "import json" doesn't import this module)
from __future__ import absolute_import
import mygpoclient
try:
# Python 3
bytes = bytes
except:
# Python 2
bytes = str
import json
from mygpoclient import http
# Additional exceptions for JSON-related errors
class JsonException(Exception): pass
class JsonClient(http.HttpClient):
"""A HttpClient with built-in JSON support
This client will automatically marshal and unmarshal data for
JSON-related web services so that code using this class will
not need to care about (de-)serialization of data structures.
"""
def __init__(self, username=None, password=None):
http.HttpClient.__init__(self, username, password)
@staticmethod
def encode(data):
"""Encodes a object into its JSON string repesentation
>>> JsonClient.encode(None) is None
True
>>> JsonClient.encode([1,2,3]) == b'[1, 2, 3]'
True
>>> JsonClient.encode(42) == b'42'
True
"""
if data is None:
return None
else:
return json.dumps(data).encode('utf-8')
@staticmethod
def decode(data):
"""Decodes a response string to a Python object
>>> JsonClient.decode(b'')
>>> JsonClient.decode(b'[1,2,3]')
[1, 2, 3]
>>> JsonClient.decode(b'42')
42
"""
if data == b'':
return None
data = data.decode('utf-8')
try:
return json.loads(data)
except ValueError:
raise JsonException('Value error while parsing response: ' + data)
@staticmethod
def _prepare_request(method, uri, data):
data = JsonClient.encode(data)
return http.HttpClient._prepare_request(method, uri, data)
@staticmethod
def _process_response(response):
data = http.HttpClient._process_response(response)
return JsonClient.decode(data)
|