code: def dialectfromstring(s):
      
      try:
          AST = compiler.parse(s)
      except SyntaxError:
          return
      else:
          try:
              if (len(AST.getChildren()) > 1):
                  ST = AST.getChildren()[1]
                  if isinstance(ST, Stmt):
                      if isinstance(ST.getChildren()[0], Discard):
                          d = ST.getChildren()[0].asList()[0]
          except (TypeError,AttributeError):
              pass
          else:
              if (isinstance(d,Dict) and (len(d.items) > 0)):
                  if all([isctype(i[0], str) for i in d.items]):
                      testd = csv.Sniffer().sniff('a,b,c')
                      if all([n.value in dir(testd) and 
                          isctype(v, type(getattr(testd, n.value))) for (n,v) in 
                                                                        d.items]):
                          D = eval(s)
                          for n in D.keys():
                              setattr(testd, n, D[n])
                          return testd
docs: 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.