branch : pmacs2
This commit is contained in:
moculus 2008-11-09 22:28:25 +00:00
parent 39077092c0
commit 9d38d5d45e
1 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import codecs, datetime, grp, hashlib, os, pwd, re, shutil, stat, string import codecs, datetime, grp, os, pwd, re, shutil, stat, string
import fcntl, select, pty, threading import fcntl, select, pty, threading
import aes, dirutil, regex, highlight, lex, term import aes, dirutil, regex, highlight, lex, term
from point import Point from point import Point
@ -12,6 +12,15 @@ ACT_UNDO = 1
ACT_REDO = 2 ACT_REDO = 2
STACK_LIMIT = 1024 STACK_LIMIT = 1024
def hasher(data):
try:
import hashlib
m = hashlib.md5(data)
except:
import md5
m = md5.new(data)
return m
class ReadOnlyError(Exception): class ReadOnlyError(Exception):
pass pass
@ -582,7 +591,8 @@ class FileBuffer(Buffer):
return os.path.exists(self.path) return os.path.exists(self.path)
def store_checksum(self, data): def store_checksum(self, data):
#self.checksum = md5.new(data) #self.checksum = md5.new(data)
self.checksum = hashlib.md5(data) #self.checksum = hashlib.md5(data)
self.checksum = hasher(data)
def read(self): def read(self):
if self.path_exists(): if self.path_exists():
f = self._open_file_r() f = self._open_file_r()
@ -620,7 +630,8 @@ class FileBuffer(Buffer):
data = f.read() data = f.read()
f.close() f.close()
#m = md5.new(data) #m = md5.new(data)
m = hashlib.md5(data) #m = hashlib.md5(data)
m = hasher(data)
return self.checksum.digest() != m.digest() return self.checksum.digest() != m.digest()
def save(self, force=False): def save(self, force=False):
if self.readonly(): if self.readonly():