equal
deleted
inserted
replaced
17 # |
17 # |
18 # Python API for Raptor. External code should interact with Raptor via this |
18 # Python API for Raptor. External code should interact with Raptor via this |
19 # module only, as it is the only programatic interface considered public. The |
19 # module only, as it is the only programatic interface considered public. The |
20 # command line --query option is also implemented using this module. |
20 # command line --query option is also implemented using this module. |
21 |
21 |
|
22 # constants |
|
23 ALL = 1 |
|
24 |
|
25 # objects |
|
26 |
22 class Reply(object): |
27 class Reply(object): |
23 """object to return values from API calls. |
28 """object to return values from API calls. |
24 """ |
29 """ |
25 def __init__(self, text=""): |
30 def __init__(self, text=""): |
26 self.text = text |
31 self.text = text |
101 def stringquery(self, query): |
106 def stringquery(self, query): |
102 """turn a string into an API call and execute it. |
107 """turn a string into an API call and execute it. |
103 |
108 |
104 This is a convenience method for "lazy" callers. |
109 This is a convenience method for "lazy" callers. |
105 |
110 |
106 The return value is also converted into a string. |
111 The return value is also converted into a well-formed XML string. |
107 """ |
112 """ |
108 |
113 |
109 if query == "aliases": |
114 if query == "aliases": |
110 aliases = self.getaliases() |
115 aliases = self.getaliases() |
111 return "".join(map(str, aliases)).strip() |
116 return "".join(map(str, aliases)).strip() |
126 |
131 |
127 def getaliases(self, type=""): |
132 def getaliases(self, type=""): |
128 """extract all aliases of a given type. |
133 """extract all aliases of a given type. |
129 |
134 |
130 the default type is "". |
135 the default type is "". |
131 to get all aliases pass type=None |
136 to get all aliases pass type=ALL |
132 """ |
137 """ |
133 aliases = [] |
138 aliases = [] |
134 |
139 |
135 for a in self.__raptor.cache.aliases.values(): |
140 for a in self.__raptor.cache.aliases.values(): |
136 if a.type == type or type == None: |
141 if type == ALL or a.type == type: |
137 # copy the members we want to expose |
142 # copy the members we want to expose |
138 aliases.append( Alias(a.name, a.meaning) ) |
143 aliases.append( Alias(a.name, a.meaning) ) |
139 |
144 |
140 return aliases |
145 return aliases |
141 |
146 |