summaryrefslogtreecommitdiff
path: root/pastepy.py
diff options
context:
space:
mode:
Diffstat (limited to 'pastepy.py')
-rw-r--r--pastepy.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/pastepy.py b/pastepy.py
index 20b386f..f63d275 100644
--- a/pastepy.py
+++ b/pastepy.py
@@ -1,4 +1,4 @@
-import templates, pygments, cgi, db, datetime, hashlib, settings, os, mimetypes
+import templates, pygments, cgi, db, datetime, hashlib, settings, os, mimetypes, Cookie
from pygments import highlight
from pygments.lexers import get_all_lexers, get_lexer_by_name
from pygments.formatters import HtmlFormatter
@@ -22,6 +22,7 @@ class Paste(object):
self.formatter = HtmlFormatter(linenos = 'table', lineanchors = 'line', anchorlinenos = True)
def paste(self):
+ c = Cookie.SimpleCookie(self.environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in self.environ else None)
if self.environ['REQUEST_METHOD'] == 'POST':
mp = cgi.FieldStorage(fp = self.environ['wsgi.input'], environ = self.environ, keep_blank_values = True)
if mp['type'].value == 'Preview':
@@ -36,6 +37,8 @@ class Paste(object):
'title': settings.pastebin_name,
'header': settings.pastebin_name,
'lexers': self.lexers,
+ 'nick': c['nick'].value if 'nick' in c else 'Anonymous',
+ 'remembered': 'nick' in c,
}))]
def preview(self, mp):
@@ -75,7 +78,13 @@ class Paste(object):
finally:
session.close()
- self.start_response('302 Found', [('Location', '/view/%s' % hash)])
+ headers = [('Location', '/view/%s' % hash)]
+ c = Cookie.SimpleCookie()
+ c['nick'] = nick
+ dt = (datetime.datetime.utcnow() + datetime.timedelta(days = 30)) if 'remember_me' in mp else datetime.datetime.utcfromtimestamp(0)
+ c['nick']['expires'] = dt.strftime('%a, %d-%b-%y %H:%M:%S GMT')
+ headers.append(('Set-Cookie', c['nick'].OutputString()))
+ self.start_response('302 Found', headers)
return []
def view(self):