فهرست منبع

Fix formatting issues.

Jelmer Vernooij 16 سال پیش
والد
کامیت
e82ea2af53

+ 1 - 0
dulwich/__init__.py

@@ -1,5 +1,6 @@
 # __init__.py -- The git module of dulwich
 # __init__.py -- The git module of dulwich
 # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
 # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
+# Copyright (C) 2008 Jelmer Vernooji <jelmer@samba.org>
 # 
 # 
 # This program is free software; you can redistribute it and/or
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # modify it under the terms of the GNU General Public License

+ 9 - 2
dulwich/client.py

@@ -20,8 +20,15 @@ import os
 import select
 import select
 import socket
 import socket
 import subprocess
 import subprocess
-from dulwich.protocol import Protocol, TCP_GIT_PORT, extract_capabilities
-from dulwich.pack import write_pack_data
+
+from dulwich.protocol import (
+    Protocol,
+    TCP_GIT_PORT,
+    extract_capabilities,
+    )
+from dulwich.pack import (
+    write_pack_data,
+    )
 
 
 class SimpleFetchGraphWalker(object):
 class SimpleFetchGraphWalker(object):
 
 

+ 6 - 0
dulwich/errors.py

@@ -16,6 +16,8 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
+"""Dulwich-related exception classes and utility functions."""
+
 class WrongObjectException(Exception):
 class WrongObjectException(Exception):
     """Baseclass for all the _ is not a _ exceptions on objects.
     """Baseclass for all the _ is not a _ exceptions on objects.
   
   
@@ -29,21 +31,25 @@ class WrongObjectException(Exception):
         string = "%s is not a %s" % (sha, self._type)
         string = "%s is not a %s" % (sha, self._type)
         Exception.__init__(self, string)
         Exception.__init__(self, string)
 
 
+
 class NotCommitError(WrongObjectException):
 class NotCommitError(WrongObjectException):
     """Indicates that the sha requested does not point to a commit."""
     """Indicates that the sha requested does not point to a commit."""
   
   
     _type = 'commit'
     _type = 'commit'
 
 
+
 class NotTreeError(WrongObjectException):
 class NotTreeError(WrongObjectException):
     """Indicates that the sha requested does not point to a tree."""
     """Indicates that the sha requested does not point to a tree."""
   
   
     _type = 'tree'
     _type = 'tree'
 
 
+
 class NotBlobError(WrongObjectException):
 class NotBlobError(WrongObjectException):
     """Indicates that the sha requested does not point to a blob."""
     """Indicates that the sha requested does not point to a blob."""
   
   
     _type = 'blob'
     _type = 'blob'
 
 
+
 class MissingCommitError(Exception):
 class MissingCommitError(Exception):
     """Indicates that a commit was not found in the repository"""
     """Indicates that a commit was not found in the repository"""
   
   

+ 2 - 0
dulwich/index.py

@@ -23,9 +23,11 @@ import struct
 def read_cache_time(f):
 def read_cache_time(f):
     return struct.unpack(">LL", f.read(8))
     return struct.unpack(">LL", f.read(8))
 
 
+
 def write_cache_time(f, t):
 def write_cache_time(f, t):
     f.write(struct.pack(">LL", *t))
     f.write(struct.pack(">LL", *t))
 
 
+
 def read_cache_entry(f):
 def read_cache_entry(f):
     beginoffset = f.tell()
     beginoffset = f.tell()
     ctime = read_cache_time(f)
     ctime = read_cache_time(f)

+ 5 - 5
dulwich/misc.py

