Mercurial > paraspace
annotate paraspace/structpath.py @ 35:2f9e7f03dbf7
Support predicates in structpath.py
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 15 Jun 2011 12:03:23 +0800 |
parents | fe1ebf0c3d40 |
children | 0b9ac7cef6e5 |
rev | line source |
---|---|
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
1 ## |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
2 # Implement a xpath liked query language. |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
3 # |
35
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
4 # \section predicate Predicate |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
5 # Structpath uses syntax of Python for predicate. That means you must use |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
6 # '==' instead of '='. |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
7 # |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
8 class context(object): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
9 all_classes = None |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
10 class_instances = None |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
11 root = None |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
12 objs = None |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
13 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
14 def __init__(self, objs, ctx=None): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
15 if ctx: |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
16 self.all_classes = ctx.all_classes |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
17 self.class_instances = ctx.class_instances |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
18 self.root = ctx.root |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
19 pass |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
20 self.objs = objs |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
21 pass |
32
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
22 |
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
23 def get_parent(self, obj): |
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
24 raise NotImplementedError, 'get_parent() is not implemented' |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
25 pass |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
26 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
27 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
28 def _path_split(path): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
29 parts = [p.strip() |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
30 for p in path.split('/')] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
31 return parts |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
32 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
33 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
34 def _is_abs(path_parts): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
35 if len(path_parts) == 0: |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
36 return False |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
37 return path_parts[0] == '' |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
38 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
39 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
40 def _rel_of_abs(path_parts): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
41 return path_parts[1:] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
42 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
43 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
44 def _is_class(part): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
45 return part.startswith('.') |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
46 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
47 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
48 def _class_name(part): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
49 return part[1:] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
50 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
51 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
52 def _is_parent_name(part): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
53 return part == '..' |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
54 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
55 |
35
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
56 def _split_attr_pred(part): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
57 try: |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
58 lq_idx = part.index('[') |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
59 except: |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
60 return part, '' |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
61 return part[:lq_idx].strip(), part[lq_idx:].strip() |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
62 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
63 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
64 def _eval_obj_sub_pred(ctx, obj, sub_pred): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
65 ns_global = {} |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
66 for attr in dir(obj): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
67 if attr.startswith('_'): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
68 continue |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
69 v = _obj_attr(obj, attr) |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
70 ns_global[attr] = v |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
71 pass |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
72 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
73 truth_v = eval(sub_pred, ns_global) |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
74 return truth_v |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
75 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
76 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
77 def _split_pred_into_subs(pred): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
78 striped_pred = pred.strip(' []\n\r') |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
79 subs = striped_pred.split('][') |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
80 return subs |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
81 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
82 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
83 def _eval_obj_pred(ctx, obj, pred): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
84 subs = _split_pred_into_subs(pred) |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
85 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
86 for sub in subs: |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
87 if not sub: |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
88 continue |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
89 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
90 if not _eval_obj_sub_pred(ctx, obj, sub): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
91 return False |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
92 pass |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
93 return True |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
94 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
95 |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
96 def _obj_attr(obj, attrname): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
97 if isinstance(obj, list): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
98 idx = int(attrname) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
99 return obj[idx] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
100 elif isinstance(obj, dict): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
101 key = eval(attrname) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
102 return obj[key] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
103 return getattr(obj, attrname) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
104 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
105 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
106 def _handle_path_part_obj(ctx, part, obj): |
35
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
107 attr, pred = _split_attr_pred(part) |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
108 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
109 if _is_parent_name(attr): |
32
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
110 new_objs = [ctx.get_parent(obj)] |
35
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
111 elif _is_class(attr): |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
112 class_name = _class_name(attr) |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
113 new_objs = ctx.class_instances[class_name] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
114 else: |
34
fe1ebf0c3d40
test get_parent() for structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
32
diff
changeset
|
115 try: |
35
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
116 new_objs = [_obj_attr(obj, attr)] |
34
fe1ebf0c3d40
test get_parent() for structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
32
diff
changeset
|
117 except AttributeError: |
fe1ebf0c3d40
test get_parent() for structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
32
diff
changeset
|
118 return [] |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
119 pass |
35
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
120 |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
121 new_objs = filter((lambda x: _eval_obj_pred(ctx, x, pred)), new_objs) |
2f9e7f03dbf7
Support predicates in structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
34
diff
changeset
|
122 |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
123 return new_objs |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
124 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
125 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
126 def _handle_path_part(ctx, part): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
127 from itertools import chain |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
128 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
129 if not ctx.objs: |
32
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
130 ctx = ctx.__class__([ctx.root], ctx) |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
131 pass |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
132 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
133 objss = [_handle_path_part_obj(ctx, part, obj) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
134 for obj in ctx.objs] |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
135 objs = [o for o in chain(*objss)] |
32
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
136 new_ctx = ctx.__class__(objs, ctx) |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
137 return new_ctx |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
138 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
139 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
140 def _handle_path_parts(ctx, path_parts): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
141 if _is_abs(path_parts): |
32
9bac21d401fe
Make get_parent() as a method of structpath.context
Thinker K.F. Li <thinker@codemud.net>
parents:
31
diff
changeset
|
142 ctx = ctx.__class__([ctx.root], ctx) |
31
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
143 path_parts = _rel_of_abs(path_parts) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
144 pass |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
145 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
146 if len(path_parts) == 1 and path_parts[0] == '': |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
147 return ctx |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
148 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
149 for path_part in path_parts: |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
150 ctx = _handle_path_part(ctx, path_part) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
151 pass |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
152 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
153 return ctx |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
154 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
155 |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
156 def find_objs_path(ctx, path): |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
157 path_parts = _path_split(path) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
158 rctx = _handle_path_parts(ctx, path_parts) |
aed662c820d8
xpath like query structpath.py
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
159 return rctx.objs |