@@ -101,8 +101,17 @@ def put_and(l):
101101 return l [0 ]
102102 return ', ' .join (l [:- 1 ]) + ' and ' + l [- 1 ]
103103
104+ # ['foo', ...] with e == '*' -> ['*foo*', ...]
105+ def enclose_in (e , l ):
106+ return ['%s%s%s' % (e , s , e ) for s in l ]
107+
104108def md_italic (l ):
105- return ['*%s*' % s for s in l ]
109+ return enclose_in ('*' , l )
110+
111+ def singular (s ):
112+ if s [- 1 ] == 's' :
113+ return s [:- 1 ]
114+ return s
106115
107116def split_camelcase_s (s ):
108117 s1 = re .sub ('(.)([A-Z][a-z]+)' , r'\1 \2' , s )
@@ -226,44 +235,6 @@ def schema_markers(s, c):
226235# -------------------------
227236## @name Activity Utilities
228237# @{
229-
230- # Returns (A, B) where
231- # A: { SchemaTypeName -> { fqan -> ['request'|'response', ...]}
232- # B: { fqan -> activity_method_data }
233- # fqan = fully qualified activity name
234- def build_activity_mappings (activities ):
235- res = dict ()
236- fqan = dict ()
237- for an , a in activities .iteritems ():
238- if 'methods' not in a :
239- continue
240- for mn , m in a .methods .iteritems ():
241- assert m .id not in fqan
242- fqan [m .id ] = m
243- for in_out_type_name in IO_TYPES :
244- t = m .get (in_out_type_name , None )
245- if t is None :
246- continue
247- tn = to_rust_type (None , None , t , allow_optionals = False )
248- info = res .setdefault (tn , dict ())
249- io_info = info .setdefault (m .id , [])
250- io_info .append (in_out_type_name )
251- # end for each io type
252-
253- # handle delete/getrating/(possibly others)
254- # delete: has no response or request
255- # getrating: response is a 'SomethingResult', which is still related to activities name
256- # the latter is used to deduce the resource name
257- an , _ = activity_split (m .id )
258- tn = activity_name_to_type_name (an )
259- info = res .setdefault (tn , dict ())
260- if m .id not in info :
261- info .setdefault (m .id , [])
262- # end handle other cases
263- # end for each method
264- # end for each activity
265- return res , fqan
266-
267238# return (name, method)
268239def activity_split (fqan ):
269240 t = fqan .split ('.' )
@@ -281,12 +252,54 @@ def iter_acitivities(c):
281252## -- End Activity Utilities -- @}
282253
283254
284- Context = collections .namedtuple ('Context' , ['sta_map' , 'fqan_map' ])
255+ Context = collections .namedtuple ('Context' , ['sta_map' , 'fqan_map' , 'rta_map' ])
285256
286257# return a newly build context from the given data
287258def new_context (resources ):
259+ # Returns (A, B) where
260+ # A: { SchemaTypeName -> { fqan -> ['request'|'response', ...]}
261+ # B: { fqan -> activity_method_data }
262+ # fqan = fully qualified activity name
263+ def build_activity_mappings (activities ):
264+ res = dict ()
265+ fqan = dict ()
266+ for an , a in activities .iteritems ():
267+ if 'methods' not in a :
268+ continue
269+ for mn , m in a .methods .iteritems ():
270+ assert m .id not in fqan
271+ fqan [m .id ] = m
272+ for in_out_type_name in IO_TYPES :
273+ t = m .get (in_out_type_name , None )
274+ if t is None :
275+ continue
276+ tn = to_rust_type (None , None , t , allow_optionals = False )
277+ info = res .setdefault (tn , dict ())
278+ io_info = info .setdefault (m .id , [])
279+ io_info .append (in_out_type_name )
280+ # end for each io type
281+
282+ # handle delete/getrating/(possibly others)
283+ # delete: has no response or request
284+ # getrating: response is a 'SomethingResult', which is still related to activities name
285+ # the latter is used to deduce the resource name
286+ an , _ = activity_split (m .id )
287+ tn = activity_name_to_type_name (an )
288+ info = res .setdefault (tn , dict ())
289+ if m .id not in info :
290+ info .setdefault (m .id , [])
291+ # end handle other cases
292+ # end for each method
293+ # end for each activity
294+ return res , fqan
295+ # end utility
296+
288297 sta_map , fqan_map = build_activity_mappings (resources )
289- return Context (sta_map , fqan_map )
298+ rta_map = dict ()
299+ for an in fqan_map :
300+ resource , activity = activity_split (an )
301+ rta_map .setdefault (resource , list ()).append (activity )
302+ return Context (sta_map , fqan_map , rta_map )
290303
291304# Expects v to be 'v\d+', throws otherwise
292305def to_api_version (v ):
@@ -296,3 +309,7 @@ def to_api_version(v):
296309# build a full library name (non-canonical)
297310def library_name (name , version ):
298311 return name + to_api_version (version )
312+
313+ # return type name of a resource builder, from a resource name
314+ def mb_type (r ):
315+ return "%sMethodBuilder" % canonical_type_name (r )
0 commit comments