Merge "astobj2: Create function to copy weak proxied objects from container."
[asterisk/asterisk.git] / rest-api-templates / transform.py
index c3a0300..88f7d2e 100644 (file)
@@ -21,6 +21,11 @@ import os.path
 import pystache
 import shutil
 import tempfile
+import sys
+
+if sys.version_info[0] == 3:
+    def unicode(v):
+        return str(v)
 
 
 class Transform(object):
@@ -52,10 +57,10 @@ class Transform(object):
         dest_exists = os.path.exists(dest_file)
         if dest_exists and not self.overwrite:
             return
-        with tempfile.NamedTemporaryFile() as out:
+        with tempfile.NamedTemporaryFile(mode='w+') as out:
             out.write(renderer.render(self.template, model))
             out.flush()
 
             if not dest_exists or not filecmp.cmp(out.name, dest_file):
-                print "Writing %s" % dest_file
+                print("Writing %s" % dest_file)
                 shutil.copyfile(out.name, dest_file)