comparison MoinMoin/wikiutil.py @ 4607:d8e5e9cfadf1

always do 'from werkzeug import ...', except for contrib, exceptions, routing, script
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 23 Feb 2009 22:39:32 +0100
parents 3caaa8c74c41
children 7ee24547de7d
comparison
equal deleted inserted replaced
4606:619b1dacf4ee 4607:d8e5e9cfadf1
24 from MoinMoin.util import pysupport, lock 24 from MoinMoin.util import pysupport, lock
25 from MoinMoin.support.python_compatibility import rsplit 25 from MoinMoin.support.python_compatibility import rsplit
26 from inspect import getargspec, isfunction, isclass, ismethod 26 from inspect import getargspec, isfunction, isclass, ismethod
27 27
28 from MoinMoin import web # needed so that next line works: 28 from MoinMoin import web # needed so that next line works:
29 import werkzeug.utils 29 import werkzeug
30 30
31 # Exceptions 31 # Exceptions
32 class InvalidFileNameError(Exception): 32 class InvalidFileNameError(Exception):
33 """ Called when we find an invalid file name """ 33 """ Called when we find an invalid file name """
34 pass 34 pass
89 pass 89 pass
90 raise UnicodeError('The string %r cannot be decoded.' % s) 90 raise UnicodeError('The string %r cannot be decoded.' % s)
91 91
92 92
93 def url_quote(s, safe='/', want_unicode=None): 93 def url_quote(s, safe='/', want_unicode=None):
94 """ see werkzeug.utils.url_quote, we use a different safe param default value """ 94 """ see werkzeug.url_quote, we use a different safe param default value """
95 try: 95 try:
96 assert want_unicode is None 96 assert want_unicode is None
97 except AssertionError: 97 except AssertionError:
98 log.exception("call with deprecated want_unicode param, please fix caller") 98 log.exception("call with deprecated want_unicode param, please fix caller")
99 return werkzeug.utils.url_quote(s, charset=config.charset, safe=safe) 99 return werkzeug.url_quote(s, charset=config.charset, safe=safe)
100 100
101 def url_quote_plus(s, safe='/', want_unicode=None): 101 def url_quote_plus(s, safe='/', want_unicode=None):
102 """ see werkzeug.utils.url_quote_plus, we use a different safe param default value """ 102 """ see werkzeug.url_quote_plus, we use a different safe param default value """
103 try: 103 try:
104 assert want_unicode is None 104 assert want_unicode is None
105 except AssertionError: 105 except AssertionError:
106 log.exception("call with deprecated want_unicode param, please fix caller") 106 log.exception("call with deprecated want_unicode param, please fix caller")
107 return werkzeug.utils.url_quote_plus(s, charset=config.charset, safe=safe) 107 return werkzeug.url_quote_plus(s, charset=config.charset, safe=safe)
108 108
109 def url_unquote(s, want_unicode=None): 109 def url_unquote(s, want_unicode=None):
110 """ see werkzeug.utils.url_unquote """ 110 """ see werkzeug.url_unquote """
111 try: 111 try:
112 assert want_unicode is None 112 assert want_unicode is None
113 except AssertionError: 113 except AssertionError:
114 log.exception("call with deprecated want_unicode param, please fix caller") 114 log.exception("call with deprecated want_unicode param, please fix caller")
115 return werkzeug.utils.url_unquote(s, charset=config.charset, errors='fallback:iso-8859-1') 115 return werkzeug.url_unquote(s, charset=config.charset, errors='fallback:iso-8859-1')
116 116
117 117
118 def parseQueryString(qstr, want_unicode=None): 118 def parseQueryString(qstr, want_unicode=None):
119 """ see werkzeug.utils.url_decode """ 119 """ see werkzeug.url_decode """
120 try: 120 try:
121 assert want_unicode is None 121 assert want_unicode is None
122 except AssertionError: 122 except AssertionError:
123 log.exception("call with deprecated want_unicode param, please fix caller") 123 log.exception("call with deprecated want_unicode param, please fix caller")
124 return werkzeug.utils.url_decode(qstr, charset=config.charset, errors='fallback:iso-8859-1', 124 return werkzeug.url_decode(qstr, charset=config.charset, errors='fallback:iso-8859-1',
125 decode_keys=False, include_empty=False) 125 decode_keys=False, include_empty=False)
126 126
127 def makeQueryString(qstr=None, want_unicode=None, **kw): 127 def makeQueryString(qstr=None, want_unicode=None, **kw):
128 """ Make a querystring from arguments. 128 """ Make a querystring from arguments.
129 129
130 kw arguments overide values in qstr. 130 kw arguments overide values in qstr.
131 131
132 If a string is passed in, it's returned verbatim and keyword parameters are ignored. 132 If a string is passed in, it's returned verbatim and keyword parameters are ignored.
133 133
134 See also: werkzeug.utils.url_encode 134 See also: werkzeug.url_encode
135 135
136 @param qstr: dict to format as query string, using either ascii or unicode 136 @param qstr: dict to format as query string, using either ascii or unicode
137 @param kw: same as dict when using keywords, using ascii or unicode 137 @param kw: same as dict when using keywords, using ascii or unicode
138 @rtype: string 138 @rtype: string
139 @return: query string ready to use in a url 139 @return: query string ready to use in a url
146 qstr = {} 146 qstr = {}
147 elif isinstance(qstr, (str, unicode)): 147 elif isinstance(qstr, (str, unicode)):
148 return qstr 148 return qstr
149 if isinstance(qstr, dict): 149 if isinstance(qstr, dict):
150 qstr.update(kw) 150 qstr.update(kw)
151 return werkzeug.utils.url_encode(qstr, charset=config.charset, encode_keys=True) 151 return werkzeug.url_encode(qstr, charset=config.charset, encode_keys=True)
152 else: 152 else:
153 raise ValueError("Unsupported argument type, should be dict.") 153 raise ValueError("Unsupported argument type, should be dict.")
154 154
155 155
156 def quoteWikinameURL(pagename, charset=config.charset): 156 def quoteWikinameURL(pagename, charset=config.charset):
163 might not be able to encode the page name and raise 163 might not be able to encode the page name and raise
164 UnicodeError. (default config.charset ('utf-8')). 164 UnicodeError. (default config.charset ('utf-8')).
165 @rtype: string 165 @rtype: string
166 @return: the quoted filename, all unsafe characters encoded 166 @return: the quoted filename, all unsafe characters encoded
167 """ 167 """
168 # XXX please note that urllib.quote and werkzeug.utils.url_quote have 168 # XXX please note that urllib.quote and werkzeug.url_quote have
169 # XXX different defaults for safe=... 169 # XXX different defaults for safe=...
170 return werkzeug.utils.url_quote(pagename, charset=charset, safe='/') 170 return werkzeug.url_quote(pagename, charset=charset, safe='/')
171 171
172 172
173 escape = werkzeug.utils.escape 173 escape = werkzeug.escape
174 174
175 175
176 def clean_input(text, max_len=201): 176 def clean_input(text, max_len=201):
177 """ Clean input: 177 """ Clean input:
178 replace CR, LF, TAB by whitespace 178 replace CR, LF, TAB by whitespace