# HG changeset patch # User Thinker K.F. Li # Date 1308074618 -28800 # Node ID 9bac21d401feb65ba237202aaafbe0d8a848ff40 # Parent aed662c820d884705a66c31ac5d16b2ca769ea64 Make get_parent() as a method of structpath.context diff -r aed662c820d8 -r 9bac21d401fe paraspace/structpath.py --- 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