from misc import Object
class Nopaste(Object):
- def create(self, subject, content, expires=None, account=None, address=None):
+ def create(self, subject, content, type="text", expires=None, account=None, address=None):
self._cleanup_database()
uid = None
if account:
uid = account.uid
+ # Escape any backslashes. PostgreSQL tends to think that they lead octal
+ # values or something that confuses the convertion from text to bytea.
+ if type == "text":
+ content = content.replace("\\", "\\\\")
+
# http://blog.00null.net/easily-generating-random-strings-in-postgresql/
res = self.db.get("INSERT INTO nopaste(uuid, subject, content, time_expires, address, uid) \
VALUES(random_slug(), %s, %s, (CASE WHEN %s = 0 THEN NULL ELSE NOW() + INTERVAL '%s seconds' END), \