Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#7519 closed defect (fixed)

[Patch] "view as plaintext" results in unicode error (0.12 compatibility)

Reported by:… Owned by: Michael Renzmann
Priority: normal Component: TracPastePlugin
Severity: normal Keywords:
Cc: lkraav Trac Release: 0.12


Using TracPaste 0.2 and Trac 0.12. Created a paste containing this, which is all straight ASCII:

myfunc () {

  find . -name ... | sed "s/$pat/$repl/g"

myfunc old1 new1
myfunc old2 new2

This paste views fine, but if you select the "plain text" link at the bottom of the page, it then throws a unicode exception:

Trac detected an internal error:

ValueError: Can't send unicode content

Python Traceback
Most recent call last:

    * File "/var/www/", line 513, in _dispatch_request
      Code fragment:
      508	try:
      509	if not env and env_error:
      510	raise HTTPInternalError(env_error)
      511	try:
      512	dispatcher = RequestDispatcher(env)
      513	dispatcher.dispatch(req)
      514	except RequestDone:
      515	pass
      516	resp = req._response or []
      518	except HTTPException, e:
      Local variables:
      Name	Value
      dispatcher 	<trac.web.main.RequestDispatcher object at 0x2416190>
      e 	ValueError("Can't send unicode content",)
      env 	<trac.env.Environment object at 0x1bbc890>
      env_error 	None
      req 	<Request "GET '/pastebin/103'">
      resp 	[]
    * File "/var/www/", line 235, in dispatch
      Code fragment:
      230	msg = _('Do you have cookies enabled?')
      231	raise HTTPBadRequest(_('Missing or invalid form token.'
      232	' %(msg)s', msg=msg))
      234	# Process the request and render the template
      235	resp = chosen_handler.process_request(req)
      236	if resp:
      237	if len(resp) == 2: # Clearsilver
      238	chrome.populate_hdf(req)
      239	template, content_type = \
      240	self._post_process_request(req, *resp)
      Local variables:
      Name	Value
      chosen_handler 	<tracpaste.web_ui.TracpastePlugin object at 0x24165d0>
      chrome 	< object at 0x2407d50>
      err 	(<type 'exceptions.ValueError'>, ValueError("Can't send unicode ...
      handler 	<tracpaste.web_ui.TracpastePlugin object at 0x24165d0>
      req 	<Request "GET '/pastebin/103'">
      self 	<trac.web.main.RequestDispatcher object at 0x2416190>
    * File "/var/www/", line 164, in process_request
      Code fragment:
      159	req.send_response(200)
      160	req.send_header('Content-Type', mimetype)
      161	req.send_header('Content-Length', len(
      162	req.send_header('Last-Modified', http_date(paste.time))
      163	req.end_headers()
      164	req.write(
      165	return
      166	else:
      167"*** download denied")
      169	data = {
      Local variables:
      Name	Value
      mimetype 	'text/plain'
      paste 	<Paste u'untitled': 103>
      req 	<Request "GET '/pastebin/103'">
      self 	<tracpaste.web_ui.TracpastePlugin object at 0x24165d0>
    * File "/var/www/", line 530, in write
      Code fragment:
      525	if not self._write:
      526	self.end_headers()
      527	if not hasattr(self, '_content_length'):
      528	raise RuntimeError("No Content-Length header set")
      529	if isinstance(data, unicode):
      530	raise ValueError("Can't send unicode content")
      531	try:
      532	self._write(data)
      533	except (IOError, socket.error), e:
      534	if e.args[0] in (errno.EPIPE, errno.ECONNRESET, 10053, 10054):
      535	raise RequestDone
      Local variables:
      Name	Value
      data 	u'myfunc () {\r\n pat="$1"\r\n repl="$2"\r\n\r\n find . -name ... | sed ...
      self 	<Request "GET '/pastebin/103'">

File "/var/www/", line 513, in _dispatch_request
File "/var/www/", line 235, in dispatch
  resp = chosen_handler.process_request(req)
File "/var/www/", line 164, in process_request
File "/var/www/", line 530, in write
  raise ValueError("Can't send unicode content")

System Information:

User Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8
Trac 	0.12
Docutils 	0.8
Genshi 	0.6
mod_wsgi 	2.8 (WSGIProcessGroup xyz_trac WSGIApplicationGroup|)
Pygments 	1.3.1
pysqlite 	2.4.0
Python 	2.5.2 (r252:60911, Jan 20 2010, 23:30:56) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)]
setuptools 	0.6c9
SQLite 	3.4.2
Subversion 	1.5.1 (r32289)
jQuery	1.2.6

Enabled Plugins:
BlackMagicTicketTweaks 	0.12r1 	/var/www/
Screamer 	0.6.0 	/var/www/
timingandestimationplugin 	1.0.6 	/var/www/
TracBurndown 	1.9.2 	/var/www/
TracPaste 	0.2 	/var/www/
TracWikiNotification 	0.2.1 	/var/www/

Attachments (1)

tracpasteplugin.r7022.patch (1.0 KB) - added by Ryan J Ollos 6 years ago.
Patch against r7022 of TracPastePlugin

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by Ryan J Ollos

It appears this may be the same issue that we see in #7556 for the VotePlugin, which PeterLawrence tracked down a solution for in t:#8675.

comment:2 Changed 6 years ago by Ryan J Ollos

Summary: "view as plaintext" results in unicode error[Patch] "view as plaintext" results in unicode error (0.12 compatibility)

Here is a patch. It's a simple fix and I'd be happy to apply it to the repository if given the go-ahead.

Changed 6 years ago by Ryan J Ollos

Attachment: tracpasteplugin.r7022.patch added

Patch against r7022 of TracPastePlugin

comment:3 Changed 6 years ago by Ryan J Ollos

Cc: lkraav added; anonymous removed

comment:4 Changed 6 years ago by Michael Renzmann

Thanks for the patch. Looks good, no objection from my side. Feel free to commit it.

comment:5 Changed 6 years ago by Ryan J Ollos

Resolution: fixed
Status: newclosed

(In [8501]) Fixed error in Trac 0.12 when Download in 'Plain Text' or 'Original Format' were selected. Fixes #7519.

comment:6 Changed 6 years ago by Ryan J Ollos

(In [8502]) Accidentally added an egg-info dir in previous commit. Refs #7519.

Modify Ticket

as closed The owner will remain Michael Renzmann.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.