/usr/share/pyshared/mygpoclient/json.py is in python-mygpoclient 1.7-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 | # -*- 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:
# Prefer the usage of the simplejson module, as it
# is most likely newer if it's installed as module
# than the built-in json module (and is mandatory
# in Python versions before 2.6, anyway).
import simplejson as json
except ImportError:
# Python 2.6 ships the "json" module by default
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)
''
>>> JsonClient.encode([1,2,3])
'[1, 2, 3]'
>>> JsonClient.encode(42)
'42'
"""
if data is None:
return ''
else:
return json.dumps(data)
@staticmethod
def decode(data):
"""Decodes a response string to a Python object
>>> JsonClient.decode('')
>>> JsonClient.decode('[1,2,3]')
[1, 2, 3]
>>> JsonClient.decode('42')
42
"""
if data == '':
return None
else:
try:
return json.loads(data)
except ValueError, ve:
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)
|