def dialectfromstring(s):
try:<EOL><INDENT>AST = compiler.parse(s)<EOL><DEDENT>except SyntaxError:<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>if (len(AST.getChildren()) > <NUM_LIT:1>):<EOL><INDENT>ST = AST.getChildren()[<NUM_LIT:1>]<EOL>if isinstance(ST, Stmt):<EOL><INDENT>if isinstance(ST.getChildren()[<NUM_LIT:0>], Discard):<EOL><INDENT>d = ST.getChildren()[<NUM_LIT:0>].asList()[<NUM_LIT:0>]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except (TypeError,AttributeError):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>if (isinstance(d,Dict) and (len(d.items) > <NUM_LIT:0>)):<EOL><INDENT>if all([isctype(i[<NUM_LIT:0>], str) for i in d.items]):<EOL><INDENT>testd = csv.Sniffer().sniff('<STR_LIT>')<EOL>if all([n.value in dir(testd) and <EOL>isctype(v, type(getattr(testd, n.value))) for (n,v) in <EOL>d.items]):<EOL><INDENT>D = eval(s)<EOL>for n in list(D.keys()):<EOL><INDENT>setattr(testd, n, D[n])<EOL><DEDENT>return testd<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Attempts to convert a string representation of a CSV 
dialect (as would be read from a file header, for instance) 
into an actual csv.Dialect object.