Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Last active August 29, 2015 14:16
Show Gist options
  • Save mgedmin/391acd3828424e856d0c to your computer and use it in GitHub Desktop.
Save mgedmin/391acd3828424e856d0c to your computer and use it in GitHub Desktop.
Fix for https://github.com/mgedmin/zodbbrowser/issues/12 and another issue I haven't filed yet
--- /srv/zopes/akl-2.13/eggs/zodbbrowser-0.12.0-py2.6.egg/zodbbrowser/browser.py.orig 2015-02-27 16:40:42.000000000 +0200
+++ /srv/zopes/akl-2.13/eggs/zodbbrowser-0.12.0-py2.6.egg/zodbbrowser/browser.py 2015-02-27 17:08:21.000000000 +0200
@@ -92,6 +92,9 @@
def __call__(self):
try:
return self.render()
+ except:
+ import traceback; traceback.print_exc()
+ import pdb; pdb.post_mortem()
finally:
if self.readonly or not self.made_changes:
resources = transaction.get()._resources
@@ -399,12 +402,17 @@
diff = compareDictsHTML(curState, oldState, d['tid'])
results.append(dict(utid=u64(d['tid']),
+ xtid='0x%x' % u64(d['tid']),
href=url, current=current,
error=state[n]['error'],
- diff=diff, user_id=user_id,
- user_location=user_location,
+ diff=diff, user_id=unicodify(user_id),
+ user_location=unicodify(user_location),
utc_timestamp=utc_timestamp,
- local_timestamp=local_timestamp, **d))
+ local_timestamp=local_timestamp,
+ size=d['size'],
+ location=unicodify(d.get('location')),
+ request_type=unicodify(d.get('request_type')),
+ description=unicodify(d['description'])))
# number in reverse order
for i in range(len(results)):
@@ -514,9 +522,9 @@
index=(self.first_idx + n + 1),
utc_timestamp=utc_timestamp,
local_timestamp=local_timestamp,
- user_id=user_id,
- user_location=user_location,
- description=d.description,
+ user_id=unicodify(user_id),
+ user_location=unicodify(user_location),
+ description=unicodify(d.description),
utid=utid,
current=(d.tid == requested_tid),
href=self.getUrl(tid=utid),
@@ -573,3 +581,28 @@
break
return ''.join(path[::-1])
+
+def unicodify(s):
+ r"""Make sure the value is unicode.
+
+ The data comes from the database and may be unicode or it may be a
+ string in some unknown encoding, or it may be None.
+
+ >>> unicodify(u'\u263B')
+ u'\u263b'
+
+ >>> unicodify('\xe2\x98\xbb')
+ u'\u263b'
+
+ >>> unicodify('\xff')
+ "'\xff'"
+
+ >>> unicodify(None)
+
+ """
+ if isinstance(s, str):
+ try:
+ return unicode(s, 'utf-8')
+ except UnicodeDecodeError:
+ return repr(s)
+ return s
--- eggs/zodbbrowser-0.12.0-py2.6.egg/zodbbrowser/templates/zodbinfo.pt.orig 2015-02-27 17:05:28.000000000 +0200
+++ eggs/zodbbrowser-0.12.0-py2.6.egg/zodbbrowser/templates/zodbinfo.pt 2015-02-27 17:05:22.000000000 +0200
@@ -103,7 +103,7 @@
and 'transaction current' or 'transaction'">
<h4 class="transaction" tal:attributes="id string:tid${history/utid}">
<a class="subtitle"
- tal:attributes="href string:@@zodbbrowser_history?tid=${history/utid}">view transaction record</a>
+ tal:attributes="href string:@@zodbbrowser_history?tid=${history/xtid}">view transaction record</a>
<a class="title" tal:attributes="href history/href">
#<span tal:replace="history/index" />:
<span class="timestamp" tal:content="string:${history/utc_timestamp}" title="UTC" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment