code: def read_graph_from_string(txt):
      
      if not txt.startswith('{'):
          return read_dot(txt)  # standard dot format
  
      def conv(value):
          if isinstance(value, basestring):
              return '"' + value + '"'
          else:
              return value
  
      # our compacted format
      doc = literal_eval(txt)
      g = digraph()
  
      for attrs, values in doc.get("nodes", []):
          attrs = [(k, conv(v)) for k, v in attrs]
  
          for value in values:
              if isinstance(value, basestring):
                  node_name = value
                  attrs_ = attrs
              else:
                  node_name, label = value
                  attrs_ = attrs + [("label", conv(label))]
  
              g.add_node(node_name, attrs=attrs_)
  
      for attrs, values in doc.get("edges", []):
          attrs_ = [(k, conv(v)) for k, v in attrs]
  
          for value in values:
              if len(value) == 3:
                  edge = value[:2]
                  label = value[-1]
              else:
                  edge = value
                  label = ''
  
              g.add_edge(edge, label=label, attrs=attrs_)
  
      return g
docs: Read a graph from a string, either in dot format, or our own
      compressed format.
  
      Returns:
          `pygraph.digraph`: Graph object.