@@ -15,11 +15,11 @@
 # along with this program; if not, write to the Free Software
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
-'''Misc utilities to work with python2.4.
+"""Misc utilities to work with python2.4.
 
 
 These utilities can all be deleted when dulwich decides it wants to stop
 These utilities can all be deleted when dulwich decides it wants to stop
 support for python 2.4.
 support for python 2.4.
-'''
+"""
 try:
 try:
     import hashlib
     import hashlib
 except ImportError:
 except ImportError:
@@ -28,7 +28,7 @@ import struct
 
 
 
 
 class defaultdict(dict):
 class defaultdict(dict):
-    '''A python 2.4 equivalent of collections.defaultdict.'''
+    """A python 2.4 equivalent of collections.defaultdict."""
 
 
     def __init__(self, default_factory=None, *a, **kw):
     def __init__(self, default_factory=None, *a, **kw):
         if (default_factory is not None and
         if (default_factory is not None and
@@ -72,7 +72,7 @@ class defaultdict(dict):
 
 
 
 
 def make_sha(source=''):
 def make_sha(source=''):
-    '''A python2.4 workaround for the sha/hashlib module fiasco.'''
+    """A python2.4 workaround for the sha/hashlib module fiasco."""
     try:
     try:
         return hashlib.sha1(source)
         return hashlib.sha1(source)
     except NameError:
     except NameError:
@@ -81,7 +81,7 @@ def make_sha(source=''):
 
 
 
 
 def unpack_from(fmt, buf, offset=0):
 def unpack_from(fmt, buf, offset=0):
-    '''A python2.4 workaround for struct missing unpack_from.'''
+    """A python2.4 workaround for struct missing unpack_from."""
     try:
     try:
         return struct.unpack_from(fmt, buf, offset)
         return struct.unpack_from(fmt, buf, offset)
     except AttributeError:
     except AttributeError:

+ 14 - 14
dulwich/object_store.py

@@ -16,24 +16,24 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
-from dulwich.objects import (
-        hex_to_sha,
-        sha_to_hex,
-        ShaFile,
-        )
-from dulwich.pack import (
-        iter_sha1, 
-        load_packs, 
-        write_pack,
-        write_pack_data,
-        write_pack_index_v2,
-        PackData, 
-        )
-
 import os
 import os
 import tempfile
 import tempfile
 import urllib2
 import urllib2
 
 
+from dulwich.objects import (
+    hex_to_sha,
+    sha_to_hex,
+    ShaFile,
+    )
+from dulwich.pack import (
+    iter_sha1, 
+    load_packs, 
+    write_pack,
+    write_pack_data,
+    write_pack_index_v2,
+    PackData, 
+    )
+
 PACKDIR = 'pack'
 PACKDIR = 'pack'
 
 
 class ObjectStore(object):
 class ObjectStore(object):

+ 5 - 4
dulwich/objects.py

@@ -25,10 +25,11 @@ import os
 import sha
 import sha
 import zlib
 import zlib
 
 
-from errors import (NotCommitError,
-                    NotTreeError,
-                    NotBlobError,
-                    )
+from dulwich.errors import (
+    NotBlobError,
+    NotCommitError,
+    NotTreeError,
+    )
 
 
 BLOB_ID = "blob"
 BLOB_ID = "blob"
 TAG_ID = "tag"
 TAG_ID = "tag"

+ 9 - 8
dulwich/pack.py

@@ -42,18 +42,18 @@ import struct
 try:
 try:
     from struct import unpack_from
     from struct import unpack_from
 except ImportError:
 except ImportError:
-    from misc import unpack_from
+    from dulwich.misc import unpack_from
 import sys
 import sys
 import zlib
 import zlib
 import difflib
 import difflib
 
 
-from objects import (
-        ShaFile,
-        hex_to_sha,
-        sha_to_hex,
-        )
-from errors import ApplyDeltaError
-from misc import make_sha
+from dulwich.objects import (
+    ShaFile,
+    hex_to_sha,
+    sha_to_hex,
+    )
+from dulwich.errors import ApplyDeltaError
+from dulwich.misc import make_sha
 
 
 supports_mmap_offset = (sys.version_info[0] >= 3 or
 supports_mmap_offset = (sys.version_info[0] >= 3 or
         (sys.version_info[0] == 2 and sys.version_info[1] >= 6))
         (sys.version_info[0] == 2 and sys.version_info[1] >= 6))
@@ -419,6 +419,7 @@ class PackData(object):
         return self._num_objects
         return self._num_objects
   
   
     def calculate_checksum(self):
     def calculate_checksum(self):
+        """Calculate the checksum for this pack."""
         f = open(self._filename, 'rb')
         f = open(self._filename, 'rb')
         try:
         try:
             map = simple_mmap(f, 0, self._size)
             map = simple_mmap(f, 0, self._size)

+ 13 - 1
dulwich/protocol.py

@@ -17,9 +17,15 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
-from errors import HangupException, GitProtocolError
+"""Generic functions for talking the git smart server protocol."""
+
 import socket
 import socket
 
 
+from dulwich.errors import (
+    HangupException,
+    GitProtocolError,
+    )
+
 TCP_GIT_PORT = 9418
 TCP_GIT_PORT = 9418
 
 
 class ProtocolFile(object):
 class ProtocolFile(object):
@@ -122,6 +128,12 @@ class Protocol(object):
 
 
 
 
 def extract_capabilities(text):
 def extract_capabilities(text):
+    """Extract a capabilities list from a string, if present.
+
+    :param text: String to extract from
+    :return: Tuple with text with capabilities removed and list of 
+        capabilities or None (if no capabilities were present.
+    """
     if not "\0" in text:
     if not "\0" in text:
         return text, None
         return text, None
     capabilities = text.split("\0")
     capabilities = text.split("\0")

+ 18 - 18
dulwich/repo.py

@@ -18,24 +18,24 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
-import os, stat
-
-from commit import Commit
-from errors import (
-        MissingCommitError, 
-        NotBlobError, 
-        NotCommitError, 
-        NotGitRepository,
-        NotTreeError, 
-        )
-from object_store import ObjectStore
-from objects import (
-        ShaFile,
-        Commit,
-        Tag,
-        Tree,
-        Blob,
-        )
+import os
+import stat
+
+from dulwich.errors import (
+    MissingCommitError, 
+    NotBlobError, 
+    NotCommitError, 
+    NotGitRepository,
+    NotTreeError, 
+    )
+from dulwich.object_store import ObjectStore
+from dulwich.objects import (
+    Blob,
+    Commit,
+    ShaFile,
+    Tag,
+    Tree,
+    )
 
 
 OBJECTDIR = 'objects'
 OBJECTDIR = 'objects'
 SYMREF = 'ref: '
 SYMREF = 'ref: '

+ 13 - 3
dulwich/server.py

@@ -17,11 +17,21 @@
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
 import SocketServer
 import SocketServer
-from dulwich.protocol import Protocol, ProtocolFile, TCP_GIT_PORT, extract_capabilities
-from dulwich.repo import Repo
-from dulwich.pack import write_pack_data
 import tempfile
 import tempfile
 
 
+from dulwich.protocol import (
+    Protocol,
+    ProtocolFile,
+    TCP_GIT_PORT,
+    extract_capabilities,
+    )
+from dulwich.repo import (
+    Repo,
+    )
+from dulwich.pack import (
+    write_pack_data,
+    )
+
 class Backend(object):
 class Backend(object):
 
 
     def get_refs(self):
     def get_refs(self):

+ 6 - 3
dulwich/tests/__init__.py

@@ -18,9 +18,12 @@
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
 import unittest
 import unittest
-import test_objects
-import test_repository
-import test_pack
+
+from dulwich.tests import (
+    test_objects,
+    test_repository,
+    test_pack,
+    )
 
 
 def test_suite():
 def test_suite():
     test_modules = [test_objects, test_repository, test_pack]
     test_modules = [test_objects, test_repository, test_pack]

+ 5 - 1
dulwich/tests/test_index.py

@@ -16,10 +16,14 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
-from dulwich.index import Index, write_index
 import os
 import os
 from unittest import TestCase
 from unittest import TestCase
 
 
+from dulwich.index import (
+    Index,
+    write_index,
+    )
+
 class IndexTestCase(TestCase):
 class IndexTestCase(TestCase):
 
 
     datadir = os.path.join(os.path.dirname(__file__), 'data/indexes')
     datadir = os.path.join(os.path.dirname(__file__), 'data/indexes')

+ 2 - 1
dulwich/tests/test_object_store.py

@@ -16,9 +16,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 # MA  02110-1301, USA.
 
 
-from dulwich.object_store import ObjectStore
 from unittest import TestCase
 from unittest import TestCase
 
 
+from dulwich.object_store import ObjectStore
+
 class ObjectStoreTests(TestCase):
 class ObjectStoreTests(TestCase):
 
 
     def test_pack_dir(self):
     def test_pack_dir(self):

+ 6 - 5
dulwich/tests/test_objects.py

@@ -20,11 +20,12 @@
 import os
 import os
 import unittest
 import unittest
 
 
-from dulwich.objects import (Blob,
-                         Tree,
-                         Commit,
-                         Tag
-                         )
+from dulwich.objects import (
+    Blob,
+    Tree,
+    Commit,
+    Tag,
+    )
 
 
 a_sha = '6f670c0fb53f9463760b7295fbb814e965fb20c8'
 a_sha = '6f670c0fb53f9463760b7295fbb814e965fb20c8'
 b_sha = '2969be3e8ee1c0222396a5611407e4769f14e54b'
 b_sha = '2969be3e8ee1c0222396a5611407e4769f14e54b'

+ 14 - 14
dulwich/tests/test_pack.py

@@ -21,21 +21,21 @@ import os
 import unittest
 import unittest
 
 
 from dulwich.objects import (
 from dulwich.objects import (
-        Tree,
-        )
+    Tree,
+    )
 from dulwich.pack import (
 from dulwich.pack import (
-        Pack,
-        PackIndex,
-        PackData,
-        hex_to_sha,
-        sha_to_hex,
-        write_pack_index_v1,
-        write_pack_index_v2,
-        write_pack,
-        apply_delta,
-        create_delta,
-        read_zlib,
-        )
+    Pack,
+    PackIndex,
+    PackData,
+    apply_delta,
+    create_delta,
+    hex_to_sha,
+    read_zlib,
+    sha_to_hex,
+    write_pack_index_v1,
+    write_pack_index_v2,
+    write_pack,
+    )
 
 
 pack1_sha = 'bc63ddad95e7321ee734ea11a7a62d314e0d7481'
 pack1_sha = 'bc63ddad95e7321ee734ea11a7a62d314e0d7481'