Patchwork [7,of,7] get-with-headers: handle httplib py3 divergence

login
register
mail settings
Submitter timeless
Date May 11, 2016, 5:20 a.m.
Message ID <a2806b270837492edb52.1462944029@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/14998/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless - May 11, 2016, 5:20 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1462561726 0
#      Fri May 06 19:08:46 2016 +0000
# Node ID a2806b270837492edb52a1146c12d9c1b5deed6d
# Parent  6849a6b26ea35775c142b78802b6b943dd2adf68
# EXP-Topic runtests
# Available At bb://timeless/mercurial-crew
#              hg pull bb://timeless/mercurial-crew -r a2806b270837
get-with-headers: handle httplib py3 divergence

With this final change, get-with-headers.py works in Python 3
Martijn Pieters - May 18, 2016, 4:42 p.m.
On 11 May 2016 at 06:20, timeless <timeless@fmr.im> wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1462561726 0
> #      Fri May 06 19:08:46 2016 +0000
> # Node ID a2806b270837492edb52a1146c12d9c1b5deed6d
> # Parent  6849a6b26ea35775c142b78802b6b943dd2adf68
> # EXP-Topic runtests
> # Available At bb://timeless/mercurial-crew
> #              hg pull bb://timeless/mercurial-crew -r a2806b270837
> get-with-headers: handle httplib py3 divergence
>
> With this final change, get-with-headers.py works in Python 3
>
> diff -r 6849a6b26ea3 -r a2806b270837 tests/get-with-headers.py
> --- a/tests/get-with-headers.py Fri May 06 19:07:23 2016 +0000
> +++ b/tests/get-with-headers.py Fri May 06 19:08:46 2016 +0000
> @@ -5,12 +5,17 @@
>
>  from __future__ import absolute_import, print_function
>
> -import httplib
>  import json
>  import os
>  import sys
>
>  try:
> +    import httplib
> +    httplib.HTTPException
> +except ImportError:
> +    import http.client as httplib

Why the httplib.HTTPException attribute test here? Surely that can be
dropped, as you don't handle the AttributeError that could throw if
the attribute is missing. And the exception isn't missing in either
2.6 or 2.7, and 3.5 will throw ImportError on the import httplib line
and never reaches that line.

> +
> +try:
>      import msvcrt
>      msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
>      msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
timeless - May 18, 2016, 5:05 p.m.
On Wed, May 18, 2016 at 9:42 AM, Martijn Pieters <mj@zopatista.com> wrote:
> On 11 May 2016 at 06:20, timeless <timeless@fmr.im> wrote:
>> # HG changeset patch
>> # User timeless <timeless@mozdev.org>
>> # Date 1462561726 0
>> #      Fri May 06 19:08:46 2016 +0000
>> # Node ID a2806b270837492edb52a1146c12d9c1b5deed6d
>> # Parent  6849a6b26ea35775c142b78802b6b943dd2adf68
>> # EXP-Topic runtests
>> # Available At bb://timeless/mercurial-crew
>> #              hg pull bb://timeless/mercurial-crew -r a2806b270837
>> get-with-headers: handle httplib py3 divergence
>>
>> With this final change, get-with-headers.py works in Python 3
>>
>> diff -r 6849a6b26ea3 -r a2806b270837 tests/get-with-headers.py
>> --- a/tests/get-with-headers.py Fri May 06 19:07:23 2016 +0000
>> +++ b/tests/get-with-headers.py Fri May 06 19:08:46 2016 +0000
>> @@ -5,12 +5,17 @@
>>
>>  from __future__ import absolute_import, print_function
>>
>> -import httplib
>>  import json
>>  import os
>>  import sys
>>
>>  try:
>> +    import httplib
>> +    httplib.HTTPException
>> +except ImportError:
>> +    import http.client as httplib
>
> Why the httplib.HTTPException attribute test here? Surely that can be
> dropped, as you don't handle the AttributeError that could throw if
> the attribute is missing. And the exception isn't missing in either
> 2.6 or 2.7, and 3.5 will throw ImportError on the import httplib line
> and never reaches that line.

copy/paste from mercurial where demandimport requires it. Feel free to
drop the line.

Patch

diff -r 6849a6b26ea3 -r a2806b270837 tests/get-with-headers.py
--- a/tests/get-with-headers.py	Fri May 06 19:07:23 2016 +0000
+++ b/tests/get-with-headers.py	Fri May 06 19:08:46 2016 +0000
@@ -5,12 +5,17 @@ 
 
 from __future__ import absolute_import, print_function
 
-import httplib
 import json
 import os
 import sys
 
 try:
+    import httplib
+    httplib.HTTPException
+except ImportError:
+    import http.client as httplib
+
+try:
     import msvcrt
     msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
     msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)