From fa511457866b36bf3686d9398495371363672b77 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 24 Mar 2017 21:59:23 +0100 Subject: Use http.cookies with fallback to Cookie. --- pastepy.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pastepy.py b/pastepy.py index fafc81e..3c919a4 100644 --- a/pastepy.py +++ b/pastepy.py @@ -1,5 +1,8 @@ import cgi -import Cookie +try: + from http.cookies import SimpleCookie +except ImportError: + from Cookie import SimpleCookie import datetime import db import mimetypes @@ -73,7 +76,7 @@ class Paste(object): }) def paste(self): - c = Cookie.SimpleCookie(self.environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in self.environ else None) + c = 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': @@ -127,7 +130,7 @@ class Paste(object): session.close() headers = [('Location', '/view/%s' % hash)] - c = Cookie.SimpleCookie() + c = 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') -- cgit v1.2.3