瀏覽代碼

More docstrings.

Jelmer Vernooij 16 年之前
父節點
當前提交
a11f0f1f40
共有 3 個文件被更改,包括 25 次插入0 次删除
  1. 14 0
      dulwich/index.py
  2. 4 0
      dulwich/object_store.py
  3. 7 0
      dulwich/server.py

+ 14 - 0
dulwich/index.py

@@ -24,10 +24,12 @@ from dulwich.objects import sha_to_hex, hex_to_sha
 
 
 def read_cache_time(f):
+    """Read a cache time."""
     return struct.unpack(">LL", f.read(8))
 
 
 def write_cache_time(f, t):
+    """Write a cache time."""
     if isinstance(t, int):
         t = (t, 0)
     f.write(struct.pack(">LL", *t))
@@ -119,13 +121,19 @@ def write_index_dict(f, entries):
 
 
 class Index(object):
+    """A Git Index file."""
 
     def __init__(self, filename):
+        """Open an index file.
+        
+        :param filename: Path to the index file
+        """
         self._filename = filename
         self.clear()
         self.read()
 
     def write(self):
+        """Write current contents of index to disk."""
         f = open(self._filename, 'w')
         try:
             write_index_dict(f, self._byname)
@@ -133,6 +141,7 @@ class Index(object):
             f.close()
 
     def read(self):
+        """Read current contents of index from disk."""
         f = open(self._filename, 'r')
         try:
             for x in read_index(f):
@@ -141,18 +150,23 @@ class Index(object):
             f.close()
 
     def __len__(self):
+        """Number of entries in this index file."""
         return len(self._byname)
 
     def __getitem__(self, name):
+        """Retrieve entry by relative path."""
         return self._byname[name]
 
     def __iter__(self):
+        """Iterate over the paths in this index."""
         return iter(self._byname)
 
     def get_sha1(self, path):
+        """Return the (git object) SHA1 for the object at a path."""
         return self[path][-2]
 
     def clear(self):
+        """Remove all contents from this index."""
         self._byname = {}
 
     def __setitem__(self, name, x):

+ 4 - 0
dulwich/object_store.py

@@ -16,6 +16,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
+
+"""Git object store interfaces and implementation."""
+
+
 import itertools
 import os
 import tempfile

+ 7 - 0
dulwich/server.py

@@ -16,6 +16,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
+
+"""Git smart network protocol server implementation."""
+
+
 import SocketServer
 import tempfile
 
@@ -88,6 +92,7 @@ class GitBackend(Backend):
 
 
 class Handler(object):
+    """Smart protocol command handler base class."""
 
     def __init__(self, backend, read, write):
         self.backend = backend
@@ -98,6 +103,7 @@ class Handler(object):
 
 
 class UploadPackHandler(Handler):
+    """Protocol handler for uploading a pack to the server."""
 
     def default_capabilities(self):
         return ("multi_ack", "side-band-64k", "thin-pack", "ofs-delta")
@@ -170,6 +176,7 @@ class UploadPackHandler(Handler):
 
 
 class ReceivePackHandler(Handler):
+    """Protocol handler for downloading a pack to the client."""
 
     def default_capabilities(self):
         return ("report-status", "delete-refs")