comparison roundup/cgi/templating.py @ 5402:88dbacd11cd1

Python 3 preparation: update urllib / urllib2 / urlparse imports. The existing roundup/anypy/urllib_.py is extended to cover more imports and used in more places. Manual patch.
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 23:48:30 +0000
parents dccae35caa59
children 3757449e00c4
comparison
equal deleted inserted replaced
5401:4cf48ff01e04 5402:88dbacd11cd1
18 """ 18 """
19 19
20 __docformat__ = 'restructuredtext' 20 __docformat__ = 'restructuredtext'
21 21
22 22
23 import cgi, urllib, re, os.path, mimetypes, csv, string 23 import cgi, re, os.path, mimetypes, csv, string
24 import calendar 24 import calendar
25 import textwrap 25 import textwrap
26 import time, hashlib 26 import time, hashlib
27 27
28 from roundup.anypy import urllib_
28 from roundup import hyperdb, date, support 29 from roundup import hyperdb, date, support
29 from roundup import i18n 30 from roundup import i18n
30 from roundup.i18n import _ 31 from roundup.i18n import _
31 32
32 from .KeywordsExpr import render_keywords_expression_editor 33 from .KeywordsExpr import render_keywords_expression_editor
761 filtervalues = [] 762 filtervalues = []
762 names = [] 763 names = []
763 for x in filterprops: 764 for x in filterprops:
764 (name, values) = x.split('=') 765 (name, values) = x.split('=')
765 names.append(name) 766 names.append(name)
766 filtervalues.append('&amp;%s=%s' % (name, urllib.quote(values))) 767 filtervalues.append('&amp;%s=%s' % (name, urllib_.quote(values)))
767 filter = '&amp;@filter=%s%s' % (','.join(names), ''.join(filtervalues)) 768 filter = '&amp;@filter=%s%s' % (','.join(names), ''.join(filtervalues))
768 else: 769 else:
769 filter = '' 770 filter = ''
770 help_url = "%s?@startwith=0&amp;@template=help&amp;"\ 771 help_url = "%s?@startwith=0&amp;@template=help&amp;"\
771 "properties=%s%s%s%s%s%s&amp;@pagesize=%s%s" % \ 772 "properties=%s%s%s%s%s%s&amp;@pagesize=%s%s" % \
1197 # create a new request and override the specified args 1198 # create a new request and override the specified args
1198 req = HTMLRequest(self._client) 1199 req = HTMLRequest(self._client)
1199 req.classname = self._klass.get(self._nodeid, 'klass') 1200 req.classname = self._klass.get(self._nodeid, 'klass')
1200 name = self._klass.get(self._nodeid, 'name') 1201 name = self._klass.get(self._nodeid, 'name')
1201 req.updateFromURL(self._klass.get(self._nodeid, 'url') + 1202 req.updateFromURL(self._klass.get(self._nodeid, 'url') +
1202 '&@queryname=%s'%urllib.quote(name)) 1203 '&@queryname=%s'%urllib_.quote(name))
1203 1204
1204 # new template, using the specified classname and request 1205 # new template, using the specified classname and request
1205 # [ ] the custom logic for search page doesn't belong to 1206 # [ ] the custom logic for search page doesn't belong to
1206 # generic templating module (techtonik) 1207 # generic templating module (techtonik)
1207 tplname = self._client.selectTemplate(req.classname, 'search') 1208 tplname = self._client.selectTemplate(req.classname, 'search')
1217 """ Assume that this item is a FileClass and that it has a name 1218 """ Assume that this item is a FileClass and that it has a name
1218 and content. Construct a URL for the download of the content. 1219 and content. Construct a URL for the download of the content.
1219 """ 1220 """
1220 name = self._klass.get(self._nodeid, 'name') 1221 name = self._klass.get(self._nodeid, 'name')
1221 url = '%s%s/%s'%(self._classname, self._nodeid, name) 1222 url = '%s%s/%s'%(self._classname, self._nodeid, name)
1222 return urllib.quote(url) 1223 return urllib_.quote(url)
1223 1224
1224 def copy_url(self, exclude=("messages", "files")): 1225 def copy_url(self, exclude=("messages", "files")):
1225 """Construct a URL for creating a copy of this item 1226 """Construct a URL for creating a copy of this item
1226 1227
1227 "exclude" is an optional list of properties that should 1228 "exclude" is an optional list of properties that should
1244 query[name] = self[name].plain() 1245 query[name] = self[name].plain()
1245 else: 1246 else:
1246 query[name] = ",".join(self._klass.get(self._nodeid, name)) 1247 query[name] = ",".join(self._klass.get(self._nodeid, name))
1247 1248
1248 return self._classname + "?" + "&".join( 1249 return self._classname + "?" + "&".join(
1249 ["%s=%s" % (key, urllib.quote(value)) 1250 ["%s=%s" % (key, urllib_.quote(value))
1250 for key, value in query.items()]) 1251 for key, value in query.items()])
1251 1252
1252 class _HTMLUser(_HTMLItem): 1253 class _HTMLUser(_HTMLItem):
1253 """Add ability to check for permissions on users. 1254 """Add ability to check for permissions on users.
1254 """ 1255 """
1461 # just return the matched text 1462 # just return the matched text
1462 return match.group(0) 1463 return match.group(0)
1463 1464
1464 def url_quote(self): 1465 def url_quote(self):
1465 """ Return the string in plain format but escaped for use in a url """ 1466 """ Return the string in plain format but escaped for use in a url """
1466 return urllib.quote(self.plain()) 1467 return urllib_.quote(self.plain())
1467 1468
1468 def hyperlinked(self): 1469 def hyperlinked(self):
1469 """ Render a "hyperlinked" version of the text """ 1470 """ Render a "hyperlinked" version of the text """
1470 return self.plain(hyperlink=1) 1471 return self.plain(hyperlink=1)
1471 1472
2853 {..., '@queryname': request.dispname or None, ...} 2854 {..., '@queryname': request.dispname or None, ...}
2854 will include @queryname in the url if there is a 2855 will include @queryname in the url if there is a
2855 dispname otherwise the parameter will be omitted 2856 dispname otherwise the parameter will be omitted
2856 from the url. 2857 from the url.
2857 """ 2858 """
2858 q = urllib.quote 2859 q = urllib_.quote
2859 sc = self.special_char 2860 sc = self.special_char
2860 l = ['%s=%s'%(k,isinstance(v, basestring) and q(v) or v) 2861 l = ['%s=%s'%(k,isinstance(v, basestring) and q(v) or v)
2861 for k,v in args.items() if v != None ] 2862 for k,v in args.items() if v != None ]
2862 # pull out the special values (prefixed by @ or :) 2863 # pull out the special values (prefixed by @ or :)
2863 specials = {} 2864 specials = {}
3067 def anti_csrf_nonce(self, lifetime=None): 3068 def anti_csrf_nonce(self, lifetime=None):
3068 return anti_csrf_nonce(self, self.client, lifetime=lifetime) 3069 return anti_csrf_nonce(self, self.client, lifetime=lifetime)
3069 3070
3070 def url_quote(self, url): 3071 def url_quote(self, url):
3071 """URL-quote the supplied text.""" 3072 """URL-quote the supplied text."""
3072 return urllib.quote(url) 3073 return urllib_.quote(url)
3073 3074
3074 def html_quote(self, html): 3075 def html_quote(self, html):
3075 """HTML-quote the supplied text.""" 3076 """HTML-quote the supplied text."""
3076 return cgi.escape(html) 3077 return cgi.escape(html)
3077 3078

Roundup Issue Tracker: http://roundup-tracker.org/