[Python-modules-commits] [isodate] 01/06: Imported Upstream version 0.5.1
Maximiliano Curia
maxy at moszumanska.debian.org
Mon Jan 19 14:33:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
maxy pushed a commit to branch master
in repository isodate.
commit a06e5d30a3f5cfb85ac1f194b7c76ac92d719c75
Author: Maximiliano Curia <maxy at gnuservers.com.ar>
Date: Mon Jan 19 14:55:09 2015 +0100
Imported Upstream version 0.5.1
---
CHANGES.txt | 9 +-
PKG-INFO | 29 +++-
README.rst | 17 ++-
setup.cfg | 2 +-
setup.py | 11 +-
src/isodate.egg-info/PKG-INFO | 29 +++-
src/isodate/__init__.py | 23 +++-
src/isodate/duration.py | 56 +++++---
src/isodate/isodates.py | 49 +++----
src/isodate/isodatetime.py | 23 ++--
src/isodate/isoduration.py | 31 +++--
src/isodate/isoerror.py | 5 +-
src/isodate/isostrf.py | 46 ++++---
src/isodate/isotime.py | 3 +-
src/isodate/isotzinfo.py | 23 ++--
src/isodate/tests/__init__.py | 1 +
src/isodate/tests/test_date.py | 23 ++--
src/isodate/tests/test_datetime.py | 20 ++-
src/isodate/tests/test_duration.py | 270 +++++++++++++++++++------------------
src/isodate/tests/test_pickle.py | 27 +++-
src/isodate/tests/test_strf.py | 17 ++-
src/isodate/tests/test_time.py | 24 ++--
src/isodate/tzinfo.py | 13 +-
23 files changed, 461 insertions(+), 290 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index ed60495..40ae79c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,10 +2,17 @@
CHANGES
=======
+0.5.1 (2014-11-07)
+------------------
+
+- fixed pickling of Duration objects
+- raise ISO8601Error when there is no 'T' separator in datetime strings (Adrian Coveney)
+
+
0.5.0 (2014-02-23)
------------------
-- ISO8601Error are subclasses of ValueError now
+- ISO8601Error are subclasses of ValueError now (Michael Hrivnak)
- improve compatibility across various python variants and versions
- raise exceptions when using fractional years and months in date
maths with durations
diff --git a/PKG-INFO b/PKG-INFO
index e487953..648e11f 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: isodate
-Version: 0.5.0
+Version: 0.5.1
Summary: An ISO 8601 date/time/duration parser and formater
Home-page: http://cheeseshop.python.org/pypi/isodate
Author: Gerhard Weis
@@ -10,7 +10,22 @@ Description:
ISO 8601 date/time parser
=========================
- .. image:: https://travis-ci.org/gweis/isodate.png?branch=master :target: https://travis-ci.org/gweis/isodate
+ .. image:: https://travis-ci.org/gweis/isodate.png?branch=master
+ :target: https://travis-ci.org/gweis/isodate
+ :alt: Travis-CI
+ .. image:: https://coveralls.io/repos/gweis/isodate/badge.png?branch=master
+ :target: https://coveralls.io/r/gweis/isodate?branch=master
+ :alt: Coveralls
+ .. image:: https://pypip.in/v/isodate/badge.png
+ :target: https://pypi.python.org/pypi/isodate/
+ :alt: Latest Version
+ .. image:: https://pypip.in/d/isodate/badge.png
+ :target: https://pypi.python.org/pypi//isodate/
+ :alt: Downloads
+ .. image:: https://pypip.in/license/isodate/badge.png
+ :target: https://pypi.python.org/pypi/isodate/
+ :alt: License
+
This module implements ISO 8601 date, time and duration parsing.
The implementation follows ISO8601:2004 standard, and implements only
@@ -114,10 +129,17 @@ Description:
CHANGES
=======
+ 0.5.1 (2014-11-07)
+ ------------------
+
+ - fixed pickling of Duration objects
+ - raise ISO8601Error when there is no 'T' separator in datetime strings (Adrian Coveney)
+
+
0.5.0 (2014-02-23)
------------------
- - ISO8601Error are subclasses of ValueError now
+ - ISO8601Error are subclasses of ValueError now (Michael Hrivnak)
- improve compatibility across various python variants and versions
- raise exceptions when using fractional years and months in date
maths with durations
@@ -237,6 +259,7 @@ Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/README.rst b/README.rst
index 81fb196..67a0e51 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,22 @@
ISO 8601 date/time parser
=========================
-.. image:: https://travis-ci.org/gweis/isodate.png?branch=master :target: https://travis-ci.org/gweis/isodate
+.. image:: https://travis-ci.org/gweis/isodate.png?branch=master
+ :target: https://travis-ci.org/gweis/isodate
+ :alt: Travis-CI
+.. image:: https://coveralls.io/repos/gweis/isodate/badge.png?branch=master
+ :target: https://coveralls.io/r/gweis/isodate?branch=master
+ :alt: Coveralls
+.. image:: https://pypip.in/v/isodate/badge.png
+ :target: https://pypi.python.org/pypi/isodate/
+ :alt: Latest Version
+.. image:: https://pypip.in/d/isodate/badge.png
+ :target: https://pypi.python.org/pypi//isodate/
+ :alt: Downloads
+.. image:: https://pypip.in/license/isodate/badge.png
+ :target: https://pypi.python.org/pypi/isodate/
+ :alt: License
+
This module implements ISO 8601 date, time and duration parsing.
The implementation follows ISO8601:2004 standard, and implements only
diff --git a/setup.cfg b/setup.cfg
index 72f9d44..6bc2ff3 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
[egg_info]
-tag_svn_revision = 0
tag_date = 0
tag_build =
+tag_svn_revision = 0
diff --git a/setup.py b/setup.py
index 7080a54..9ab0855 100644
--- a/setup.py
+++ b/setup.py
@@ -46,7 +46,7 @@ def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name='isodate',
- version='0.5.0',
+ version='0.5.1',
packages=['isodate', 'isodate.tests'],
package_dir={'': 'src'},
@@ -58,7 +58,7 @@ setup(name='isodate',
author_email='gerhard.weis at proclos.com',
description='An ISO 8601 date/time/duration parser and formater',
license='BSD',
- #keywords = '',
+ # keywords = '',
url='http://cheeseshop.python.org/pypi/isodate',
long_description=(read('README.rst') +
@@ -75,9 +75,10 @@ setup(name='isodate',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet',
- 'Topic :: Software Development :: Libraries :: Python Modules',
+ ('Topic :: Software Development :'
+ ': Libraries :: Python Modules'),
],
- **setupargs
- )
+ **setupargs)
diff --git a/src/isodate.egg-info/PKG-INFO b/src/isodate.egg-info/PKG-INFO
index e487953..648e11f 100644
--- a/src/isodate.egg-info/PKG-INFO
+++ b/src/isodate.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: isodate
-Version: 0.5.0
+Version: 0.5.1
Summary: An ISO 8601 date/time/duration parser and formater
Home-page: http://cheeseshop.python.org/pypi/isodate
Author: Gerhard Weis
@@ -10,7 +10,22 @@ Description:
ISO 8601 date/time parser
=========================
- .. image:: https://travis-ci.org/gweis/isodate.png?branch=master :target: https://travis-ci.org/gweis/isodate
+ .. image:: https://travis-ci.org/gweis/isodate.png?branch=master
+ :target: https://travis-ci.org/gweis/isodate
+ :alt: Travis-CI
+ .. image:: https://coveralls.io/repos/gweis/isodate/badge.png?branch=master
+ :target: https://coveralls.io/r/gweis/isodate?branch=master
+ :alt: Coveralls
+ .. image:: https://pypip.in/v/isodate/badge.png
+ :target: https://pypi.python.org/pypi/isodate/
+ :alt: Latest Version
+ .. image:: https://pypip.in/d/isodate/badge.png
+ :target: https://pypi.python.org/pypi//isodate/
+ :alt: Downloads
+ .. image:: https://pypip.in/license/isodate/badge.png
+ :target: https://pypi.python.org/pypi/isodate/
+ :alt: License
+
This module implements ISO 8601 date, time and duration parsing.
The implementation follows ISO8601:2004 standard, and implements only
@@ -114,10 +129,17 @@ Description:
CHANGES
=======
+ 0.5.1 (2014-11-07)
+ ------------------
+
+ - fixed pickling of Duration objects
+ - raise ISO8601Error when there is no 'T' separator in datetime strings (Adrian Coveney)
+
+
0.5.0 (2014-02-23)
------------------
- - ISO8601Error are subclasses of ValueError now
+ - ISO8601Error are subclasses of ValueError now (Michael Hrivnak)
- improve compatibility across various python variants and versions
- raise exceptions when using fractional years and months in date
maths with durations
@@ -237,6 +259,7 @@ Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/src/isodate/__init__.py b/src/isodate/__init__.py
index 091af0a..26604c2 100644
--- a/src/isodate/__init__.py
+++ b/src/isodate/__init__.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -28,12 +28,12 @@
Import all essential functions and constants to re-export them here for easy
access.
-This module contains also various pre-defined ISO 8601 format strings.
+This module contains also various pre-defined ISO 8601 format strings.
'''
from isodate.isodates import parse_date, date_isoformat
from isodate.isotime import parse_time, time_isoformat
from isodate.isodatetime import parse_datetime, datetime_isoformat
-from isodate.isoduration import parse_duration, duration_isoformat, Duration
+from isodate.isoduration import parse_duration, duration_isoformat
from isodate.isoerror import ISO8601Error
from isodate.isotzinfo import parse_tzinfo, tz_isoformat
from isodate.tzinfo import UTC, FixedOffset, LOCAL
@@ -53,3 +53,18 @@ from isodate.isostrf import DT_BAS_ORD_COMPLETE, DT_EXT_ORD_COMPLETE
from isodate.isostrf import DT_BAS_WEEK_COMPLETE, DT_EXT_WEEK_COMPLETE
from isodate.isostrf import D_DEFAULT, D_WEEK, D_ALT_EXT, D_ALT_BAS
from isodate.isostrf import D_ALT_BAS_ORD, D_ALT_EXT_ORD
+
+__all__ = (parse_date, date_isoformat, parse_time, time_isoformat,
+ parse_datetime, datetime_isoformat, parse_duration,
+ duration_isoformat, ISO8601Error, parse_tzinfo,
+ tz_isoformat, UTC, FixedOffset, LOCAL, Duration,
+ strftime, DATE_BAS_COMPLETE, DATE_BAS_ORD_COMPLETE,
+ DATE_BAS_WEEK, DATE_BAS_WEEK_COMPLETE, DATE_CENTURY,
+ DATE_EXT_COMPLETE, DATE_EXT_ORD_COMPLETE, DATE_EXT_WEEK,
+ DATE_EXT_WEEK_COMPLETE, DATE_MONTH, DATE_YEAR,
+ TIME_BAS_COMPLETE, TIME_BAS_MINUTE, TIME_EXT_COMPLETE,
+ TIME_EXT_MINUTE, TIME_HOUR, TZ_BAS, TZ_EXT, TZ_HOUR,
+ DT_BAS_COMPLETE, DT_EXT_COMPLETE, DT_BAS_ORD_COMPLETE,
+ DT_EXT_ORD_COMPLETE, DT_BAS_WEEK_COMPLETE,
+ DT_EXT_WEEK_COMPLETE, D_DEFAULT, D_WEEK, D_ALT_EXT,
+ D_ALT_BAS, D_ALT_BAS_ORD, D_ALT_EXT_ORD)
diff --git a/src/isodate/duration.py b/src/isodate/duration.py
index 4484919..b44faa8 100644
--- a/src/isodate/duration.py
+++ b/src/isodate/duration.py
@@ -40,13 +40,13 @@ def fquotmod(val, low, high):
'''
# assumes that all the maths is done with Decimals.
- # divmod for Decimal uses truncate instead of floor as builtin divmod, so we have
- # to do it manually here.
+ # divmod for Decimal uses truncate instead of floor as builtin
+ # divmod, so we have to do it manually here.
a, b = val - low, high - low
div = (a / b).to_integral(ROUND_FLOOR)
mod = a - div * b
# if we were not usig Decimal, it would look like this.
- #div, mod = divmod(val - low, high - low)
+ # div, mod = divmod(val - low, high - low)
mod += low
return int(div), mod
@@ -101,6 +101,12 @@ class Duration(object):
self.tdelta = timedelta(days, seconds, microseconds, milliseconds,
minutes, hours, weeks)
+ def __getstate__(self):
+ return self.__dict__
+
+ def __setstate__(self, state):
+ self.__dict__.update(state)
+
def __getattr__(self, name):
'''
Provide direct access to attributes of included timedelta instance.
@@ -124,9 +130,9 @@ class Duration(object):
Return a string suitable for repr(x) calls.
'''
return "%s.%s(%d, %d, %d, years=%d, months=%d)" % (
- self.__class__.__module__, self.__class__.__name__,
- self.tdelta.days, self.tdelta.seconds,
- self.tdelta.microseconds, self.years, self.months)
+ self.__class__.__module__, self.__class__.__name__,
+ self.tdelta.days, self.tdelta.seconds,
+ self.tdelta.microseconds, self.years, self.months)
def __neg__(self):
"""
@@ -153,8 +159,10 @@ class Duration(object):
newduration.tdelta = self.tdelta + other.tdelta
return newduration
if isinstance(other, (date, datetime)):
- if (not( float(self.years).is_integer() and float(self.months).is_integer())):
- raise ValueError('fractional years or months not supported for date calculations')
+ if (not(float(self.years).is_integer()
+ and float(self.months).is_integer())):
+ raise ValueError('fractional years or months not supported'
+ ' for date calculations')
newmonth = other.month + self.months
carry, newmonth = fquotmod(newmonth, 1, 13)
newyear = other.year + self.years + carry
@@ -177,8 +185,10 @@ class Duration(object):
newduration.tdelta = self.tdelta + other
return newduration
if isinstance(other, (date, datetime)):
- if (not( float(self.years).is_integer() and float(self.months).is_integer())):
- raise ValueError('fractional years or months not supported for date calculations')
+ if (not(float(self.years).is_integer()
+ and float(self.months).is_integer())):
+ raise ValueError('fractional years or months not supported'
+ ' for date calculations')
newmonth = other.month + self.months
carry, newmonth = fquotmod(newmonth, 1, 13)
newyear = other.year + self.years + carry
@@ -214,10 +224,12 @@ class Duration(object):
It is possible to subtract Duration objecs from date, datetime and
timedelta objects.
'''
- #print '__rsub__:', self, other
+ # print '__rsub__:', self, other
if isinstance(other, (date, datetime)):
- if (not( float(self.years).is_integer() and float(self.months).is_integer())):
- raise ValueError('fractional years or months not supported for date calculations')
+ if (not(float(self.years).is_integer()
+ and float(self.months).is_integer())):
+ raise ValueError('fractional years or months not supported'
+ ' for date calculations')
newmonth = other.month - self.months
carry, newmonth = fquotmod(newmonth, 1, 13)
newyear = other.year - self.years + carry
@@ -240,13 +252,14 @@ class Duration(object):
If the years, month part and the timedelta part are both equal, then
the two Durations are considered equal.
'''
- if (isinstance(other, timedelta) and
- self.years == 0 and self.months == 0):
+ if ((isinstance(other, timedelta) and
+ self.years == 0 and self.months == 0)):
return self.tdelta == other
if not isinstance(other, Duration):
return NotImplemented
- if ((self.years * 12 + self.months) ==
- (other.years * 12 + other.months) and self.tdelta == other.tdelta):
+ if (((self.years * 12 + self.months) ==
+ (other.years * 12 + other.months)
+ and self.tdelta == other.tdelta)):
return True
return False
@@ -255,12 +268,15 @@ class Duration(object):
If the years, month part or the timedelta part is not equal, then
the two Durations are considered not equal.
'''
- if isinstance(other, timedelta) and self.years == 0 and self.months == 0:
+ if ((isinstance(other, timedelta)
+ and self.years == 0
+ and self.months == 0)):
return self.tdelta != other
if not isinstance(other, Duration):
return NotImplemented
- if ((self.years * 12 + self.months) !=
- (other.years * 12 + other.months) or self.tdelta != other.tdelta):
+ if (((self.years * 12 + self.months) !=
+ (other.years * 12 + other.months)
+ or self.tdelta != other.tdelta)):
return True
return False
diff --git a/src/isodate/isodates.py b/src/isodate/isodates.py
index 8bafa20..37d42f8 100644
--- a/src/isodate/isodates.py
+++ b/src/isodate/isodates.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -42,18 +42,19 @@ DATE_REGEX_CACHE = {}
# A dictionary to cache pre-compiled regular expressions.
# A set of regular expressions is identified, by number of year digits allowed
# and whether a plus/minus sign is required or not. (This option is changeable
-# only for 4 digit years).
+# only for 4 digit years).
+
def build_date_regexps(yeardigits=4, expanded=False):
'''
Compile set of regular expressions to parse ISO dates. The expressions will
be created only if they are not already in REGEX_CACHE.
-
+
It is necessary to fix the number of year digits, else it is not possible
to automatically distinguish between various ISO date formats.
-
+
ISO 8601 allows more than 4 digit years, on prior agreement, but then a +/-
- sign is required (expanded format). To support +/- sign for 4 digit years,
+ sign is required (expanded format). To support +/- sign for 4 digit years,
the expanded parameter needs to be set to True.
'''
if yeardigits != 4:
@@ -73,7 +74,7 @@ def build_date_regexps(yeardigits=4, expanded=False):
% (sign, yeardigits)))
# YYYYMMDD or +- YYYYYYMMDD... basic date format
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
- r"(?P<month>[0-9]{2})(?P<day>[0-9]{2})"
+ r"(?P<month>[0-9]{2})(?P<day>[0-9]{2})"
% (sign, yeardigits)))
# 2. complete week dates:
# YYYY-Www-D or +-YYYYYY-Www-D ... extended week date
@@ -98,7 +99,7 @@ def build_date_regexps(yeardigits=4, expanded=False):
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-W(?P<week>[0-9]{2})"
% (sign, yeardigits)))
- # YYYYWww or +-YYYYYYWww ... basic reduced accuracy week date
+ # YYYYWww or +-YYYYYYWww ... basic reduced accuracy week date
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})W"
r"(?P<week>[0-9]{2})"
% (sign, yeardigits)))
@@ -120,18 +121,19 @@ def build_date_regexps(yeardigits=4, expanded=False):
DATE_REGEX_CACHE[(yeardigits, expanded)] = cache_entry
return DATE_REGEX_CACHE[(yeardigits, expanded)]
+
def parse_date(datestring, yeardigits=4, expanded=False):
'''
Parse an ISO 8601 date string into a datetime.date object.
-
+
As the datetime.date implementation is limited to dates starting from
0001-01-01, negative dates (BC) and year 0 can not be parsed by this
method.
-
+
For incomplete dates, this method chooses the first day for it. For
- instance if only a century is given, this method returns the 1st of
+ instance if only a century is given, this method returns the 1st of
January in year 1 of this century.
-
+
supported formats: (expanded formats are shown with 6 digits for year)
YYYYMMDD +-YYYYYYMMDD basic complete date
YYYY-MM-DD +-YYYYYY-MM-DD extended complete date
@@ -149,10 +151,10 @@ def parse_date(datestring, yeardigits=4, expanded=False):
@param yeardigits: how many digits are used to represent a year
@param expanded: if True then +/- signs are allowed. This parameter
is forced to True, if yeardigits != 4
-
+
@return: a datetime.date instance represented by datestring
@raise ISO8601Error: if this function can not parse the datestring
- @raise ValueError: if datestring can not be represented by datetime.date
+ @raise ValueError: if datestring can not be represented by datetime.date
'''
if yeardigits != 4:
expanded = True
@@ -163,10 +165,10 @@ def parse_date(datestring, yeardigits=4, expanded=False):
groups = match.groupdict()
# sign, century, year, month, week, day,
# FIXME: negative dates not possible with python standard types
- sign = (groups['sign'] == '-' and -1) or 1
+ sign = (groups['sign'] == '-' and -1) or 1
if 'century' in groups:
return date(sign * (int(groups['century']) * 100 + 1), 1, 1)
- if not 'month' in groups: # weekdate or ordinal date
+ if 'month' not in groups: # weekdate or ordinal date
ret = date(sign * int(groups['year']), 1, 1)
if 'week' in groups:
isotuple = ret.isocalendar()
@@ -175,10 +177,10 @@ def parse_date(datestring, yeardigits=4, expanded=False):
else:
days = 1
# if first week in year, do weeks-1
- return ret + timedelta(weeks=int(groups['week']) -
- (((isotuple[1] == 1) and 1) or 0),
- days = -isotuple[2] + days)
- elif 'day' in groups: # ordinal date
+ return ret + timedelta(weeks=int(groups['week']) -
+ (((isotuple[1] == 1) and 1) or 0),
+ days=-isotuple[2] + days)
+ elif 'day' in groups: # ordinal date
return ret + timedelta(days=int(groups['day'])-1)
else: # year date
return ret
@@ -187,14 +189,15 @@ def parse_date(datestring, yeardigits=4, expanded=False):
day = 1
else:
day = int(groups['day'])
- return date(sign * int(groups['year']),
+ return date(sign * int(groups['year']),
int(groups['month']) or 1, day)
raise ISO8601Error('Unrecognised ISO 8601 date format: %r' % datestring)
+
def date_isoformat(tdate, format=DATE_EXT_COMPLETE, yeardigits=4):
'''
- Format date strings.
-
+ Format date strings.
+
This method is just a wrapper around isodate.isostrf.strftime and uses
Date-Extended-Complete as default format.
'''
diff --git a/src/isodate/isodatetime.py b/src/isodate/isodatetime.py
index 7e4d570..9a5fce0 100644
--- a/src/isodate/isodatetime.py
+++ b/src/isodate/isodatetime.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -35,26 +35,33 @@ from datetime import datetime
from isodate.isostrf import strftime
from isodate.isostrf import DATE_EXT_COMPLETE, TIME_EXT_COMPLETE, TZ_EXT
from isodate.isodates import parse_date
+from isodate.isoerror import ISO8601Error
from isodate.isotime import parse_time
+
def parse_datetime(datetimestring):
'''
Parses ISO 8601 date-times into datetime.datetime objects.
-
+
This function uses parse_date and parse_time to do the job, so it allows
more combinations of date and time representations, than the actual
ISO 8601:2004 standard allows.
'''
- datestring, timestring = datetimestring.split('T')
+ try:
+ datestring, timestring = datetimestring.split('T')
+ except ValueError:
+ raise ISO8601Error("ISO 8601 time designator 'T' missing. Unable to"
+ " parse datetime string %r" % datetimestring)
tmpdate = parse_date(datestring)
tmptime = parse_time(timestring)
return datetime.combine(tmpdate, tmptime)
-def datetime_isoformat(tdt, format=DATE_EXT_COMPLETE + 'T' +
- TIME_EXT_COMPLETE + TZ_EXT):
+
+def datetime_isoformat(tdt, format=DATE_EXT_COMPLETE + 'T' +
+ TIME_EXT_COMPLETE + TZ_EXT):
'''
- Format datetime strings.
-
+ Format datetime strings.
+
This method is just a wrapper around isodate.isostrf.strftime and uses
Extended-Complete as default format.
'''
diff --git a/src/isodate/isoduration.py b/src/isodate/isoduration.py
index 97affdc..af44661 100644
--- a/src/isodate/isoduration.py
+++ b/src/isodate/isoduration.py
@@ -39,14 +39,15 @@ from isodate.isoerror import ISO8601Error
from isodate.isodatetime import parse_datetime
from isodate.isostrf import strftime, D_DEFAULT
-ISO8601_PERIOD_REGEX = re.compile(r"^(?P<sign>[+-])?"
- r"P(?P<years>[0-9]+([,.][0-9]+)?Y)?"
- r"(?P<months>[0-9]+([,.][0-9]+)?M)?"
- r"(?P<weeks>[0-9]+([,.][0-9]+)?W)?"
- r"(?P<days>[0-9]+([,.][0-9]+)?D)?"
- r"((?P<separator>T)(?P<hours>[0-9]+([,.][0-9]+)?H)?"
- r"(?P<minutes>[0-9]+([,.][0-9]+)?M)?"
- r"(?P<seconds>[0-9]+([,.][0-9]+)?S)?)?$")
+ISO8601_PERIOD_REGEX = re.compile(
+ r"^(?P<sign>[+-])?"
+ r"P(?P<years>[0-9]+([,.][0-9]+)?Y)?"
+ r"(?P<months>[0-9]+([,.][0-9]+)?M)?"
+ r"(?P<weeks>[0-9]+([,.][0-9]+)?W)?"
+ r"(?P<days>[0-9]+([,.][0-9]+)?D)?"
+ r"((?P<separator>T)(?P<hours>[0-9]+([,.][0-9]+)?H)?"
+ r"(?P<minutes>[0-9]+([,.][0-9]+)?M)?"
+ r"(?P<seconds>[0-9]+([,.][0-9]+)?S)?)?$")
# regular expression to parse ISO duartion strings.
@@ -103,11 +104,12 @@ def parse_duration(datestring):
if key not in ('separator', 'sign'):
if val is None:
groups[key] = "0n"
- #print groups[key]
+ # print groups[key]
if key in ('years', 'months'):
groups[key] = Decimal(groups[key][:-1].replace(',', '.'))
else:
- # these values are passed into a timedelta object, which works with floats.
+ # these values are passed into a timedelta object,
+ # which works with floats.
groups[key] = float(groups[key][:-1].replace(',', '.'))
if groups["years"] == 0 and groups["months"] == 0:
ret = timedelta(days=groups["days"], hours=groups["hours"],
@@ -134,10 +136,11 @@ def duration_isoformat(tduration, format=D_DEFAULT):
'''
# TODO: implement better decision for negative Durations.
# should be done in Duration class in consistent way with timedelta.
- if ((isinstance(tduration, Duration) and (tduration.years < 0 or
- tduration.months < 0 or
- tduration.tdelta < timedelta(0)))
- or (isinstance(tduration, timedelta) and (tduration < timedelta(0)))):
+ if (((isinstance(tduration, Duration)
+ and (tduration.years < 0 or tduration.months < 0
+ or tduration.tdelta < timedelta(0)))
+ or (isinstance(tduration, timedelta)
+ and (tduration < timedelta(0))))):
ret = '-'
else:
ret = ''
diff --git a/src/isodate/isoerror.py b/src/isodate/isoerror.py
index edbc5aa..e7b211b 100644
--- a/src/isodate/isoerror.py
+++ b/src/isodate/isoerror.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -28,5 +28,6 @@
This module defines all exception classes in the whole package.
'''
+
class ISO8601Error(ValueError):
'''Raised when the given ISO string can not be parsed.'''
diff --git a/src/isodate/isostrf.py b/src/isodate/isostrf.py
index 5f3169f..1afc810 100644
--- a/src/isodate/isostrf.py
+++ b/src/isodate/isostrf.py
@@ -69,10 +69,10 @@ DT_EXT_COMPLETE = DATE_EXT_COMPLETE + 'T' + TIME_EXT_COMPLETE + TZ_EXT
DT_BAS_COMPLETE = DATE_BAS_COMPLETE + 'T' + TIME_BAS_COMPLETE + TZ_BAS
DT_EXT_ORD_COMPLETE = DATE_EXT_ORD_COMPLETE + 'T' + TIME_EXT_COMPLETE + TZ_EXT
DT_BAS_ORD_COMPLETE = DATE_BAS_ORD_COMPLETE + 'T' + TIME_BAS_COMPLETE + TZ_BAS
-DT_EXT_WEEK_COMPLETE = DATE_EXT_WEEK_COMPLETE + 'T' + TIME_EXT_COMPLETE +\
- TZ_EXT
-DT_BAS_WEEK_COMPLETE = DATE_BAS_WEEK_COMPLETE + 'T' + TIME_BAS_COMPLETE +\
- TZ_BAS
+DT_EXT_WEEK_COMPLETE = (DATE_EXT_WEEK_COMPLETE + 'T' +
+ TIME_EXT_COMPLETE + TZ_EXT)
+DT_BAS_WEEK_COMPLETE = (DATE_BAS_WEEK_COMPLETE + 'T' +
+ TIME_BAS_COMPLETE + TZ_BAS)
# Duration formts
D_DEFAULT = 'P%P'
@@ -86,17 +86,19 @@ STRF_DT_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.day,
'%f': lambda tdt, yds: '%06d' % tdt.microsecond,
'%H': lambda tdt, yds: '%02d' % tdt.hour,
'%j': lambda tdt, yds: '%03d' % (tdt.toordinal() -
- date(tdt.year, 1, 1).toordinal() +
- 1),
+ date(tdt.year,
+ 1, 1).toordinal() +
+ 1),
'%m': lambda tdt, yds: '%02d' % tdt.month,
'%M': lambda tdt, yds: '%02d' % tdt.minute,
'%S': lambda tdt, yds: '%02d' % tdt.second,
'%w': lambda tdt, yds: '%1d' % tdt.isoweekday(),
'%W': lambda tdt, yds: '%02d' % tdt.isocalendar()[1],
- '%Y': lambda tdt, yds: (((yds != 4) and '+') or '') +\
- (('%%0%dd' % yds) % tdt.year),
- '%C': lambda tdt, yds: (((yds != 4) and '+') or '') +\
- (('%%0%dd' % (yds - 2)) % (tdt.year / 100)),
+ '%Y': lambda tdt, yds: (((yds != 4) and '+') or '') +
+ (('%%0%dd' % yds) % tdt.year),
+ '%C': lambda tdt, yds: (((yds != 4) and '+') or '') +
+ (('%%0%dd' % (yds - 2)) %
+ (tdt.year / 100)),
'%h': lambda tdt, yds: tz_isoformat(tdt, '%h'),
'%Z': lambda tdt, yds: tz_isoformat(tdt, '%Z'),
'%z': lambda tdt, yds: tz_isoformat(tdt, '%z'),
@@ -109,11 +111,11 @@ STRF_D_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.days,
'%M': lambda tdt, yds: '%02d' % ((tdt.seconds / 60) % 60),
'%S': lambda tdt, yds: '%02d' % (tdt.seconds % 60),
'%W': lambda tdt, yds: '%02d' % (abs(tdt.days / 7)),
- '%Y': lambda tdt, yds: (((yds != 4) and '+') or '') +\
- (('%%0%dd' % yds) % tdt.years),
- '%C': lambda tdt, yds: (((yds != 4) and '+') or '') +\
- (('%%0%dd' % (yds - 2)) %
- (tdt.years / 100)),
+ '%Y': lambda tdt, yds: (((yds != 4) and '+') or '') +
+ (('%%0%dd' % yds) % tdt.years),
+ '%C': lambda tdt, yds: (((yds != 4) and '+') or '') +
+ (('%%0%dd' % (yds - 2)) %
+ (tdt.years / 100)),
'%%': lambda tdt, yds: '%'}
@@ -183,24 +185,28 @@ def _strfdt(tdt, format, yeardigits=4):
def strftime(tdt, format, yeardigits=4):
- '''
- Directive Meaning Notes
+ '''Directive Meaning Notes
%d Day of the month as a decimal number [01,31].
- %f Microsecond as a decimal number [0,999999], zero-padded on the left (1)
+ %f Microsecond as a decimal number [0,999999], zero-padded
+ on the left (1)
%H Hour (24-hour clock) as a decimal number [00,23].
%j Day of the year as a decimal number [001,366].
%m Month as a decimal number [01,12].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61]. (3)
%w Weekday as a decimal number [0(Monday),6].
- %W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. (4)
+ %W Week number of the year (Monday as the first day of the week)
+ as a decimal number [00,53]. All days in a new year preceding the
+ first Monday are considered to be in week 0. (4)
%Y Year with century as a decimal number. [0000,9999]
%C Century as a decimal number. [00,99]
- %z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive). (5)
+ %z UTC offset in the form +HHMM or -HHMM (empty string if the
+ object is naive). (5)
%Z Time zone name (empty string if the object is naive).
%P ISO8601 duration format.
%p ISO8601 duration format in weeks.
%% A literal '%' character.
+
'''
if isinstance(tdt, (timedelta, Duration)):
return _strfduration(tdt, format, yeardigits)
diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py
index 7ded2d4..2b268d0 100644
--- a/src/isodate/isotime.py
+++ b/src/isodate/isotime.py
@@ -129,7 +129,8 @@ def parse_time(timestring):
# int(...) ... no rounding
# to_integral() ... rounding
return time(int(groups['hour']), int(groups['minute']),
- int(second), int(microsecond.to_integral()), tzinfo)
+ int(second), int(microsecond.to_integral()),
+ tzinfo)
if 'minute' in groups:
minute = Decimal(groups['minute'])
second = (minute - int(minute)) * 60
diff --git a/src/isodate/isotzinfo.py b/src/isodate/isotzinfo.py
index 97dbe8c..263afd7 100644
--- a/src/isodate/isotzinfo.py
+++ b/src/isodate/isotzinfo.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -27,7 +27,7 @@
'''
This module provides an ISO 8601:2004 time zone info parser.
-It offers a function to parse the time zone offset as specified by ISO 8601.
+It offers a function to parse the time zone offset as specified by ISO 8601.
'''
import re
@@ -39,10 +39,11 @@ TZ_REGEX = r"(?P<tzname>(Z|(?P<tzsign>[+-])"\
TZ_RE = re.compile(TZ_REGEX)
+
def build_tzinfo(tzname, tzsign='+', tzhour=0, tzmin=0):
'''
create a tzinfo instance according to given parameters.
-
+
tzname:
'Z' ... return UTC
'' | None ... return None
@@ -55,10 +56,11 @@ def build_tzinfo(tzname, tzsign='+', tzhour=0, tzmin=0):
tzsign = ((tzsign == '-') and -1) or 1
return FixedOffset(tzsign * tzhour, tzsign * tzmin, tzname)
+
def parse_tzinfo(tzstring):
'''
Parses ISO 8601 time zone designators to tzinfo objecs.
-
+
A time zone designator can be in the following format:
no designator indicates local time zone
Z UTC
@@ -69,19 +71,20 @@ def parse_tzinfo(tzstring):
match = TZ_RE.match(tzstring)
if match:
groups = match.groupdict()
- return build_tzinfo(groups['tzname'], groups['tzsign'],
- int(groups['tzhour'] or 0),
+ return build_tzinfo(groups['tzname'], groups['tzsign'],
+ int(groups['tzhour'] or 0),
int(groups['tzmin'] or 0))
raise ISO8601Error('%s not a valid time zone info' % tzstring)
+
def tz_isoformat(dt, format='%Z'):
'''
- return time zone offset ISO 8601 formatted.
+ return time zone offset ISO 8601 formatted.
The various ISO formats can be chosen with the format parameter.
-
+
if tzinfo is None returns ''
if tzinfo is UTC returns 'Z'
- else the offset is rendered to the given format.
+ else the offset is rendered to the given format.
format:
%h ... +-HH
%z ... +-HHMM
diff --git a/src/isodate/tests/__init__.py b/src/isodate/tests/__init__.py
index bc1867d..09dba2e 100644
--- a/src/isodate/tests/__init__.py
+++ b/src/isodate/tests/__init__.py
@@ -32,6 +32,7 @@ import unittest
from isodate.tests import (test_date, test_time, test_datetime, test_duration,
test_strf, test_pickle)
+
def test_suite():
'''
Return a new TestSuite instance consisting of all available TestSuites.
diff --git a/src/isodate/tests/test_date.py b/src/isodate/tests/test_date.py
index 3a1b4a6..fdc1043 100644
--- a/src/isodate/tests/test_date.py
+++ b/src/isodate/tests/test_date.py
@@ -14,11 +14,11 @@
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -66,20 +66,21 @@ TEST_CASES = {4: [('19', date(1901, 1, 1), DATE_CENTURY),
('+001985W15', date(1985, 4, 8), DATE_BAS_WEEK),
('+001985-W15', date(1985, 4, 8), DATE_EXT_WEEK)]}
+
def create_testcase(yeardigits, datestring, expectation, format):
'''
Create a TestCase class for a specific test.
-
+
This allows having a separate TestCase for each test tuple from the
TEST_CASES list, so that a failed test won't stop other tests.
'''
-
+
class TestDate(unittest.TestCase):
'''
A test case template to parse an ISO date string into a date
object.
'''
-
+
def test_parse(self):
'''
Parse an ISO date string and compare it to the expected value.
@@ -90,7 +91,7 @@ def create_testcase(yeardigits, datestring, expectation, format):
else:
result = parse_date(datestring, yeardigits)
self.assertEqual(result, expectation)
-
+
def test_format(self):
'''
Take date object and create ISO string from it.
@@ -98,15 +99,16 @@ def create_testcase(yeardigits, datestring, expectation, format):
'''
if expectation is None:
self.assertRaises(AttributeError,
- date_isoformat, expectation, format,
- yeardigits)
+ date_isoformat, expectation, format,
+ yeardigits)
else:
self.assertEqual(date_isoformat(expectation, format,
yeardigits),
datestring)
-
+
return unittest.TestLoader().loadTestsFromTestCase(TestDate)
+
def test_suite():
'''
Construct a TestSuite instance for all test cases.
@@ -118,9 +120,10 @@ def test_suite():
expectation, format))
return suite
+
# load_tests Protocol
def load_tests(loader, tests, pattern):
... 620 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/isodate.git
More information about the Python-modules-commits
mailing list