/usr/lib/python3/dist-packages/kanboard/client.py is in python3-kanboard 1.0.1-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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | import json
import base64
from kanboard import exceptions
try:
    from urllib import request as http
except ImportError:
    import urllib2 as http
class Kanboard(object):
    """
    Kanboard API client
    Example:
        from kanboard import Kanboard
        kb = Kanboard(url="http://localhost/jsonrpc.php",
                      username="jsonrpc",
                      password="your_api_token")
        project_id = kb.create_project(name="My project")
    """
    def __init__(self, url, username, password, auth_header='Authorization'):
        """
        Constructor
        Args:
            url: API url endpoint
            username: API username or real username
            password: API token or user password
            auth_header: API HTTP header
        """
        self._url = url
        self._username = username
        self._password = password
        self._auth_header = auth_header
    def __getattr__(self, name):
        def function(*args, **kwargs):
            return self.execute(method=self._to_camel_case(name), **kwargs)
        return function
    @staticmethod
    def _to_camel_case(snake_str):
        components = snake_str.split('_')
        return components[0] + ''.join(x.title() for x in components[1:])
    @staticmethod
    def _parse_response(response):
        try:
            body = json.loads(response.decode())
            if 'error' in body:
                message = body.get('error').get('message')
                raise exceptions.KanboardClientException(message)
            return body.get('result')
        except ValueError:
            return None
    def _do_request(self, headers, body):
        try:
            request = http.Request(self._url,
                                   headers=headers,
                                   data=json.dumps(body).encode())
            response = http.urlopen(request).read()
        except Exception as e:
            raise exceptions.KanboardClientException(str(e))
        return self._parse_response(response)
    def execute(self, method, **kwargs):
        """
        Call remote API procedure
        Args:
            method: Procedure name
            kwargs: Procedure named arguments
        Returns:
            Procedure result
        Raises:
            urllib2.HTTPError: Any HTTP error (Python 2)
            urllib.error.HTTPError: Any HTTP error (Python 3)
        """
        payload = {
            'id': 1,
            'jsonrpc': '2.0',
            'method': method,
            'params': kwargs
        }
        credentials = base64.b64encode('{}:{}'.format(self._username, self._password).encode())
        headers = {
            self._auth_header: 'Basic {}'.format(credentials.decode()),
            'Content-Type': 'application/json',
        }
        return self._do_request(headers, payload)
 |