def _decompose_pattern(self, pattern):
sep = '<STR_LIT>'<EOL>float_codes = ['<STR_LIT:e>','<STR_LIT:E>','<STR_LIT:f>', '<STR_LIT:F>','<STR_LIT:g>', '<STR_LIT>', '<STR_LIT:n>']<EOL>typecodes = dict([(k,float) for k in float_codes]<EOL>+ [('<STR_LIT:b>',bin), ('<STR_LIT:d>',int), ('<STR_LIT:o>',oct), ('<STR_LIT:x>',hex)])<EOL>parse = list(string.Formatter().parse(pattern))<EOL>text, fields, codes, _ = zip(*parse)<EOL>types = []<EOL>for (field, code) in zip(fields, codes):<EOL><INDENT>if code in ['<STR_LIT>', None]: continue<EOL>constructor =  typecodes.get(code[-<NUM_LIT:1>], None)<EOL>if constructor: types += [(field, constructor)]<EOL><DEDENT>stars =  ['<STR_LIT>' if not f else '<STR_LIT:*>' for f in fields]<EOL>globpat = '<STR_LIT>'.join(text+star for (text,star) in zip(text,stars))<EOL>refields = ['<STR_LIT>' if not f else sep+('<STR_LIT>'% f)+sep for f in fields]<EOL>parts = '<STR_LIT>'.join(text+group for (text,group) in zip(text, refields)).split(sep)<EOL>for i in range(<NUM_LIT:0>, len(parts), <NUM_LIT:2>): parts[i] = re.escape(parts[i])<EOL>regexp_pattern = '<STR_LIT>'.join(parts).replace('<STR_LIT>','<STR_LIT>')<EOL>fields = list(f for f in fields if f)<EOL>return globpat, regexp_pattern , fields, dict(types)<EOL>
Given a path pattern with format declaration, generates a
four-tuple (glob_pattern, regexp pattern, fields, type map)