Did I find the right examples for you? yes no Crawl my project Python Jobs
All Samples(5) | Call(5) | Derive(0) | Import(0)
Recover the ref-attr, all-inclusion or derive from if present. :returns: The results of parsing the given value string. This is a dict in the form: .. code-block:: python dict( found='refatt', 'all', 'derivefrom' or None,(more...)
def parse_value(value): """Recover the ref-attr, all-inclusion or derive from if present. :returns: The results of parsing the given value string. This is a dict in the form: .. code-block:: python dict( found='refatt', 'all', 'derivefrom' or None, reference='' or '', attribute='' or ' ', allfrom='' or ' ', derivefrom='' or 'derivefrom string recovered', ) """ returned = dict(found=None,reference='',attribute='',allfrom='') if type(value) in types.StringTypes: # Only bother with strings, ignore everything else. #print "value to parse: '%s'." % value if value.strip() == '.*': # ignore empty .* inclusion return returned refatt_result = re.search(REFATT_RE, value) allinc_result = re.search(ALLINC_RE, value) derivefrom_result = re.search(DERIVEFROM_RE, value) if refatt_result: found = refatt_result.groupdict() #print "found: '%s'" % pprint.pformat(found)) #print "groups", refatt_result.groups()) returned['found'] = 'refatt' returned['reference'] = found.get('ref') returned['attribute'] = found.get('attr') if allinc_result: found = allinc_result.groupdict() #print("found: '%s'" % pprint.pformat(found)) #print("groups", allinc_result.groups()) returned['found'] = 'all' returned['allfrom'] = found.get('allfrom') if derivefrom_result: found = derivefrom_result.groupdict() #print("found: '%s'" % pprint.pformat(found)) #print("groups", derivefrom_result.groups()) returned['found'] = 'derivefrom' returned['derivefrom'] = found.get('derivefrom') return returned
for value in ignore: correct = dict(found=None,reference='',attribute='',allfrom='') result = utils.parse_value(value) self.assertEquals(result, correct) # Now check the recovery of valid reference-attributes: value = 'abc.$.efg' correct = dict(found='refatt',reference='abc',attribute='efg',allfrom='') result = utils.parse_value(value)
value = 'settings.host.$.timeout' correct = dict(found='refatt',reference='settings.host',attribute='timeout',allfrom='') result = utils.parse_value(value) self.assertEquals(result, correct) # Now try all inclusion entries: # value = 'settings.host.*' correct = dict(found='all',reference='',attribute='',allfrom='settings.host') result = utils.parse_value(value)
value = 'abc.*' correct = dict(found='all',reference='',attribute='',allfrom='abc') result = utils.parse_value(value) self.assertEquals(result, correct)