[PATCH 1 of 2] py3: use email.generator.BytesGenerator in patch.split()

Pulkit Goyal 7895pulkit at gmail.com
Thu Oct 10 09:45:11 EDT 2019


On Thu, Oct 10, 2019 at 4:40 PM Denis Laxalde <denis at laxalde.org> wrote:
>
> Pulkit Goyal a écrit :
> > On Thu, Oct 10, 2019 at 12:02 PM Denis Laxalde <denis at laxalde.org> wrote:
> > >
> > > # HG changeset patch
> > > # User Denis Laxalde <denis.laxalde at logilab.fr>
> > > # Date 1570697337 -7200
> > > #      Thu Oct 10 10:48:57 2019 +0200
> > > # Node ID 707fc6aeadc33b02888e057e549c05d886fb67b0
> > > # Parent  52781d57313d512efb7150603104bea3ca11d0eb
> > > py3: use email.generator.BytesGenerator in patch.split()
> > >
> > > This fixes test-import.t on python3.
> > >
> > > We add Generator alias in mail module to handle python2/python3
> > > compatibility.
> > >
> > > diff --git a/mercurial/mail.py b/mercurial/mail.py
> > > index b478f38..8ee25bf 100644
> > > --- a/mercurial/mail.py
> > > +++ b/mercurial/mail.py
> > > @@ -420,6 +420,8 @@ def mimeencode(ui, s, charsets=None, dis
> > >
> > >  if pycompat.ispy3:
> > >
> > > +    Generator = email.generator.BytesGenerator
> > > +
> > >      def parse(fp):
> > >          ep = email.parser.Parser()
> > >          # disable the "universal newlines" mode, which isn't binary safe.
> > > @@ -436,6 +438,8 @@ if pycompat.ispy3:
> > >
> > >  else:
> > >
> > > +    Generator = email.generator.Generator
> >
> > fixed this to `email.Generator.Generator` in flight.
>
> Is this problematic? I did it on purpose as "email.generator" exists on
> py2.7 and "email.Generator" appears to be a proxy to the latter. Not a
> big deal though. (Should have mentioned this in the commit message.)

```
$ python
Python 2.7.15+ (default, Jul  9 2019, 16:51:35)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
>>> email.generator.Generator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'generator'
>>> import email.generator
>>> email.generator.Generator
<class email.generator.Generator at 0x7fac41c84668>
>>>
```

looks like we need to do `import email.generator` also.


More information about the Mercurial-devel mailing list