diff options
author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2018-07-02 08:18:54 -0400 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-07-09 03:38:36 +0000 |
commit | 55d1b0531a0b322a1b851fc921fd6fdf25d26331 (patch) | |
tree | f3d8c84e4d27fb8894a9c921a9a4ed06257cf80e /xlators | |
parent | dab12ce093628860bf43c3e0c7eaf9099cf7a78f (diff) |
core/various: python3 compat, prepare for python2 -> python3
see https://review.gluster.org/#/c/19788/,
https://review.gluster.org/#/c/19871/,
https://review.gluster.org/#/c/19952/,
https://review.gluster.org/#/c/20104/,
https://review.gluster.org/#/c/20162/,
https://review.gluster.org/#/c/20185/,
https://review.gluster.org/#/c/20207/,
https://review.gluster.org/#/c/20227/,
https://review.gluster.org/#/c/20307/,
https://review.gluster.org/#/c/20320/,
https://review.gluster.org/#/c/20332/, and
https://review.gluster.org/#/c/20364/
Fixes glupy.py python2isms, iteritems -> items, and some overlooked
print() in georep/peer_mountbroker.in
Note: Fedora packaging guidelines and SUSE rpmlint require explicit
shebangs; popular practices like #!/usr/bin/env python and #!/usr/bin/python
are not allowed; they must be #!/usr/bin/python2 or #!/usr/bin/python3
Note: Selected small fixes from 2to3 utility. Specifically apply,
basestring, funcattrs, has_key, idioms, map, numliterals, raise,
set_literal, types, urllib, and zip have already been applied. Also
version agnostic imports for urllib, cpickle, socketserver, _thread,
queue, etc., suggested by Aravinda in https://review.gluster.org/#/c/19767/1
Note: these 2to3 fixes report no changes are necessary: asserts, buffer,
exec, execfile, exitfunc, filter, getcwdu, imports2, input, intern,
itertools, metaclass, methodattrs, ne, next, nonzero, operator, paren,
raw_input, reduce, reload, renames, repr, standarderror, sys_exc, throw,
tuple_params, xreadlines.
Change-Id: Idda031c1ec975417c79323aea33e7b694e752b2a
updates: #411
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'xlators')
-rwxr-xr-x | xlators/experimental/fdl/src/gen_dumper.py | 4 | ||||
-rwxr-xr-x | xlators/experimental/fdl/src/gen_fdl.py | 2 | ||||
-rwxr-xr-x | xlators/experimental/fdl/src/gen_recon.py | 14 | ||||
-rwxr-xr-x | xlators/experimental/jbr-client/src/gen-fops.py | 8 | ||||
-rwxr-xr-x | xlators/experimental/jbr-server/src/gen-fops.py | 6 | ||||
-rw-r--r-- | xlators/features/cloudsync/src/cloudsync-fops-h.py | 2 | ||||
-rw-r--r-- | xlators/features/glupy/src/glupy.c | 54 | ||||
-rw-r--r-- | xlators/features/utime/src/utime-gen-fops-h.py | 2 |
8 files changed, 61 insertions, 31 deletions
diff --git a/xlators/experimental/fdl/src/gen_dumper.py b/xlators/experimental/fdl/src/gen_dumper.py index 95313adefcc..c15f7c8870d 100755 --- a/xlators/experimental/fdl/src/gen_dumper.py +++ b/xlators/experimental/fdl/src/gen_dumper.py @@ -73,7 +73,7 @@ def get_special_subs (args): def gen_functions (): code = "" - for name, value in ops.iteritems(): + for name, value in ops.items(): if "journal" not in [ x[0] for x in value ]: continue fop_subs[name]["@FUNCTION_BODY@"] = get_special_subs(value) @@ -83,7 +83,7 @@ def gen_functions (): def gen_cases (): code = "" - for name, value in ops.iteritems(): + for name, value in ops.items(): if "journal" not in [ x[0] for x in value ]: continue # Add the CASE fragment for this fop. diff --git a/xlators/experimental/fdl/src/gen_fdl.py b/xlators/experimental/fdl/src/gen_fdl.py index e8f97dc9957..8647ba7b6f1 100755 --- a/xlators/experimental/fdl/src/gen_fdl.py +++ b/xlators/experimental/fdl/src/gen_fdl.py @@ -310,7 +310,7 @@ selective_generate = { def gen_fdl (): entrypoints = [] - for name, value in ops.iteritems(): + for name, value in ops.items(): if "journal" not in [ x[0] for x in value ]: continue diff --git a/xlators/experimental/fdl/src/gen_recon.py b/xlators/experimental/fdl/src/gen_recon.py index ff5b5e16066..c6b3b02a2fe 100755 --- a/xlators/experimental/fdl/src/gen_recon.py +++ b/xlators/experimental/fdl/src/gen_recon.py @@ -142,14 +142,14 @@ def get_special_subs (name, args, fop_type): # is not stored in or read from the journal. There are other ways to # do that, but this is the only place we need anything similar and we # already have to treat it as a special case so this is simplest. - s_args_str = 'fd, &vector, 1, off, iobref, flags, &preop, &postop, xdata' + s_args_str = 'fd, &vector, 1, off, iobref, flags, &preop, &postop, xdata' elif name == 'symlink': # Swap 'linkpath' and 'loc'. s_args_str = '&loc, linkpath, &iatt, xdata' - elif name == 'xattrop': - s_args_str = '&loc, flags, dict, xdata, NULL' - elif name == 'fxattrop': - s_args_str = 'fd, flags, dict, xdata, NULL' + elif name == 'xattrop': + s_args_str = '&loc, flags, dict, xdata, NULL' + elif name == 'fxattrop': + s_args_str = 'fd, flags, dict, xdata, NULL' else: s_args_str = string.join (s_args, ", ") return code, links, s_args_str, cleanups @@ -162,7 +162,7 @@ def get_special_subs (name, args, fop_type): # an error is detected. This will probably get messy. def gen_functions (): code = "" - for name, value in ops.iteritems(): + for name, value in ops.items(): fop_type = [ x[1] for x in value if x[0] == "journal" ] if not fop_type: continue @@ -184,7 +184,7 @@ def gen_functions (): def gen_cases (): code = "" - for name, value in ops.iteritems(): + for name, value in ops.items(): if "journal" not in [ x[0] for x in value ]: continue # Add the CASE fragment for this fop. diff --git a/xlators/experimental/jbr-client/src/gen-fops.py b/xlators/experimental/jbr-client/src/gen-fops.py index 1962d2f8067..47b339910d4 100755 --- a/xlators/experimental/jbr-client/src/gen-fops.py +++ b/xlators/experimental/jbr-client/src/gen-fops.py @@ -14,7 +14,7 @@ from generator import ops, fop_subs, cbk_subs, generate # We really want the callback argument list, even when we're generating fop # code, so we propagate here. # TBD: this should probably be right in generate.py -for k, v in cbk_subs.iteritems(): +for k, v in cbk_subs.items(): fop_subs[k]['@ERROR_ARGS@'] = v['@ERROR_ARGS@'] # Stolen from old codegen.py @@ -29,18 +29,18 @@ def load_templates (path): m = tmpl_re.match(line) if m: if t_name: - templates[t_name] = string.join(t_contents, '') + templates[t_name] = ''.join(t_contents) t_name = m.group(1).strip() t_contents = [] elif t_name: t_contents.append(line) if t_name: - templates[t_name] = string.join(t_contents, '') + templates[t_name] = ''.join(t_contents) return templates # Stolen from gen_fdl.py def gen_client (templates): - for name, value in ops.iteritems(): + for name, value in ops.items(): if name == 'getspec': # It's not real if it doesn't have a stub function. continue diff --git a/xlators/experimental/jbr-server/src/gen-fops.py b/xlators/experimental/jbr-server/src/gen-fops.py index c4c87556cb3..bf6ff912d0c 100755 --- a/xlators/experimental/jbr-server/src/gen-fops.py +++ b/xlators/experimental/jbr-server/src/gen-fops.py @@ -19,7 +19,7 @@ from generator import ops, fop_subs, cbk_subs, generate # We really want the callback argument list, even when we're generating fop # code, so we propagate here. # TBD: this should probably be right in generate.py -for k, v in cbk_subs.iteritems(): +for k, v in cbk_subs.items(): fop_subs[k]['@ERROR_ARGS@'] = v['@ERROR_ARGS@'] # Stolen from old codegen.py @@ -34,13 +34,13 @@ def load_templates (path): m = tmpl_re.match(line) if m: if t_name: - templates[t_name] = string.join(t_contents, '') + templates[t_name] = ''.join(t_contents) t_name = m.group(1).strip() t_contents = [] elif t_name: t_contents.append(line) if t_name: - templates[t_name] = string.join(t_contents, '') + templates[t_name] = ''.join(t_contents) return templates # We need two types of templates. The first, for pure read operations, just diff --git a/xlators/features/cloudsync/src/cloudsync-fops-h.py b/xlators/features/cloudsync/src/cloudsync-fops-h.py index 37dfa5b10be..8a97cd0fcdd 100644 --- a/xlators/features/cloudsync/src/cloudsync-fops-h.py +++ b/xlators/features/cloudsync/src/cloudsync-fops-h.py @@ -16,7 +16,7 @@ cs_@NAME@ (call_frame_t *frame, xlator_t *this, """ def gen_defaults(): - for name, value in ops.iteritems(): + for name, value in ops.items(): if name == 'getspec': continue print(generate(OP_FOP_TEMPLATE, name, fop_subs)) diff --git a/xlators/features/glupy/src/glupy.c b/xlators/features/glupy/src/glupy.c index 46d1af5533a..bacccfef686 100644 --- a/xlators/features/glupy/src/glupy.c +++ b/xlators/features/glupy/src/glupy.c @@ -2317,6 +2317,41 @@ mem_acct_init (xlator_t *this) return ret; } +static void +py_error_log(const char *name, PyObject *pystr) +{ +#if PY_MAJOR_VERSION > 2 + char scr[256]; + if (PyUnicode_Check(pystr)) { + PyObject *tmp = + PyUnicode_AsEncodedString(pystr, "UTF-8", "strict"); + if (tmp != NULL) { + strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr)); + Py_DECREF(tmp); + } else { + strncpy(scr, "string encoding error", sizeof(scr)); + } + } else if (PyBytes_Check(pystr)) { + strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr)); + } else { + strncpy(scr, "string encoding error", sizeof(scr)); + } + gf_log (name, GF_LOG_ERROR, "Python error: %s", scr); +#else + gf_log (name, GF_LOG_ERROR, "Python error: %s", PyString_AsString(pystr)); +#endif +} + +static PyObject * +encode (const char *str) +{ +#if PY_MAJOR_VERSION > 2 + return PyUnicode_FromString(str); +#else + return PyString_FromString(str); +#endif +} + int32_t init (xlator_t *this) { @@ -2385,17 +2420,16 @@ init (xlator_t *this) /* Adjust python's path */ syspath = PySys_GetObject("path"); - path = PyString_FromString(GLUSTER_PYTHON_PATH); + path = encode(GLUSTER_PYTHON_PATH); PyList_Append(syspath, path); Py_DECREF(path); - py_mod_name = PyString_FromString(module_name); + py_mod_name = encode(module_name); if (!py_mod_name) { gf_log (this->name, GF_LOG_ERROR, "could not create name"); if (PyErr_Occurred()) { PyErr_Fetch (&error_type, &error_msg, &error_bt); - gf_log (this->name, GF_LOG_ERROR, "Python error: %s", - PyString_AsString(error_msg)); + py_error_log(this->name, error_msg); } goto *err_cleanup; } @@ -2408,8 +2442,7 @@ init (xlator_t *this) module_name); if (PyErr_Occurred()) { PyErr_Fetch (&error_type, &error_msg, &error_bt); - gf_log (this->name, GF_LOG_ERROR, "Python error: %s", - PyString_AsString(error_msg)); + py_error_log (this->name, error_msg); } goto *err_cleanup; } @@ -2421,8 +2454,7 @@ init (xlator_t *this) gf_log (this->name, GF_LOG_ERROR, "missing init func"); if (PyErr_Occurred()) { PyErr_Fetch (&error_type, &error_msg, &error_bt); - gf_log (this->name, GF_LOG_ERROR, "Python error: %s", - PyString_AsString(error_msg)); + py_error_log (this->name, error_msg); } goto *err_cleanup; } @@ -2433,8 +2465,7 @@ init (xlator_t *this) gf_log (this->name, GF_LOG_ERROR, "could not create args"); if (PyErr_Occurred()) { PyErr_Fetch (&error_type, &error_msg, &error_bt); - gf_log (this->name, GF_LOG_ERROR, "Python error: %s", - PyString_AsString(error_msg)); + py_error_log (this->name, error_msg); } goto *err_cleanup; } @@ -2447,8 +2478,7 @@ init (xlator_t *this) gf_log (this->name, GF_LOG_ERROR, "Python init failed"); if (PyErr_Occurred()) { PyErr_Fetch (&error_type, &error_msg, &error_bt); - gf_log (this->name, GF_LOG_ERROR, "Python error: %s", - PyString_AsString(error_msg)); + py_error_log (this->name, error_msg); } goto *err_cleanup; } diff --git a/xlators/features/utime/src/utime-gen-fops-h.py b/xlators/features/utime/src/utime-gen-fops-h.py index 9c297062929..e04cbd41293 100644 --- a/xlators/features/utime/src/utime-gen-fops-h.py +++ b/xlators/features/utime/src/utime-gen-fops-h.py @@ -21,7 +21,7 @@ utime_ops = ['fallocate', 'zerofill', 'opendir', 'mknod', 'mkdir', 'readv', 'writev', 'setattr', 'fsetattr'] def gen_defaults(): - for name, value in ops.iteritems(): + for name, value in ops.items(): if name in utime_ops: print(generate(OP_FOP_TEMPLATE, name, fop_subs)) |