diff options
| author | Paul Ganssle <paul@ganssle.io> | 2018-03-10 18:10:32 -0500 |
|---|---|---|
| committer | Paul Ganssle <paul@ganssle.io> | 2018-03-10 18:10:32 -0500 |
| commit | c25fd9e40e3620b16e2b6161272ac7ea43dc4590 (patch) | |
| tree | d373e78134e39b713b821fe615a229525d777557 /dateutil/parser | |
| parent | eb701cf58c65f04486e4d1e37249df788a739a38 (diff) | |
| download | dateutil-git-c25fd9e40e3620b16e2b6161272ac7ea43dc4590.tar.gz | |
Relax strictness of default isoparse behavior
Diffstat (limited to 'dateutil/parser')
| -rw-r--r-- | dateutil/parser/isoparser.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/dateutil/parser/isoparser.py b/dateutil/parser/isoparser.py index 114e516..844bb5d 100644 --- a/dateutil/parser/isoparser.py +++ b/dateutil/parser/isoparser.py @@ -38,16 +38,21 @@ def _takes_ascii(f): class isoparser(object): - def __init__(self, sep='T'): + def __init__(self, sep=None): """ :param sep: - A single character that separates date and time portions + A single character that separates date and time portions. If + ``None``, the parser will accept any single character. + For strict ISO-8601 adherence, pass ``'T'``. """ - if (len(sep) != 1 or ord(sep) >= 128 or sep in '0123456789'): - raise ValueError('Separator must be a single, non-numeric ' - 'ASCII character') + if sep is not None: + if (len(sep) != 1 or ord(sep) >= 128 or sep in '0123456789'): + raise ValueError('Separator must be a single, non-numeric ' + + 'ASCII character') - self._sep = sep.encode('ascii') + sep = sep.encode('ascii') + + self._sep = sep @_takes_ascii def isoparse(self, dt_str): @@ -123,7 +128,7 @@ class isoparser(object): components, pos = self._parse_isodate(dt_str) if len(dt_str) > pos: - if dt_str[pos:pos + 1] == self._sep: + if self._sep is None or dt_str[pos:pos + 1] == self._sep: components += self._parse_isotime(dt_str[pos + 1:]) else: raise ValueError('String contains unknown ISO components') |
