Mercurial > paraspace
changeset 32:9bac21d401fe
Make get_parent() as a method of structpath.context
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 15 Jun 2011 02:03:38 +0800 |
parents | aed662c820d8 |
children | e625ebf17441 |
files | paraspace/structpath.py |
diffstat | 1 files changed, 7 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/paraspace/structpath.py Wed Jun 15 01:09:35 2011 +0800 +++ b/paraspace/structpath.py Wed Jun 15 02:03:38 2011 +0800 @@ -15,6 +15,9 @@ pass self.objs = objs pass + + def get_parent(self, obj): + raise NotImplementedError, 'get_parent() is not implemented' pass @@ -46,10 +49,6 @@ return part == '..' -def _get_parent(obj): - raise NotImplementedError, '_get_parent() is not implemented' - - def _obj_attr(obj, attrname): if isinstance(obj, list): idx = int(attrname) @@ -62,7 +61,7 @@ def _handle_path_part_obj(ctx, part, obj): if _is_parent_name(part): - new_objs = [_get_parent(obj)] + new_objs = [ctx.get_parent(obj)] elif _is_class(part): class_name = _class_name(part) new_objs = ctx.class_instances[class_name] @@ -76,19 +75,19 @@ from itertools import chain if not ctx.objs: - ctx = context([ctx.root], ctx) + ctx = ctx.__class__([ctx.root], ctx) pass objss = [_handle_path_part_obj(ctx, part, obj) for obj in ctx.objs] objs = [o for o in chain(*objss)] - new_ctx = context(objs, ctx) + new_ctx = ctx.__class__(objs, ctx) return new_ctx def _handle_path_parts(ctx, path_parts): if _is_abs(path_parts): - ctx = context([ctx.root], ctx) + ctx = ctx.__class__([ctx.root], ctx) path_parts = _rel_of_abs(path_parts) pass