Skip to content

Commit

Permalink
print data that's a string (best effort) as a string, otw as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
phunt committed Oct 24, 2009
1 parent 21a487a commit 43ce91a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion zktree/templates/zktree/index.html
Expand Up @@ -19,7 +19,7 @@ <h1>ZooKeeper ZNode {{znode.path}}</h1>
Path : {{znode.path}} Path : {{znode.path}}
<p> <p>


Data : {{znode.data}} Data({{znode.datatype}}) : {{znode.data}}
<p> <p>


</div> </div>
Expand Down
13 changes: 13 additions & 0 deletions zktree/views.py
@@ -1,13 +1,26 @@
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
import string


from zookeeper_dashboard.zktree.models import ZNode 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=""): def index(request, path=""):
print(path) print(path)
path = "/" + path path = "/" + path
try: try:
znode = ZNode(path) znode = ZNode(path)
znode.children.sort() 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', return render_to_response('zktree/index.html',
{'znode':znode}) {'znode':znode})
except Exception as err: except Exception as err:
Expand Down

0 comments on commit 43ce91a

Please sign in to comment.