예제 #1
0
파일: api.py 프로젝트: sraedler/pyload
def call_api(func, args=""):
    response.headers.replace("Content-type", "application/json")
    response.headers.append("Cache-Control", "no-cache, must-revalidate")

    s = request.environ.get('beaker.session')
    if 'session' in request.POST:
        s = s.get_by_id(request.POST['session'])

    if not s or not s.get("authenticated", False):
        return HTTPError(403, json.dumps("Forbidden"))

    if not PYLOAD.isAuthorized(func, {"role": s["role"], "permission": s["perms"]}):
        return HTTPError(401, json.dumps("Unauthorized"))

    args = args.split("/")[1:]
    kwargs = {}

    for x, y in chain(request.GET.iteritems(), request.POST.iteritems()):
        if x == "session": continue
        kwargs[x] = unquote(y)

    try:
        return callApi(func, *args, **kwargs)
    except Exception, e:
        print_exc()
        return HTTPError(500, json.dumps({"error": e.message, "traceback": format_exc()}))
예제 #2
0
파일: api.py 프로젝트: FedeG/pyload
def callApi(func, *args, **kwargs):
    if not hasattr(PYLOAD.EXTERNAL, func) or func.startswith("_"):
        print "Invalid API call", func
        return HTTPError(404, json.dumps("Not Found"))

    result = getattr(PYLOAD, func)(*[literal_eval(x) for x in args],
                                   **dict([(x, literal_eval(y)) for x, y in kwargs.iteritems()]))

    # null is invalid json  response
    return json.dumps(result or True, cls=TBaseEncoder)
예제 #3
0
파일: api.py 프로젝트: sraedler/pyload
def callApi(func, *args, **kwargs):
    if not hasattr(PYLOAD.EXTERNAL, func) or func.startswith("_"):
        print "Invalid API call", func
        return HTTPError(404, json.dumps("Not Found"))

    result = getattr(PYLOAD, func)(*[literal_eval(x) for x in args],
                                   **dict([(x, literal_eval(y)) for x, y in kwargs.iteritems()]))

    # null is invalid json  response
    if result is None: result = True

    return json.dumps(result, cls=TBaseEncoder)
예제 #4
0
파일: MegaNz.py 프로젝트: sebmaynard/pyload
    def callApi(self, **kwargs):
        """ Dispatch a call to the api, see https://mega.co.nz/#developers """
        # generate a session id, no idea where to obtain elsewhere
        uid = random.randint(10 << 9, 10**10)

        resp = self.load(self.API_URL % uid, post=json.dumps([kwargs]))
        self.logDebug("Api Response: " + resp)
        return json.loads(resp)
예제 #5
0
    def callApi(self, **kwargs):
        """ Dispatch a call to the api, see https://mega.co.nz/#developers """
        # generate a session id, no idea where to obtain elsewhere
        uid = random.randint(10 << 9, 10 ** 10)

        resp = self.load(self.API_URL % uid, post=json.dumps([kwargs]))
        self.logDebug("Api Response: " + resp)
        return json.loads(resp)
예제 #6
0
    def saveAccounts(self):
        """save all account information"""

        data = []
        for name, plugin in self.accounts.iteritems():
            data.extend([(name, acc.loginname, acc.activated, acc.password, json.dumps(acc.options)) for acc in
                                                                                                     plugin.itervalues()])
        self.core.db.saveAccounts(data)
예제 #7
0
def dumps(*args, **kwargs):
    if 'compact' in kwargs:
        kwargs['cls'] = BaseEncoderCompact
        del kwargs['compact']
    else:
        kwargs['cls'] = BaseEncoder

    kwargs['separators'] = separators
    return json.dumps(*args, **kwargs)
예제 #8
0
    def saveAccounts(self):
        """save all account information"""

        data = []
        for name, plugin in self.accounts.iteritems():
            data.extend([(name, acc.loginname, acc.activated, acc.password,
                          json.dumps(acc.options))
                         for acc in plugin.itervalues()])
        self.core.db.saveAccounts(data)
예제 #9
0
파일: api.py 프로젝트: sraedler/pyload
def login():
    response.headers.replace("Content-type", "application/json")
    response.headers.append("Cache-Control", "no-cache, must-revalidate")

    user = request.forms.get("username")
    password = request.forms.get("password")

    info = PYLOAD.checkAuth(user, password)

    if not info:
        return json.dumps(False)

    s = set_session(request, info)

    # get the session id by dirty way, documentations seems wrong
    try:
        sid = s._headers["cookie_out"].split("=")[1].split(";")[0]
        return json.dumps(sid)
    except:
        return json.dumps(True)
예제 #10
0
 def saveValues(self, user, section):
     self.db.saveConfig(section, json.dumps(self.values[user, section]), user)
예제 #11
0
 def callApi(self, **kwargs):
     """ Dispatch a call to the api, see megacrypter.com/api_doc """
     self.logDebug("JSON request: " + json.dumps(kwargs))
     resp = self.load(self.API_URL, post=json.dumps(kwargs))
     self.logDebug("API Response: " + resp)
     return json.loads(resp)
예제 #12
0
 def saveValues(self, user, section):
     self.db.saveConfig(section, json.dumps(self.values[user, section]), user)
예제 #13
0
def dumps(*args, **kwargs):
    kwargs['cls'] = BaseEncoder
    return json.dumps(*args, **kwargs)
예제 #14
0
def dumps(*args, **kwargs):
    kwargs['cls'] = BaseEncoder
    kwargs['separators'] = separators
    return json.dumps(*args, **kwargs)
예제 #15
0
def dumps(*args, **kwargs):
    kwargs['cls'] = BaseEncoder
    return json.dumps(*args, **kwargs)