def set_utility_file(self, path, lang, name): with open(os.path.join(self.directory, path), "r") as f: code = f.read() lang = LANGUAGE_ADAPTER[lang] fingerprint = sha_hash( sha_hash(lang) + sha_hash(code) + sha_hash(name)) try: sp = SpecialProgram.objects.get(fingerprint=fingerprint) except: sp = SpecialProgram.objects.create(fingerprint=fingerprint, lang=lang, filename=name, category=name, code=code) setattr(self.problem, name, sp.fingerprint)
def save_fingerprint(self): self.fingerprint = sha_hash( sha_hash(self.lang) + sha_hash(self.code) + sha_hash(self.tag))
def post(self, request, *args, **kwargs): code = request.POST["code"] expire_seconds = int(request.POST["expire"]) h = sha_hash(code)[:8] cache.set("PASTEBIN" + h, code, min(max(expire_seconds, 10), 86400)) return redirect(reverse('pastebin') + '?id=' + h)