Commit 455ab5b5 authored by gijs's avatar gijs

Pad extensions, syntax around exception handling

parent 5e11c38c
......@@ -57,8 +57,8 @@ cf http://fredericiana.com/2010/10/08/decoding-html-entities-to-text-in-python/
h = HTMLParser()
unescape = h.unescape
allowed_extensions = ['md', 'html', 'css']
default_extension = 'md'
allowed_extensions = ['.md', '.html', '.css']
default_extension = '.md'
"""
Create a regex for our include template tag
......@@ -79,12 +79,12 @@ def padCreate(request):
form = forms.PadCreate(request.POST)
if form.is_valid():
n, ext = os.path.splitext(form.cleaned_data['name'])
n = re.sub(r'\s+', u'_', n)
n = re.sub(r'\s+', '_', n)
if ext in allowed_extensions:
n = '{}.{}'.format(n, ext)
n = '{}{}'.format(n, ext)
else:
n = '{}.{}'.format(n, default_extension)
n = '{}{}'.format(n, default_extension)
pad = Pad(
name=slugify(n)[:42], # This is the slug internally used by etherpad
......@@ -135,7 +135,7 @@ def pad(request, pk=None, slug=None): # pad_write
'pad': pad,
'link': padLink,
'server': server,
'uname': u"%s" % author.user,
'uname': "{}".format(author.user),
'error': _('You are not allowed to view or edit this pad')
},
context_instance=RequestContext(request)
......@@ -160,7 +160,7 @@ def pad(request, pk=None, slug=None): # pad_write
author.authorID,
time.mktime(expires.timetuple()).__str__()
)
except(Exception, e):
except Exception as e:
response = render(
request,
'pad.html',
......@@ -168,9 +168,9 @@ def pad(request, pk=None, slug=None): # pad_write
'pad': pad,
'link': padLink,
'server': server,
'uname': u"%s" % author.user,
'uname': "{}".format(author.user),
'error': _('etherpad-lite session request returned:') +
' "' + e.reason + '"'
' "' + e.reason if isinstance(e, UnicodeError) else str(e) + '"'
}
)
return response
......@@ -183,7 +183,7 @@ def pad(request, pk=None, slug=None): # pad_write
'pad': pad,
'link': padLink,
'server': server,
'uname': u"%s" % author.user,
'uname': "{}".format(author.user),
'error': False,
'mode' : 'write'
},
......@@ -359,7 +359,7 @@ def home(request):
hash = {}
for article in articles:
if sort in article:
if isinstance(article[sort], basestring):
if isinstance(article[sort], str):
subject = article[sort]
if not subject in hash:
hash[subject] = [article]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment