Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-16 Thread peter green

On 16/09/2019 10:38, Andreas Tille wrote:

Hi Peter,

On Sun, Sep 15, 2019 at 02:47:50PM +0100, peter green wrote:

tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave)))

Thanks to this hint

This hint was *wrong*, it will introduce garbage into the string and the 
"rotor" code is clearly designed to work with byte strings, not unicode strings.

Change it to

"tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )"

Thanks a lot for your patience.  Unfortunately this is not
yet the final solution:

...
Traceback (most recent call last):
   File "/usr/bin/cycle", line 83, in OnCloseWindow
 Save_Cycle(cycle.name, cycle.passwd, cycle.file)
   File "/usr/share/cycle/save_load.py", line 46, in Save_Cycle
 tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )
   File "/usr/share/cycle/p_rotor.py", line 63, in encrypt
 return self.cryptmore(buf, 0)
   File "/usr/share/cycle/p_rotor.py", line 88, in cryptmore
 c = rotors[i][c ^ pos[i]]
TypeError: unsupported operand type(s) for ^: 'int' and 'float'


Kind regards

Andreas.


When you get a floating point number where you were expecting an integer that 
is probably an issue related to the change in behavior of the division operator 
in python 3. In python 2 using the regular division operator on two integers 
produces an integer result, but in python 3 it produces a floating point result.

I see a few cases in the p_rotor code where regular division is used in a way 
that python2 would interpret it as floored division but python3 would interpret 
it as floating point division.

|"drotor[i] = erotor[i] = 1 + 2*rand(i/2) # increment" -> |||"drotor[i] = erotor[i] 
= 1 + 2*rand(i//2) # increment"
"|x = 171 * (x % 177) - 2 * (x/177)|" -> |||"x = 171 * (x % 177) - 2 * 
(x//177)"
"|||y = 172 * (y % 176) - 35 * (y/176)|" -> "y = 172 * (y % 176) - 35 * 
(y//176)||"
"z = 170 * (z % 178) - 63 * (z/178)" -> "z = 170 * (z % 178) - 63 * (z//178)"|


||
||



Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-16 Thread Andreas Tille
Hi Peter,

On Sun, Sep 15, 2019 at 02:47:50PM +0100, peter green wrote:
> > > tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave)))
> > 
> > Thanks to this hint
> This hint was *wrong*, it will introduce garbage into the string and the 
> "rotor" code is clearly designed to work with byte strings, not unicode 
> strings.
> 
> Change it to
> 
> "tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )"

Thanks a lot for your patience.  Unfortunately this is not
yet the final solution:

...
Traceback (most recent call last):
  File "/usr/bin/cycle", line 83, in OnCloseWindow
Save_Cycle(cycle.name, cycle.passwd, cycle.file)
  File "/usr/share/cycle/save_load.py", line 46, in Save_Cycle
tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )
  File "/usr/share/cycle/p_rotor.py", line 63, in encrypt
return self.cryptmore(buf, 0)
  File "/usr/share/cycle/p_rotor.py", line 88, in cryptmore
c = rotors[i][c ^ pos[i]]
TypeError: unsupported operand type(s) for ^: 'int' and 'float'


Kind regards

   Andreas. 

-- 
http://fam-tille.de



Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-15 Thread peter green

> tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave)))

Thanks to this hint

This hint was *wrong*, it will introduce garbage into the string and the 
"rotor" code is clearly designed to work with byte strings, not unicode strings.

Change it to

"tmp=rt.encrypt( b'Cycle'+pickle.dumps(objSave) )"




Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-13 Thread Andreas Tille
Hi,

On Thu, Sep 12, 2019 at 09:08:04PM +0200, Michael Kesper wrote:
> > Since I do not have much experience with hashlib I'd be happy if 
> > someone might be able to proof-read `def Save_Cycle` in 
> > save_load.py.
> 
> This does not have anything to do with hashlib per se.
> It's just the usual mess of mixing bytestrings with strings.
> You often don't notice in Python2, it just introduces subtle bugs.
> Python3 is more strict here and doesn't allow it.
> 
> Try this:
> 
> tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave)))

Thanks to this hint and the other hints by Peter Green, I'm now a
bit further.
 
> As an explanation:
> 
> Python 3.7.3 (default, Apr  3 2019, 05:39:12)
> ...

Thanks as well.

> P.S.: The code is in a bad state regarding whitespace / indentation.
> This is critical to get right in Python (e.g. after a for there _has to_
> be an indentation added, Python normally uses four spaces, no tabs).

I'm aware that the code is not good - there are other issues than spaces
and tabs for instance I removed an instance of os.tempnam where upstream
simply had overridden the automatic warning.  Its unmaintained upstream
as well.

I've seen other code in Debian which is not good as well.  Its rather a
philosophical question whether it is better to drop it from Debian (and
leave its users alone may be fiddling around with the upstream code
themselves) or whether we try our best to make the code at least
acceptable.  I usually subscribe to the latter and think there is no
right or wrong here.

I'm not really sure whether we might manage in this case.  After
implementing all hints I'm now stumbling upon:


Traceback (most recent call last):
  File "/usr/bin/cycle", line 83, in OnCloseWindow
Save_Cycle(cycle.name, cycle.passwd, cycle.file)
  File "/usr/share/cycle/save_load.py", line 46, in Save_Cycle
tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave)))
  File "/usr/share/cycle/p_rotor.py", line 63, in encrypt
return self.cryptmore(buf, 0)
  File "/usr/share/cycle/p_rotor.py", line 88, in cryptmore
c = rotors[i][c ^ pos[i]]
TypeError: unsupported operand type(s) for ^: 'str' and 'int'


I think an  "int(c) ^ pos[i]"  could do here - but I'd like
to get some confirmation first.

Kind regards

 Andreas.

-- 
http://fam-tille.de



Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-12 Thread peter green

but this leads later to

Traceback (most recent call last):
   File "cycle.py", line 83, in OnCloseWindow
 Save_Cycle(cycle.name, cycle.passwd, cycle.file)
   File "/home/andreas/debian-maintain/salsa/med-team/cycle/save_load.py", line 
46, in Save_Cycle
 tmp=rt.encrypt( 'Cycle'+pickle.dumps(objSave) )
TypeError: can only concatenate str (not "bytes") to str

String handling changed significantly between python2 and python3. Python 2 is "byte strings by 
default", type "str" was used for byte strings and type "unicode" was used for 
unicode strings. Implicit conversions between the two were allowed.

Python 3 is "unicode by default", type "bytes" is used for byte strings and type 
"str" is used for unicode strings. There is no implict conversion between unicode strings and byte 
strings.

"pickle.dumps" returned a bytes object, and you tried to concatenate it to a 
str object. You need to change 'Cycle' to b'Cycle'.

Also python 3 bytes objects behave a bit differently from python 2 str objects. 
To accommodate this I believe you need the following changes in p_rotor.py

"|for c in map(ord, buf):|" -> "|for c in buf:|"
"|return ''.join(map(chr, outbuf))|" -> "|return bytes(outbuf)|"
"|for c in map(ord, key):|" -> "for c in key:"



Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-12 Thread Andreas Tille
On Thu, Sep 12, 2019 at 01:57:32PM +0500, Andrey Rahmatullin wrote:
> > > There are circular imports in the code so you most likely broke that by
> > > reordering imports in various files.
> > 
> > s/you most likely broke/2to3 most likely broke/
> 2to3 doesn't do that. You mentioned autopep8, it could do that.

Ahhh, well, that might be another way to mess up the sequence.  Put a
mental note to warn me about autodep8.
 
> > So may be I misinterpreted your hint but even reverting the reordering
> > of 2to3 in my latest commit does not help.
> I also said that other changes may be problematic too. I didn't check
> them.

