def add_package(): name = request.forms.get("add_name", "New Package").strip() queue = int(request.forms['add_dest']) links = decode(request.forms['add_links']) links = links.split("\n") pw = request.forms.get("add_password", "").strip("\n\r") try: f = request.files['add_file'] if not name or name == "New Package": name = f.name fpath = join(PYLOAD.getConfigValue("general", "download_folder"), "tmp_" + f.filename) destination = open(fpath, 'wb') copyfileobj(f.file, destination) destination.close() links.insert(0, fpath) except: pass name = name.decode("utf8", "ignore") links = map(lambda x: x.strip(), links) links = filter(lambda x: x != "", links) pack = PYLOAD.addPackage(name, links, queue) if pw: pw = pw.decode("utf8", "ignore") data = {"password": pw} PYLOAD.setPackageData(pack, data)
def save_config(category): for key, value in request.POST.iteritems(): try: section, option = key.split("|") except: continue if category == "general": category = "core" PYLOAD.setConfigValue(section, option, decode(value), category)
def _pluginSet(self, plugins): regexp = re.compile(r'^[\w\-.^_]{3,63}\.[a-zA-Z]{2,}$', re.U) plugins = [decode(p.strip()).lower() for p in plugins if regexp.match(p.strip())] for r in self.DOMAIN_REPLACEMENTS: rf, rt = r repr = re.compile(rf, re.I|re.U) plugins = [re.sub(rf, rt, p) if repr.match(p) else p for p in plugins] return set(plugins)
def decryptAttr(self, data, key): k, iv, meta_mac = self.getCipherKey(key) cbc = AES.new(k, AES.MODE_CBC, "\0" * 16) attr = decode(cbc.decrypt(self.b64_decode(data))) self.logDebug("Decrypted Attr: %s" % attr) if not attr.startswith("MEGA"): self.fail(_("Decryption failed")) # Data is padded, 0-bytes must be stripped return json_loads(re.search(r'{.+?}', attr).group(0))
def decrypt_attr(self, data, key): k, iv, meta_mac = self.get_cipher_key(key) cbc = AES.new(k, AES.MODE_CBC, "\0" * 16) attr = decode(cbc.decrypt(self.b64_decode(data))) self.log_debug("Decrypted Attr: %s" % attr) if not attr.startswith("MEGA"): self.fail(_("Decryption failed")) #: Data is padded, 0-bytes must be stripped return json_loads(re.search(r'{.+?}', attr).group(0))
def _pluginSet(self, plugins): regexp = re.compile(r'^[\w\-.^_]{3,63}\.[a-zA-Z]{2,}$', re.U) plugins = [ decode(p.strip()).lower() for p in plugins if regexp.match(p.strip()) ] for r in self.DOMAIN_REPLACEMENTS: rf, rt = r repr = re.compile(rf, re.I | re.U) plugins = [ re.sub(rf, rt, p) if repr.match(p) else p for p in plugins ] return set(plugins)
def load_config(category, section): conf = None if category == "general": conf = PYLOAD.getConfigDict() elif category == "plugin": conf = PYLOAD.getPluginConfigDict() for key, option in conf[section].iteritems(): if key in ("desc","outline"): continue if ";" in option["type"]: option["list"] = option["type"].split(";") option["value"] = decode(option["value"]) return render_to_response("settings_item.html", {"skey": section, "section": conf[section]})
def renderFooter(self, line): """ prints out the input line with input """ println(line, "") line += 1 println(line, white(" Input: ") + decode(self.input)) #clear old output if line < self.lastLowestLine: for i in range(line + 1, self.lastLowestLine + 1): println(i, "") self.lastLowestLine = line #set cursor to position print "\033[" + str(self.inputline) + ";0H"
def _log(self, level, *args, **kwargs): if "sep" in kwargs: sep = "%s" % kwargs["sep"] else: sep = " | " strings = [] for obj in args: if type(obj) == unicode: strings.append(obj) elif type(obj) == str: strings.append(decode(obj)) else: strings.append(str(obj)) getattr(self.log, level)("%s: %s" % (self.__name__, sep.join(strings)))
def listContent(self): command = "vb" if self.fullpath else "lb" p = self.call_unrar(command, "-v", self.file, password=self.password) out, err = p.communicate() if "Cannot open" in err: raise ArchiveError("Cannot open file") if err.strip(): #: only log error at this point self.m.logError(err.strip()) result = set() for f in decode(out).splitlines(): f = f.strip() result.add(save_join(self.out, f)) self.files = result
def parsePackages(self, startNode): return [(decode(node.getAttribute("name")).decode('base64'), self.parseLinks(node)) \ for node in startNode.getElementsByTagName("package")]