[apparmor] [patch] rewrite set_profile_flags() to use write_header()
Christian Boltz
apparmor at cboltz.de
Thu Apr 2 19:55:24 UTC 2015
Hello,
Am Donnerstag, 2. April 2015 schrieb Seth Arnold:
> On Thu, Apr 02, 2015 at 12:03:40PM -0700, Steve Beattie wrote:
> > > The difference is this:
> > >
> > > $ python2.7 -c "print(len(' ')/2)"
> > > 1
Seriously?
if 3/2 == 1:
print("old python inside")
> > > $ python3 -c "print(len(' ')/2)"
> > > 1.5
>
> Argh. I still can't believe that made it into a relese..
At least the new version does what sane people and math teachers expect.
> > So importing division from __future__ gives floating point division
> > by default in python 2.7, to match the behavior of division in
> > python3. Adding it to apparmor/aa.py lets the tests that were
> > failing only under python 2.7 pass, but I'm a little leery of
> > adding it, as grepping for>
> > division in aa.py gives at least:
> > data += write_methods[segs](prof_data, int(depth /
> > 2))
> >
> > data += write_header(write_prof_data[name],
> > int(depth / 2), name, False, include_flags)>
> > depth = int(len(line) - len(line.lstrip()) / 2)
> > + 1
> > depth = int((len(line) - len(line.lstrip())) /
> > 2)
> >
> > so I'm concerned we'd be introducing other changes by doing
> > so... though getting consistent behavior across python2 and python3
> > would be a benefit, I'd say.
>
> It looks like those other cases are prepared for it, the int()
> wrappers look like they are bringing back the usual truncation on
> division.
I also checked and agree - all divisions have an int() call around.
BTW: the only divisions we do are for depth (number of leading spaces),
and funnily we later undo this with a multiplication ;-)
Besides that - I'm using the tools with py3 since quite some time and
didn't notice any division-related crash.
> I think importing division from future makes sense here.
Agreed. To make it more formal:
Tell python2 about math
if 3/2 == 1:
print("python2 inside")
Add "from __future__ import division" so that python2 returns the
correct result (if needed, as float)
On related news: At least python3 knows how to calculate correctly.
I propose this patch for trunk and 2.9.
[ 21a-tell-python2-about-math.diff ]
=== modified file utils/apparmor/aa.py
--- utils/apparmor/aa.py 2015-04-02 12:01:55.401784901 +0200
+++ utils/apparmor/aa.py 2015-04-02 21:34:02.886805899 +0200
@@ -13,7 +13,7 @@
#
#
----------------------------------------------------------------------
# No old version logs, only 2.6 + supported
-from __future__ import with_statement
+from __future__ import division, with_statement
import inspect
import os
import re
Regards,
Christian Boltz
--
Yeah, I always need to have a sick bag handy when thinking about
web apps ;-) [Ludwig Nussel in opensuse-packaging]
More information about the AppArmor
mailing list