Commits

Ali Gholami Rudi  committed 958858c

Only compressing history and objectdb if gzip is available

  • Participants
  • Parent commits 3f44aaf

Comments (0)

Files changed (2)

File rope/base/history.py

             self.max_undos = maxundos
         self.compress = project.get_prefs().get('compress_history', False)
         if self.compress:
-            import gzip
-            self.opener = gzip.open
-        else:
+            try:
+                import gzip
+                self.opener = gzip.open
+            except ImportError:
+                self.compress = False
+        if not self.compress:
             self.opener = open
         self._load_history()
         self.current_change = None
                 self._import_old_files()
             if not self.history_file.exists():
                 return
-            input_file = self.opener(self.history_file.real_path)
+            input_file = self.opener(self.history_file.real_path, 'rb')
             to_change = change.DataToChange(self.history_file.project)
             for data in pickle.load(input_file):
                 self._undo_list.append(to_change(data))
     def sync(self):
         if self.history_file is not None:
             self._remove_extra_items()
-            output_file = self.opener(self.history_file.real_path, 'w')
+            output_file = self.opener(self.history_file.real_path, 'wb')
             to_data = change.ChangeToData()
             pickle.dump([to_data(change_) for change_ in self.undo_list],
                         output_file, 2)

File rope/base/oi/memorydb.py

         self.files = self
         self.compress = project.prefs.get('compress_objectdb', False)
         if self.compress:
-            import gzip
-            self.opener = gzip.open
-        else:
+            try:
+                import gzip
+                self.opener = gzip.open
+            except ImportError:
+                self.compress = False
+        if not self.compress:
             self.opener = open
         self._load_files()