Skip to content
Browse files

print data that's a string (best effort) as a string, otw as hex

  • Loading branch information...
1 parent 21a487a commit 43ce91a995d235fe593743672e0c72cfb8d60da3 @phunt committed Oct 23, 2009
Showing with 14 additions and 1 deletion.
  1. +1 −1 zktree/templates/zktree/index.html
  2. +13 −0 zktree/views.py
View
2 zktree/templates/zktree/index.html
@@ -19,7 +19,7 @@
Path : {{znode.path}}
<p>
-Data : {{znode.data}}
+Data({{znode.datatype}}) : {{znode.data}}
<p>
</div>
View
13 zktree/views.py
@@ -1,13 +1,26 @@
from django.shortcuts import render_to_response
+import string
from zookeeper_dashboard.zktree.models import ZNode
+def istext(s, text_chars="".join(map(chr, range(32, 127))) + "\n\r\t\b"):
+ if "\0" in s: return False
+ if not s: return True
+ t = s.translate(string.maketrans("", ""), text_chars)
+ return len(t) == 0
+
def index(request, path=""):
print(path)
path = "/" + path
try:
znode = ZNode(path)
znode.children.sort()
+ if not istext(znode.data):
+ znode.data = "0x" + "".join(["%d" % (ord(d)) for d in znode.data])
+ znode.datatype = "bin"
+ else:
+ znode.datatype = "str"
+
return render_to_response('zktree/index.html',
{'znode':znode})
except Exception as err:

0 comments on commit 43ce91a

Please sign in to comment.
Something went wrong with that request. Please try again.