ó ŸÃÒYc@sÈddlZddlmZddlmZddlZddlmZddlm Z dddgZ d „Z d „Z d „Z ed „ƒZe ed Vss.gzs.bz2s.gziptrcst‡‡fd†ƒ}|S(szDecorator to ensure clean opening and closing of files. Parameters ---------- path_arg : int Location of the path argument in args. Even if the argument is a named positional argument (with a default value), you must specify its index as a positional argument. mode : str String for opening mode. Returns ------- _open_file : function Function which cleanly executes the io. Examples -------- Decorate functions like this:: @open_file(0,'r') def read_function(pathname): pass @open_file(1,'w') def write_function(G,pathname): pass @open_file(1,'w') def write_function(G, pathname='graph.dot') pass @open_file('path', 'w+') def another_function(arg, **kwargs): path = kwargs['path'] pass c sUy|ˆ}Wn|tk rgy|ˆ}Wn/tk r]d}tj|jˆƒƒ‚q“Xt}n,tk rŒd}tj|ƒ‚nXt}t|ƒrÎt |ƒd}t ||dˆƒ}t}n*t |dƒrì|}t}n |}t}|r|} ||ˆs"    9      Ž