My favorites
▼
|
Sign in
json-template
Minimal but powerful templating language implemented in multiple languages
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
73
attachment: py3k.patch
(3.1 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
--- jsontemplate.py.orig Fri Jun 29 10:03:38 2012
+++ jsontemplate.py Thu Aug 2 12:38:04 2012
@@ -38,16 +38,28 @@
# Function API
'SIMPLE_FUNC', 'ENHANCED_FUNC']
-import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
import pprint
import re
import sys
+try:
+ basestring
+except NameError:
+ # Python 3
+ basestring = str
# For formatters
import cgi # cgi.escape
import time # for strftime
-import urllib # for urllib.encode
-import urlparse # for urljoin
+try:
+ # Python 3
+ from urllib.parse import urlencode, urljoin, quote_plus
+except ImportError:
+ from urllib import urlencode, quote_plus
+ from urlparse import urljoin
class Error(Exception):
@@ -702,7 +714,7 @@
"""
# urljoin is flexible about trailing/leading slashes -- it will add or de-dupe
# them
- return urlparse.urljoin(context.Lookup('base-url'), relative_url)
+ return urljoin(context.Lookup('base-url'), relative_url)
def _Reverse(x):
@@ -744,10 +756,10 @@
'size': lambda value: str(len(value)),
# The argument is a dictionary, and we get a a=1&b=2 string back.
- 'url-params': lambda x: urllib.urlencode(x, doseq=True),
+ 'url-params': lambda x: urlencode(x, doseq=True),
# The argument is an atom, and it takes 'Search query?' -> 'Search+query%3F'
- 'url-param-value': urllib.quote_plus, # param is an atom
+ 'url-param-value': quote_plus, # param is an atom
# The default formatter, when no other default is specifier. For debugging,
# this could be lambda x: json.dumps(x, indent=2), but here we want to be
@@ -889,7 +901,7 @@
if n % 2 == 1:
raise ConfigurationError(
'%r has an odd number of metacharacters' % meta)
- return meta[:n/2], meta[n/2:]
+ return meta[:n//2], meta[n//2:]
_token_re_cache = {}
@@ -1238,7 +1250,7 @@
def FromString(s, **kwargs):
"""Like FromFile, but takes a string."""
- f = StringIO.StringIO(s)
+ f = StringIO(s)
return FromFile(f, **kwargs)
@@ -1280,7 +1292,8 @@
# HTTP/E-mail headers.
name = name.lower()
# In Python 2.4, kwargs must be plain strings
- name = name.encode('utf-8')
+ # XXX Python 3
+# name = name.encode('utf-8')
if name in _OPTION_NAMES:
name = name.replace('-', '_')
@@ -1634,7 +1647,7 @@
else:
try:
value = context.Lookup(name)
- except TypeError, e:
+ except TypeError as e:
raise EvaluationError(
'Error evaluating %r in context %r: %r' % (name, context, e))
@@ -1667,7 +1680,7 @@
# Don't "wrap" recursive EvaluationErrors
raise
- except Exception, e:
+ except Exception as e:
if formatter_type == TEMPLATE_FORMATTER:
raise # in this case we want to see the original exception
raise EvaluationError(
@@ -1702,7 +1715,7 @@
try:
func, args = statement
func(args, context, callback, trace)
- except UndefinedVariable, e:
+ except UndefinedVariable as e:
# Show context for statements
start = max(0, i-3)
end = i+3
Powered by
Google Project Hosting