Changeset 18476
- Timestamp:
- Apr 9, 2022, 10:54:14 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tracdragdropplugin/0.12/tracdragdrop/web_ui.py
r18448 r18476 7 7 import re 8 8 import socket 9 import sys 9 10 from pkg_resources import parse_version, resource_filename 10 11 from tempfile import TemporaryFile … … 23 24 from trac.util.translation import domain_functions, dgettext 24 25 26 if sys.version_info[0] == 2: 27 text_type = unicode 28 binary_type = str 29 else: 30 text_type = str 31 binary_type = bytes 32 25 33 _parsed_version = parse_version(__version__) 26 34 … … 54 62 def gettext_messages(msgid, **args): 55 63 return dgettext('messages', msgid, **args) 64 65 66 def _get_except(): 67 return sys.exc_info()[1] 56 68 57 69 … … 205 217 req.args['realm'] = match.group(2) 206 218 req.args['path'] = match.group(3) 207 except (IOError, socket.error) , e:208 if _is_disconnected(req, e):219 except (IOError, socket.error): 220 if _is_disconnected(req, _get_except()): 209 221 raise RequestDone 210 222 raise … … 247 259 except RequestDone: 248 260 raise 249 except TracError, e: 250 return self._send_message_on_except(req, e, 500) 251 except PermissionError, e: 252 return self._send_message_on_except(req, e, 403) 253 except Exception, e: 254 self.log.error('Internal error in tracdragdrop', 255 exc_info=True) 256 return self._send_message_on_except(req, e, 500) 261 except TracError: 262 return self._send_message_on_except(req, _get_except(), 500) 263 except PermissionError: 264 return self._send_message_on_except(req, _get_except(), 403) 265 except: 266 self.log.error('Internal error in tracdragdrop', exc_info=True) 267 return self._send_message_on_except(req, _get_except(), 500) 257 268 258 269 def _delegate_new_request(self, req): … … 266 277 try: 267 278 mod.process_request(req) 268 except OSError, e: 279 except OSError: 280 e = _get_except() 269 281 if e.args[0] == errno.ENAMETOOLONG: 270 282 raise TracError(_("Can't attach due to too long file " … … 291 303 AttachmentModule(self.env).process_request(req) 292 304 except RedirectListened: 293 req.send( 'Ok', status=200)305 req.send(binary_type(), status=200) 294 306 295 307 def _render_attachments(self, req): … … 322 334 323 335 def _send_message_on_except(self, req, message, status): 324 if not isinstance(message, unicode):336 if not isinstance(message, text_type): 325 337 message = to_unicode(message) 326 338 req.send_header('Connection', 'close') … … 360 372 if value is None: 361 373 return None 362 if isinstance(value, unicode):374 if isinstance(value, text_type): 363 375 value = value.encode('utf-8') 364 376 … … 389 401 try: 390 402 buf = input.read(n) 391 except (IOError, socket.error) , e:392 if _is_disconnected(req, e):403 except (IOError, socket.error): 404 if _is_disconnected(req, _get_except()): 393 405 raise RequestDone 394 406 raise
Note: See TracChangeset
for help on using the changeset viewer.