Skip to content

Commit

Permalink
Use int() to make py2/py3 octal numbers more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaberez committed May 27, 2017
1 parent 8429f3f commit 0f1d283
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def parse_fcgi_socket(self, sock, proc_uid, socket_owner, socket_mode):
socket_owner = (proc_uid, gid_for_uid(proc_uid))

if socket_mode is None:
socket_mode = 0700
socket_mode = int('700', 8)

return UnixStreamSocketConfig(path, owner=socket_owner,
mode=socket_mode)
Expand Down Expand Up @@ -1050,7 +1050,7 @@ def server_configs_from_parser(self, parser):
except (TypeError, ValueError):
raise ValueError('Invalid chmod value %s' % chmod)
else:
chmod = 0700
chmod = int('700', 8)
config['chmod'] = chmod
config['section'] = section
configs.append(config)
Expand Down Expand Up @@ -1475,7 +1475,7 @@ def check_execv_args(self, filename, argv, st):
elif stat.S_ISDIR(st[stat.ST_MODE]):
raise NotExecutable("command at %r is a directory" % filename)

elif not (stat.S_IMODE(st[stat.ST_MODE]) & 0111):
elif not (stat.S_IMODE(st[stat.ST_MODE]) & int('111', 8)):
raise NotExecutable("command at %r is not executable" % filename)

elif not os.access(filename, os.X_OK):
Expand Down
2 changes: 1 addition & 1 deletion supervisor/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def makeExecutable(file, substitutions=None):
f = open(tmpnam, 'w')
f.write(data)
f.close()
os.chmod(tmpnam, 0755)
os.chmod(tmpnam, int('755', 8))
return tmpnam

def makeSpew(unkillable=False):
Expand Down
4 changes: 2 additions & 2 deletions supervisor/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def test_make_http_servers_noauth(self):
socketfile = tempfile.mktemp()
inet = {'family':socket.AF_INET, 'host':'localhost', 'port':17735,
'username':None, 'password':None, 'section':'inet_http_server'}
unix = {'family':socket.AF_UNIX, 'file':socketfile, 'chmod':0700,
unix = {'family':socket.AF_UNIX, 'file':socketfile, 'chmod':int('700', 8),
'chown':(-1, -1), 'username':None, 'password':None,
'section':'unix_http_server'}
servers = self._make_http_servers([inet, unix])
Expand Down Expand Up @@ -652,7 +652,7 @@ def test_make_http_servers_withauth(self):
inet = {'family':socket.AF_INET, 'host':'localhost', 'port':17736,
'username':'username', 'password':'password',
'section':'inet_http_server'}
unix = {'family':socket.AF_UNIX, 'file':socketfile, 'chmod':0700,
unix = {'family':socket.AF_UNIX, 'file':socketfile, 'chmod':int('700', 8),
'chown':(-1, -1), 'username':'username', 'password':'password',
'section':'unix_http_server'}
servers = self._make_http_servers([inet, unix])
Expand Down
12 changes: 6 additions & 6 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_options(self):
instance.realize(args=[])
options = instance.configroot.supervisord
self.assertEqual(options.directory, tempfile.gettempdir())
self.assertEqual(options.umask, 022)
self.assertEqual(options.umask, int('22', 8))
self.assertEqual(options.logfile, 'supervisord.log')
self.assertEqual(options.logfile_maxbytes, 1000 * 1024 * 1024)
self.assertEqual(options.logfile_backups, 5)
Expand Down Expand Up @@ -634,7 +634,7 @@ def test_options(self):
self.assertEqual(instance.uid, 0)
self.assertEqual(instance.gid, 0)
self.assertEqual(instance.directory, tempfile.gettempdir())
self.assertEqual(instance.umask, 022)
self.assertEqual(instance.umask, int('22', 8))
self.assertEqual(instance.logfile, os.path.join(here,'supervisord.log'))
self.assertEqual(instance.logfile_maxbytes, 1000 * 1024 * 1024)
self.assertEqual(instance.logfile_backups, 5)
Expand Down Expand Up @@ -2503,7 +2503,7 @@ def get_process_groups(instance, config):
self.assertEqual(gconf_foo.socket_config.url,
'unix:///tmp/foo.sock')
self.assertEqual(exp_owner, gconf_foo.socket_config.get_owner())
self.assertEqual(0666, gconf_foo.socket_config.get_mode())
self.assertEqual(int('666', 8), gconf_foo.socket_config.get_mode())
self.assertEqual(len(gconf_foo.process_configs), 2)
pconfig_foo = gconf_foo.process_configs[0]
self.assertEqual(pconfig_foo.__class__, FastCGIProcessConfig)
Expand All @@ -2514,7 +2514,7 @@ def get_process_groups(instance, config):
self.assertEqual(gconf_bar.socket_config.url,
'unix:///tmp/bar.sock')
self.assertEqual(exp_owner, gconf_bar.socket_config.get_owner())
self.assertEqual(0700, gconf_bar.socket_config.get_mode())
self.assertEqual(int('700', 8), gconf_bar.socket_config.get_mode())
self.assertEqual(len(gconf_bar.process_configs), 3)

gconf_cub = gconfigs[2]
Expand All @@ -2528,7 +2528,7 @@ def get_process_groups(instance, config):
self.assertEqual(gconf_flub.socket_config.url,
'unix:///tmp/flub.sock')
self.assertEqual(None, gconf_flub.socket_config.get_owner())
self.assertEqual(0700, gconf_flub.socket_config.get_mode())
self.assertEqual(int('700', 8), gconf_flub.socket_config.get_mode())
self.assertEqual(len(gconf_flub.process_configs), 1)

def test_fcgi_programs_from_parser_with_environment_expansions(self):
Expand Down Expand Up @@ -2586,7 +2586,7 @@ def get_process_groups(instance, config):
self.assertEqual(gconf_foo.socket_config.url,
'unix:///tmp/foo.usock')
self.assertEqual(exp_owner, gconf_foo.socket_config.get_owner())
self.assertEqual(438, gconf_foo.socket_config.get_mode()) # 0666 in Py2, 0o666 in Py3
self.assertEqual(int('666', 8), gconf_foo.socket_config.get_mode())
self.assertEqual(len(gconf_foo.process_configs), 2)
pconfig_foo = gconf_foo.process_configs[0]
self.assertEqual(pconfig_foo.__class__, FastCGIProcessConfig)
Expand Down

0 comments on commit 0f1d283

Please sign in to comment.