OK, I redid the patching in git[1] now.  Some more wxPython 4 porting
was needed as well but I somehow got the user interface working.  May be
some final helping hint could be how to fix leaving the program that
leads to:


Traceback (most recent call last):
  File "/usr/bin/cycle", line 83, in OnCloseWindow
Save_Cycle(cycle.name, cycle.passwd, cycle.file)
  File "/usr/share/cycle/save_load.py", line 27, in Save_Cycle
m.update(passwd)
TypeError: Unicode-objects must be encoded before hashing


I tried

  m.update(passwd.encode())

but this leads later to

Traceback (most recent call last):
  File "cycle.py", line 83, in OnCloseWindow
Save_Cycle(cycle.name, cycle.passwd, cycle.file)
  File "/home/andreas/debian-maintain/salsa/med-team/cycle/save_load.py", line 
46, in Save_Cycle
tmp=rt.encrypt( 'Cycle'+pickle.dumps(objSave) )
TypeError: can only concatenate str (not "bytes") to str


Since I do not have much experience with hashlib I'd be happy if someone
might be able to proof-read `def Save_Cycle` in save_load.py.

Kind regards

  Andreas.


[1] https://salsa.debian.org/med-team/cycle

-- 
http://fam-tille.de



Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-12 Thread Andrey Rahmatullin
On Thu, Sep 12, 2019 at 09:17:08AM +0200, Andreas Tille wrote:
> > > $ cycle
> > > Traceback (most recent call last):
> > >   File "/usr/bin/cycle", line 12, in 
> > > from dialogs import *
> > >   File "/usr/share/cycle/dialogs.py", line 8, in 
> > > from cal_year import cycle, Val
> > >   File "/usr/share/cycle/cal_year.py", line 9, in 
> > > from dialogs import Note_Dlg
> > > ImportError: cannot import name 'Note_Dlg' from 'dialogs' 
> > > (/usr/share/cycle/dialogs.py)
> > There are circular imports in the code so you most likely broke that by
> > reordering imports in various files.
> 
> s/you most likely broke/2to3 most likely broke/
2to3 doesn't do that. You mentioned autopep8, it could do that.

> > "from cal_year import *; from dialogs import *" works, the reverse
> > doesn't, so the /usr/bin/cycle code is definitely problematic, not sure
> > about other changes.
> 
> I can not confirm that
> 
>from cal_year import *
> 
> works at all.  It works in the unpatched Python2 version.
I was just saying that (in the unpatched Python2 version) "from cal_year
import *; from dialogs import *" works, the reverse doesn't, and the
patched version contains the reverse.

>git clone https://salsa.debian.org/med-team/cycle
>cd cycle
>echo "from cal_year import *" | python
>quilt push -a
>echo "from cal_year import *" | python3
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py", line 
> 9, in 
> from dialogs import Note_Dlg
>   File "/home/andreas/debian-maintain/salsa/med-team/cycle/dialogs.py", line 
> 12, in 
> from cal_year import cycle, Val
> ImportError: cannot import name 'cycle' from 'cal_year' 
> (/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py)
> 
> 
> So may be I misinterpreted your hint but even reverting the reordering
> of 2to3 in my latest commit does not help.
I also said that other changes may be problematic too. I didn't check
them.

-- 
WBR, wRAR


signature.asc
Description: PGP signature


Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-12 Thread Andreas Tille
Hi Andrey,

On Wed, Sep 11, 2019 at 07:32:33PM +0500, Andrey Rahmatullin wrote:
> > $ cycle
> > Traceback (most recent call last):
> >   File "/usr/bin/cycle", line 12, in 
> > from dialogs import *
> >   File "/usr/share/cycle/dialogs.py", line 8, in 
> > from cal_year import cycle, Val
> >   File "/usr/share/cycle/cal_year.py", line 9, in 
> > from dialogs import Note_Dlg
> > ImportError: cannot import name 'Note_Dlg' from 'dialogs' 
> > (/usr/share/cycle/dialogs.py)
> There are circular imports in the code so you most likely broke that by
> reordering imports in various files.

