#288 Fix python3 incompatible syntax
Merged 3 years ago by puiterwijk. Opened 3 years ago by puiterwijk.
puiterwijk/ipsilon py3syntax  into  master

@@ -258,7 +258,7 @@ 

  

          path = os.path.join(opts['data_dir'], 'openidc')

          if not os.path.exists(path):

-             os.makedirs(path, 0700)

+             os.makedirs(path, 0o700)

Interesting, I wasn't familiar with this syntax, but it looks good:

>>> 0o700
448
>>> 0b111000000
448

Python2 implied that you meant octal numbers when you prefix with a 0, but python3 considers that a syntax error, because it wants you to explicitly say it's octal with "0o", just like "0x".

  

          keyfile = os.path.join(path, 'openidc.key')

          keyid = int(time.time())

@@ -98,7 +98,7 @@ 

          # Check storage path is present or create it

          path = os.path.join(opts['data_dir'], 'persona')

          if not os.path.exists(path):

-             os.makedirs(path, 0700)

+             os.makedirs(path, 0o700)

  

          keyfile = os.path.join(path, 'persona.key')

          exponent = 0x10001

@@ -514,7 +514,7 @@ 

          # Check storage path is present or create it

          path = os.path.join(opts['data_dir'], 'saml2')

          if not os.path.exists(path):

-             os.makedirs(path, 0700)

+             os.makedirs(path, 0o700)

  

          # Use the same cert for signing and ecnryption for now

          cert = Certificate(path)

file modified
+2 -2
@@ -5,7 +5,7 @@ 

  from string import Template

  

  

- def fix_user_dirs(path, user=None, mode=0700):

+ def fix_user_dirs(path, user=None, mode=0o700):

      pw = None

      if user:

          pw = pwd.getpwnam(user)
@@ -15,7 +15,7 @@ 

              target = os.path.join(root, name)

              if pw:

                  os.chown(target, pw.pw_uid, pw.pw_gid)

-             os.chmod(target, mode & 0666)

+             os.chmod(target, mode & 0o666)

          if pw:

              os.chown(root, pw.pw_uid, pw.pw_gid)

          os.chmod(root, mode)

Interesting, I wasn't familiar with this syntax, but it looks good:

>>> 0o700
448
>>> 0b111000000
448

Python2 implied that you meant octal numbers when you prefix with a 0, but python3 considers that a syntax error, because it wants you to explicitly say it's octal with "0o", just like "0x".

Commit 4f554db fixes this pull-request

Pull-Request has been merged by patrick@puiterwijk.org

3 years ago