Patchwork [3,of,3,V2] py3: convert date and format arguments str before passing in time.strptime

login
register
mail settings
Submitter Pulkit Goyal
Date May 15, 2017, 5:50 p.m.
Message ID <bffb17a42e8c185bb3d3.1494870648@workspace>
Download mbox | patch
Permalink /patch/20630/
State Accepted
Headers show

Comments

Pulkit Goyal - May 15, 2017, 5:50 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1494026485 -19800
#      Sat May 06 04:51:25 2017 +0530
# Node ID bffb17a42e8c185bb3d31f4489066448ce2e259a
# Parent  75245b989dd661164041794620770ad7726fe9cd
py3: convert date and format arguments str before passing in time.strptime

time.strptime() raises ValueError if the arguments are not str.
Source Code: https://hg.python.org/cpython/file/3.5/Lib/_strptime.py#l307
Augie Fackler - May 15, 2017, 5:56 p.m.
On Mon, May 15, 2017 at 11:20:48PM +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1494026485 -19800
> #      Sat May 06 04:51:25 2017 +0530
> # Node ID bffb17a42e8c185bb3d31f4489066448ce2e259a
> # Parent  75245b989dd661164041794620770ad7726fe9cd
> py3: convert date and format arguments str before passing in time.strptime

queued patches 2 and 3, thanks
via Mercurial-devel - May 16, 2017, 3:39 p.m.
On Mon, May 15, 2017 at 10:50 AM, Pulkit Goyal <7895pulkit@gmail.com> wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1494026485 -19800
> #      Sat May 06 04:51:25 2017 +0530
> # Node ID bffb17a42e8c185bb3d31f4489066448ce2e259a
> # Parent  75245b989dd661164041794620770ad7726fe9cd
> py3: convert date and format arguments str before passing in time.strptime
>
> time.strptime() raises ValueError if the arguments are not str.
> Source Code: https://hg.python.org/cpython/file/3.5/Lib/_strptime.py#l307
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1937,7 +1937,8 @@
>              # elements are relative to today
>              usenow = True
>
> -    timetuple = time.strptime(date, format)
> +    timetuple = time.strptime(encoding.strfromlocal(date),
> +                                    encoding.strfromlocal(format))

Like the previous patch, indentation looks off here. I'm fixing it in
flight. You may want to look over your editor's settings.

>      localunixtime = int(calendar.timegm(timetuple))
>      if offset is None:
>          # local timezone
> _______________________________________________
> 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
@@ -1937,7 +1937,8 @@ 
             # elements are relative to today
             usenow = True
 
-    timetuple = time.strptime(date, format)
+    timetuple = time.strptime(encoding.strfromlocal(date),
+                                    encoding.strfromlocal(format))
     localunixtime = int(calendar.timegm(timetuple))
     if offset is None:
         # local timezone