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)
def loadValues(self, user, section): if (user, section) not in self.values: conf = self.db.loadConfig(section, user) try: self.values[user, section] = json.loads(conf) if conf else {} except ValueError: # Something did go wrong when parsing self.values[user, section] = {} self.core.print_exc()
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)
def decryptAttr(self, data, key): cbc = AES.new(self.getCipherKey(key), AES.MODE_CBC, "\0" * 16) attr = cbc.decrypt(self.b64_decode(data)) self.logDebug("Decrypted Attr: " + attr) if not attr.startswith("MEGA"): self.fail(_("Decryption failed")) # Data is padded, 0-bytes must be stripped return json.loads(attr.replace("MEGA", "").rstrip("\0").strip())
def loadValues(self, user, section): if (user, section) not in self.values: conf = self.db.loadConfig(section, user) try: self.values[user, section] = json.loads(conf) if conf else {} except ValueError: # Something did go wrong when parsing self.values[user, section] = {} self.core.print_exc() return self.values[user, section]
def decryptAttr(self, data, key): cbc = AES.new(self.getCipherKey(key), AES.MODE_CBC, "\0" * 16) attr = cbc.decrypt(self.b64_decode(data)) self.logDebug("Decrypted Attr: " + attr) if not attr.startswith("MEGA"): self.fail(_("Decryption failed")) # Data is padded, 0-bytes must be stripped return json.loads(attr.replace("MEGA", "").rstrip("\0").strip())
def loadAccounts(self): """loads all accounts available""" self.accounts = {} for plugin, loginname, activated, password, options in self.core.db.loadAccounts(): # put into options as used in other context options = json.loads(options) if options else {} options["activated"] = activated self.createAccount(plugin, loginname, password, options)
def loadAccounts(self): """loads all accounts available""" self.accounts = {} for plugin, loginname, activated, password, options in self.core.db.loadAccounts( ): # put into options as used in other context options = json.loads(options) if options else {} options["activated"] = activated self.createAccount(plugin, loginname, password, options)
def iterSections(self, user=None): """ Yields: section, metadata, values """ values = self.db.loadConfigsForUser(user) # Every section needs to be json decoded for section, data in values.items(): try: values[section] = json.loads(data) if data else {} except ValueError: values[section] = {} self.core.print_exc() for name, config in self.config.iteritems(): yield name, config, values[name] if name in values else {}
def loads(*args, **kwargs): kwargs['object_hook'] = convert_obj return json.loads(*args, **kwargs)
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)