Reimplemented rfc822 date parsing without using dateutil to get rid of
authorEd Bartosh <eduard.bartosh@intel.com>
Wed, 30 May 2012 06:02:55 +0000 (09:02 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Thu, 31 May 2012 07:30:05 +0000 (10:30 +0300)
dependency to dateutil

Change-Id: Ib0676db9bfa535b25f5c9f9a69e79c001013527f

debian/control
gbp/git/__init__.py
packaging/git-buildpackage.spec

index 6d434195475e04817ca32f0f78e0f101cc33e037..f1a275e6ac6a5e1f061062deddb7c516fd22791b 100644 (file)
@@ -3,7 +3,7 @@ Section: vcs
 Priority: optional
 Maintainer: Guido Günther <agx@sigxcpu.org>
 Build-Depends: debhelper (>= 7.0.50~), python (>> 2.6.6-3~),
- pychecker, gtk-doc-tools, sgml2x, docbook-utils, jade, python-dateutil, python-nose,
+ pychecker, gtk-doc-tools, sgml2x, docbook-utils, jade, python-nose,
  bash-completion, perl, python-epydoc, python-coverage, python-setuptools, python-rpm,
 # For the testsuite
  git, bzip2, unzip, pristine-tar
@@ -16,7 +16,7 @@ X-Python-Version: >= 2.6
 
 Package: git-buildpackage-common
 Architecture: all
-Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, git, python-dateutil
+Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, git
 Recommends: pristine-tar (>= 0.5)
 Suggests: python-notify, unzip
 Description: Suite to help with packaging in Git repositories
index cf15beb617b998e67da488938fbd8e61a05899e0..31c5a15ce29c8e211e0470d8c74752077f24a36f 100644 (file)
@@ -17,7 +17,8 @@
 """Accessing Git from python"""
 
 import calendar
-import dateutil.parser
+import datetime
+import rfc822
 
 from gbp.git.modifier import GitModifier
 from gbp.git.commit import GitCommit
@@ -27,6 +28,23 @@ from gbp.git.fastimport import FastImport
 from gbp.git.args import GitArgs
 
 
+class FixedOffset(datetime.tzinfo):
+    """Fixed offset in seconds east from UTC."""
+
+    ZERO = datetime.timedelta(0)
+
+    def __init__(self, offset):
+        datetime.tzinfo.__init__(self)
+        self._offset = datetime.timedelta(seconds=offset)
+
+    def utcoffset(self, dtime):
+        return self._offset + self.dst(dtime)
+
+    def dst(self, dtime):
+        assert dtime.tzinfo is self
+        return self.ZERO
+
+
 def rfc822_date_to_git(rfc822_date):
     """Parse a date in RFC822 format, and convert to a 'seconds tz' C{str}ing.
 
@@ -37,9 +55,10 @@ def rfc822_date_to_git(rfc822_date):
     >>> rfc822_date_to_git('Sat, 5 Apr 2008 17:01:32 +0200')
     '1207407692 +0200'
     """
-    d = dateutil.parser.parse(rfc822_date)
-    seconds = calendar.timegm(d.utctimetuple())
-    tz = d.strftime("%z")
-    return '%d %s' % (seconds, tz)
+    parsed = rfc822.parsedate_tz(rfc822_date)
+    date = datetime.datetime(*parsed[:6], tzinfo=FixedOffset(parsed[-1]))
+    seconds = calendar.timegm(date.utctimetuple())
+    tzone = date.strftime("%z")
+    return '%d %s' % (seconds, tzone)
 
 # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
index 21cc3c2e3f62c337065c89ef599e4a4189877a6b..dc3bd4b2a04eb1e2d8a8fd60fb636bfcade3b732 100644 (file)
@@ -29,7 +29,6 @@ Summary:    Common files for git-buildpackage debian and rpm tools
 Group:      Development/Tools/Building
 Requires:   git-core
 Requires:   python-base
-Requires:   python-dateutil
 
 %description common
 Common files and documentation, used by both git-buildpackage debian and rpm tools