Commits

Doug Hellmann committed a0b337d

backwards compatibility changes

  • Participants
  • Parent commits 299ef1c
  • Tags 1.2

Comments (0)

Files changed (4)

+2011-02-19  Doug Hellmann  <dhellmann@racemi.com>
+
+	* rst2marsedit/main.py: Change use of "with" to make the script
+	work on older versions of Python.
+
 2010-06-17  Doug Hellmann  <doug.hellmann@gmail.com>
 
 	* rst2marsedit/SendToMarsEdit.applescript: Read the file as UTF-8 encoded text.
 Release History
 ===============
 
+1.2
+
+ - Change implementation to make the script work with versions of
+   Python that don't support "with".
+
 1.1
 
  - Fix Unicode handling in the AppleScript used to communicate with MarsEdit.

File rst2marsedit/main.py

     title = ''.join(unicode(c) for c in soup.find('title').contents)
 
     # Save the body to a file so the AppleScript can read it.
-    with tempfile.NamedTemporaryFile(mode='w', suffix='.html') as f:
+    f = tempfile.NamedTemporaryFile(mode='w', suffix='.html')
+    try:
         out = codecs.getwriter('utf-8')(f)
         out.write(content)
         f.flush()
 
         # Build the AppleScript file from the template
-        with tempfile.NamedTemporaryFile(mode='w', suffix='.applescript') as script_file:
+        script_file = tempfile.NamedTemporaryFile(mode='w', suffix='.applescript')
+        try:
             script_template = string.Template(
                 pkg_resources.resource_string(__name__, SCRIPT_TEMPLATE_NAME)
                 )
             # Open a new blog entry in MarsEdit
             mars = subprocess.Popen(['osascript', script_file.name, f.name, title])
             mars.communicate()
+        finally:
+            script_file.close()
+    finally:
+        f.close()
     return
 
 
 #!/usr/bin/env python
 
 PROJECT = 'rst2marsedit'
-VERSION = '1.1'
+VERSION = '1.2'
 
 # Bootstrap installation of Distribute
 import distribute_setup
                     'Topic :: Text Processing :: Markup :: HTML',
                     ],
 
-    platforms = ('Any',),
+    platforms = ['Any'],
 
     provides=['rst2marsedit',
               ],