s/you most likely broke/2to3 most likely broke/

I admit I did not really checked what 2to3 created but I can assure you
I did not simply fired up an editor and had fun reverting some import
sequences.

> "from cal_year import *; from dialogs import *" works, the reverse
> doesn't, so the /usr/bin/cycle code is definitely problematic, not sure
> about other changes.

I can not confirm that

   from cal_year import *

works at all.  It works in the unpatched Python2 version.

   git clone https://salsa.debian.org/med-team/cycle
   cd cycle
   echo "from cal_year import *" | python
   quilt push -a
   echo "from cal_year import *" | python3
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py", line 
9, in 
from dialogs import Note_Dlg
  File "/home/andreas/debian-maintain/salsa/med-team/cycle/dialogs.py", line 
12, in 
from cal_year import cycle, Val
ImportError: cannot import name 'cycle' from 'cal_year' 
(/home/andreas/debian-maintain/salsa/med-team/cycle/cal_year.py)


So may be I misinterpreted your hint but even reverting the reordering
of 2to3 in my latest commit does not help.

Kind regards

  Andreas.

-- 
http://fam-tille.de



Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-11 Thread Andrey Rahmatullin
On Wed, Sep 11, 2019 at 04:12:34PM +0200, Andreas Tille wrote:
> Control: tags -1 help
> 
> On Wed, Sep 11, 2019 at 09:33:54AM -0300, Antonio Terceiro wrote:
> > E: Sub-process /usr/bin/dpkg returned an error code (1)
> > ~[100]$ cycle
> >   File "/usr/bin/cycle", line 29
> > if lang_find:
> > ^
> > TabError: inconsistent use of tabs and spaces in indentation
> 
> Argh.  That's fixed via autopep8 in Git[1] now.  However, when calling
> cycle I get
> 
> $ cycle
> Traceback (most recent call last):
>   File "/usr/bin/cycle", line 12, in 
> from dialogs import *
>   File "/usr/share/cycle/dialogs.py", line 8, in 
> from cal_year import cycle, Val
>   File "/usr/share/cycle/cal_year.py", line 9, in 
> from dialogs import Note_Dlg
> ImportError: cannot import name 'Note_Dlg' from 'dialogs' 
> (/usr/share/cycle/dialogs.py)
There are circular imports in the code so you most likely broke that by
reordering imports in various files.
"from cal_year import *; from dialogs import *" works, the reverse
doesn't, so the /usr/bin/cycle code is definitely problematic, not sure
about other changes.

-- 
WBR, wRAR


signature.asc
Description: PGP signature


Bug#939181: [Help] Re: Bug#939181: cycle: Python2 removal in sid/bullseye

2019-09-11 Thread Andreas Tille
Control: tags -1 help

On Wed, Sep 11, 2019 at 09:33:54AM -0300, Antonio Terceiro wrote:
> E: Sub-process /usr/bin/dpkg returned an error code (1)
> ~[100]$ cycle
>   File "/usr/bin/cycle", line 29
> if lang_find:
> ^
> TabError: inconsistent use of tabs and spaces in indentation

Argh.  That's fixed via autopep8 in Git[1] now.  However, when calling
cycle I get

$ cycle
Traceback (most recent call last):
  File "/usr/bin/cycle", line 12, in 
from dialogs import *
  File "/usr/share/cycle/dialogs.py", line 8, in 
from cal_year import cycle, Val
  File "/usr/share/cycle/cal_year.py", line 9, in 
from dialogs import Note_Dlg
ImportError: cannot import name 'Note_Dlg' from 'dialogs' 
(/usr/share/cycle/dialogs.py)


Any idea how to fix this?

Kind regards

 Andreas.


[1]  https://salsa.debian.org/med-team/cycle

-- 
http://fam-tille.de