diff options
author | 2013-06-09 18:10:22 +0200 | |
---|---|---|
committer | 2013-06-09 18:10:23 +0200 | |
commit | 16af85004c84d0d6c626b4f8424ce9647669a0c1 (patch) | |
tree | 025d479862d376dbc17e934f4ed20031c8cd97d1 /module/remote/JSONClient.py | |
parent | adapted to jshint config (diff) | |
download | pyload-16af85004c84d0d6c626b4f8424ce9647669a0c1.tar.xz |
moved everything from module to pyload
Diffstat (limited to 'module/remote/JSONClient.py')
-rw-r--r-- | module/remote/JSONClient.py | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/module/remote/JSONClient.py b/module/remote/JSONClient.py deleted file mode 100644 index a2c07a132..000000000 --- a/module/remote/JSONClient.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from urllib import urlopen, urlencode -from httplib import UNAUTHORIZED, FORBIDDEN - -from json_converter import loads, dumps -from apitypes import Unauthorized, Forbidden - -class JSONClient: - URL = "http://localhost:8001/api" - - def __init__(self, url=None): - self.url = url or self.URL - self.session = None - - def request(self, path, data): - ret = urlopen(self.url + path, urlencode(data)) - if ret.code == 400: - raise loads(ret.read()) - if ret.code == 404: - raise AttributeError("Unknown Method") - if ret.code == 500: - raise Exception("Remote Exception") - if ret.code == UNAUTHORIZED: - raise Unauthorized() - if ret.code == FORBIDDEN: - raise Forbidden() - return ret.read() - - def login(self, username, password): - self.session = loads(self.request("/login", {'username': username, 'password': password})) - return self.session - - def logout(self): - self.call("logout") - self.session = None - - def call(self, func, *args, **kwargs): - # Add the current session - kwargs["session"] = self.session - path = "/" + func + "/" + "/".join(dumps(x) for x in args) - data = dict((k, dumps(v)) for k, v in kwargs.iteritems()) - rep = self.request(path, data) - return loads(rep) - - def __getattr__(self, item): - def call(*args, **kwargs): - return self.call(item, *args, **kwargs) - - return call - -if __name__ == "__main__": - api = JSONClient() - api.login("User", "test") - print api.getServerVersion()
\ No newline at end of file |