소스 검색

Support use without mmap module (e.g. ironpython).

Jelmer Vernooij 14 년 전
부모
커밋
44a9af8734
1개의 변경된 파일14개의 추가작업 그리고 8개의 파일을 삭제
  1. 14 8
      dulwich/pack.py

+ 14 - 8
dulwich/pack.py

@@ -47,7 +47,12 @@ from itertools import (
     imap,
     izip,
     )
-import mmap
+try:
+    import mmap
+except ImportError:
+    has_mmap = False
+else:
+    has_mmap = True
 import os
 import struct
 try:
@@ -163,13 +168,14 @@ def _load_file_contents(f, size=None):
         fd = f.fileno()
         if size is None:
             size = os.fstat(fd).st_size
-        try:
-            contents = mmap.mmap(fd, size, access=mmap.ACCESS_READ)
-        except mmap.error:
-            # Perhaps a socket?
-            pass
-        else:
-            return contents, size
+        if has_mmap:
+            try:
+                contents = mmap.mmap(fd, size, access=mmap.ACCESS_READ)
+            except mmap.error:
+                # Perhaps a socket?
+                pass
+            else:
+                return contents, size
     contents = f.read()
     size = len(contents)
     return contents, size