aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/util
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-08 08:54:50 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-08 08:54:50 -0500
commit44b4e3f8b6405d0e1e0ebf6cb526ab62cdbbdb25 (patch)
tree213e8842f2edbede6e31af409200842ff5ad940c /libbe/util
parent7a8b1223fac612ef8b3dffd0e4c6832a97aa222d (diff)
downloadbugseverywhere-44b4e3f8b6405d0e1e0ebf6cb526ab62cdbbdb25.tar.gz
Transitioned bugdir.py to new storage format.
Diffstat (limited to 'libbe/util')
-rw-r--r--libbe/util/encoding.py23
-rw-r--r--libbe/util/id.py35
2 files changed, 46 insertions, 12 deletions
diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py
index d09117f..21e40cf 100644
--- a/libbe/util/encoding.py
+++ b/libbe/util/encoding.py
@@ -1,4 +1,3 @@
-# Bugs Everywhere, a distributed bugtracker
# Copyright (C) 2008-2009 Gianluca Montecchi <gian@grys.it>
# W. Trevor King <wking@drexel.edu>
#
@@ -62,5 +61,27 @@ def set_IO_stream_encodings(encoding):
sys.stdout = codecs.getwriter(encoding)(sys.__stdout__)
sys.stderr = codecs.getwriter(encoding)(sys.__stderr__)
+
+ def _guess_encoding(self):
+ return encoding.get_encoding()
+ def _check_encoding(value):
+ if value != None:
+ return encoding.known_encoding(value)
+ def _setup_encoding(self, new_encoding):
+ # change hook called before generator.
+ if new_encoding not in [None, settings_object.EMPTY]:
+ if self._manipulate_encodings == True:
+ encoding.set_IO_stream_encodings(new_encoding)
+ def _set_encoding(self, old_encoding, new_encoding):
+ self._setup_encoding(new_encoding)
+ self._prop_save_settings(old_encoding, new_encoding)
+
+ @_versioned_property(name="encoding",
+ doc="""The default input/output encoding to use (e.g. "utf-8").""",
+ change_hook=_set_encoding,
+ generator=_guess_encoding,
+ check_fn=_check_encoding)
+ def encoding(): return {}
+
if libbe.TESTING == True:
suite = doctest.DocTestSuite()
diff --git a/libbe/util/id.py b/libbe/util/id.py
index 0f1576c..d57205f 100644
--- a/libbe/util/id.py
+++ b/libbe/util/id.py
@@ -19,6 +19,8 @@
Handle ID creation and parsing.
"""
+import os.path
+
import libbe
if libbe.TESTING == True:
@@ -59,6 +61,7 @@ except ImportError:
def _assemble(*args):
+ args = list(args)
for i,arg in enumerate(args):
if arg == None:
args[i] = ''
@@ -71,31 +74,41 @@ def _split(id):
args[i] = None
return args
+def _is_a_uuid(id):
+ if id.startswith('uuid:'):
+ return True
+ return False
+
+def _uuid_to_id(id):
+ return 'uuid:' + id
+
+def _id_to_uuid(id):
+ return id[len('uuid:'):]
def bugdir_id(bugdir, *args):
- return _assemble(bugdir.uuid, args)
+ return _assemble(_uuid_to_id(bugdir.uuid), *args)
def bug_id(bug, *args):
- if bug.bug == None:
- bugdir_id = None
+ if bug.bugdir == None:
+ bdid = None
else:
- bugdir_id = bugdir_id(bug.bugdir)
- return _assemble(bugdir_id, bug.uuid, args)
+ bdid = bugdir_id(bug.bugdir)
+ return _assemble(bdid, _uuid_to_id(bug.uuid), *args)
def comment_id(comment, *args):
if comment.bug == None:
- bug_id = None
+ bid = None
else:
- bug_id = bug_id(comment.bug)
- return _assemble(bug_id, comment.uuid, args)
+ bid = bug_id(comment.bug)
+ return _assemble(bid, _uuid_to_id(comment.uuid), *args)
def parse_id(id):
args = _split(id)
- ret = {'bugdir':args.pop(0)}
+ ret = {'bugdir':_id_to_uuid(args.pop(0))}
type = 'bugdir'
for child_name in ['bug', 'comment']:
- if len(args) > 0 and is_a_uuid(args[0]):
- ret[child_name] = args.pop(0)
+ if len(args) > 0 and _is_a_uuid(args[0]):
+ ret[child_name] = _id_to_uuid(args.pop(0))
type = child_name
ret['type'] = type
ret['remaining'] = os.path.join(args)