Patchwork [5,of,5] py3: work around bytes/unicode divergence in parsedate()

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 27, 2017, 12:34 p.m.
Message ID <3908ba8ca01db2bbb610.1506515682@mimosa>
Download mbox | patch
Permalink /patch/24184/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 27, 2017, 12:34 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1506508061 -32400
#      Wed Sep 27 19:27:41 2017 +0900
# Node ID 3908ba8ca01db2bbb6104946cb1e86e514ea4b8d
# Parent  b75831c83770a3ce9d9c84112cec6c6807563db1
py3: work around bytes/unicode divergence in parsedate()
Pulkit Goyal - Sept. 30, 2017, 12:05 a.m.
On Wed, Sep 27, 2017 at 6:04 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1506508061 -32400
> #      Wed Sep 27 19:27:41 2017 +0900
> # Node ID 3908ba8ca01db2bbb6104946cb1e86e514ea4b8d
> # Parent  b75831c83770a3ce9d9c84112cec6c6807563db1
> py3: work around bytes/unicode divergence in parsedate()

This series looks good to me.
Augie Fackler - Sept. 30, 2017, 1:49 p.m.
> On Sep 30, 2017, at 01:05, Pulkit Goyal <7895pulkit@gmail.com> wrote:
> 
> On Wed, Sep 27, 2017 at 6:04 PM, Yuya Nishihara <yuya@tcha.org> wrote:
>> # HG changeset patch
>> # User Yuya Nishihara <yuya@tcha.org>
>> # Date 1506508061 -32400
>> #      Wed Sep 27 19:27:41 2017 +0900
>> # Node ID 3908ba8ca01db2bbb6104946cb1e86e514ea4b8d
>> # Parent  b75831c83770a3ce9d9c84112cec6c6807563db1
>> py3: work around bytes/unicode divergence in parsedate()
> 
> This series looks good to me.

Queued, many thanks

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2006,12 +2006,12 @@  def parsedate(date, formats=None, bias=N
     The date may be a "unixtime offset" string or in one of the specified
     formats. If the date already is a (unixtime, offset) tuple, it is returned.
 
-    >>> parsedate(b' today ') == parsedate(\
-                                  datetime.date.today().strftime('%b %d'))
+    >>> parsedate(b' today ') == parsedate(
+    ...     datetime.date.today().strftime('%b %d').encode('ascii'))
     True
-    >>> parsedate(b'yesterday ') == parsedate((datetime.date.today() -\
-                                               datetime.timedelta(days=1)\
-                                              ).strftime('%b %d'))
+    >>> parsedate(b'yesterday ') == parsedate(
+    ...     (datetime.date.today() - datetime.timedelta(days=1)
+    ...      ).strftime('%b %d').encode('ascii'))
     True
     >>> now, tz = makedate()
     >>> strnow, strtz = parsedate(b'now')
@@ -2033,10 +2033,12 @@  def parsedate(date, formats=None, bias=N
     if date == 'now' or date == _('now'):
         return makedate()
     if date == 'today' or date == _('today'):
-        date = datetime.date.today().strftime('%b %d')
+        date = datetime.date.today().strftime(r'%b %d')
+        date = encoding.strtolocal(date)
     elif date == 'yesterday' or date == _('yesterday'):
         date = (datetime.date.today() -
-                datetime.timedelta(days=1)).strftime('%b %d')
+                datetime.timedelta(days=1)).strftime(r'%b %d')
+        date = encoding.strtolocal(date)
 
     try:
         when, offset = map(int, date.split(' '))
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -69,7 +69,7 @@  testmod('mercurial.templatefilters')
 testmod('mercurial.templater')
 testmod('mercurial.ui')
 testmod('mercurial.url')
-testmod('mercurial.util', py3=False)  # py3: multiple bytes/unicode issues
+testmod('mercurial.util')
 testmod('mercurial.util', testtarget='platform')
 testmod('hgext.convert.convcmd')
 testmod('hgext.convert.cvsps')