Skip to content

Commit

Permalink
[_480] Remove Python 2 compatibility and artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
d-w-moore committed Oct 22, 2024
1 parent f2394e0 commit d50d70e
Show file tree
Hide file tree
Showing 66 changed files with 199 additions and 423 deletions.
9 changes: 9 additions & 0 deletions irods/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import sys

minimum_compatible_python = (3,6)

if sys.version_info < minimum_compatible_python:
to_dotted_string = lambda version_tuple: '.'.join(str(_) for _ in version_tuple)
version_message = "This library is only supported on Python {} and above.".format(to_dotted_string(minimum_compatible_python))
raise RuntimeError(version_message)

from .version import __version__, version_as_tuple, version_as_string

import logging
Expand Down
7 changes: 2 additions & 5 deletions irods/access.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import collections
import copy
import six
from irods.collection import iRODSCollection
from irods.data_object import iRODSDataObject
from irods.path import iRODSPath
Expand All @@ -11,7 +10,7 @@ def keys(self): return list(self.codes.keys())
def values(self): return list(self.codes[k] for k in self.codes.keys())
def items(self): return list(zip(self.keys(),self.values()))

class iRODSAccess(six.with_metaclass(_Access_LookupMeta)):
class iRODSAccess(metaclass = _Access_LookupMeta):

@classmethod
def to_int(cls,key):
Expand Down Expand Up @@ -101,9 +100,7 @@ def __repr__(self):
object_dict = vars(self)
access_name = self.access_name.replace(' ','_')
user_type_hint = ("({user_type})" if object_dict.get('user_type') is not None else "").format(**object_dict)
return "<iRODSAccess {0} {path} {user_name}{1} {user_zone}>".format(access_name,
user_type_hint,
**object_dict)
return f"<iRODSAccess {access_name} {self.path} {self.user_name}{user_type_hint} {self.user_zone}>"

class _iRODSAccess_pre_4_3_0(iRODSAccess):
codes = collections.OrderedDict(
Expand Down
2 changes: 1 addition & 1 deletion irods/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from irods import derived_auth_filename

class iRODSAccount(object):
class iRODSAccount:

@property
def derived_auth_file(self):
Expand Down
1 change: 0 additions & 1 deletion irods/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
__all__ = [ 'pam_password', 'native' ]

AUTH_PLUGIN_PACKAGE = 'irods.auth'
Expand Down
6 changes: 2 additions & 4 deletions irods/client_configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import ast
import collections
import contextlib
Expand All @@ -7,7 +6,6 @@
import logging
import os
import re
import six
import sys
import types

Expand All @@ -16,7 +14,7 @@

logger = logging.Logger(__name__)

class iRODSConfiguration(object):
class iRODSConfiguration:
__slots__ = ()

def getter(category, setting):
Expand All @@ -39,7 +37,7 @@ def __new__(meta, name, bases, attrs):
isinstance(v,property) and v.fset is not None)
return cls

class ConnectionsProperties(six.with_metaclass(iRODSConfigAliasMetaclass,iRODSConfiguration)):
class ConnectionsProperties(iRODSConfiguration, metaclass = iRODSConfigAliasMetaclass):
@property
def xml_parser_default(self):
from irods.message import get_default_XML_by_name
Expand Down
5 changes: 2 additions & 3 deletions irods/collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import itertools
import operator

Expand All @@ -11,7 +10,7 @@ def _first_char( *Strings ):
if s: return s[0]
return ''

class iRODSCollection(object):
class iRODSCollection:

class AbsolutePathRequired(Exception):
"""Exception raised by iRODSCollection.normalize_path.
Expand Down Expand Up @@ -108,4 +107,4 @@ def normalize_path(*paths, **kw_):
return irods.path.iRODSPath(*paths, absolute = absolute)

def __repr__(self):
return "<iRODSCollection {id} {name}>".format(id = self.id, name = self.name.encode('utf-8'))
return f"<iRODSCollection {self.id} {self.name}>"
12 changes: 5 additions & 7 deletions irods/column.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import absolute_import
import six
from datetime import datetime
from calendar import timegm


class QueryKey(object):
class QueryKey:

def __init__(self, column_type):
self.column_type = column_type
Expand All @@ -28,7 +26,7 @@ def __ge__(self, other):
return Criterion('>=', self, other)


class Criterion(object):
class Criterion:

def __init__(self, op, query_key, value):
self.op = op
Expand Down Expand Up @@ -105,7 +103,7 @@ def __init__(self, column_type, icat_key):


# consider renaming columnType
class ColumnType(object):
class ColumnType:

@staticmethod
def to_python(string):
Expand Down Expand Up @@ -137,11 +135,11 @@ def to_python(string):
def to_irods(data):
try:
# Convert to Unicode string (aka decode)
data = six.text_type(data, 'utf-8', 'replace')
data = str(data, 'utf-8', 'replace')
except TypeError:
# Some strings are already Unicode so they do not need decoding
pass
return u"'{}'".format(data)
return "'{}'".format(data)


class DateTime(ColumnType):
Expand Down
27 changes: 8 additions & 19 deletions irods/connection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import absolute_import
import socket
import logging
import struct
import hashlib
import six
import os
import ssl
import datetime
Expand Down Expand Up @@ -49,7 +47,7 @@

class PlainTextPAMPasswordError(Exception): pass

class Connection(object):
class Connection:

DISALLOWING_PAM_PLAINTEXT = True

Expand Down Expand Up @@ -90,7 +88,7 @@ def __init__(self, pool, account):
auth_type = None

if not auth_type:
msg = "Authentication failed: scheme = {scheme!r}, auth_type = {auth_type!r}, auth_module = {auth_module!r}, ".format(**locals())
msg = f"Authentication failed: scheme = {scheme!r}, auth_type = {auth_type!r}, auth_module = {auth_module!r}, "
raise ValueError(msg)

self.create_time = datetime.datetime.now()
Expand Down Expand Up @@ -583,28 +581,19 @@ def _login_native(self, password=None):
# one "session" signature per connection
# see https://github.com/irods/irods/blob/4.2.1/plugins/auth/native/libnative.cpp#L137
# and https://github.com/irods/irods/blob/4.2.1/lib/core/src/clientLogin.cpp#L38-L60
if six.PY2:
self._client_signature = "".join("{:02x}".format(ord(c)) for c in challenge[:16])
else:
self._client_signature = "".join("{:02x}".format(c) for c in challenge[:16])
self._client_signature = "".join("{:02x}".format(c) for c in challenge[:16])

if six.PY3:
challenge = challenge.strip()
padded_pwd = struct.pack(
"%ds" % MAX_PASSWORD_LENGTH, password.encode(
'utf-8').strip())
else:
padded_pwd = struct.pack(
"%ds" % MAX_PASSWORD_LENGTH, password)
challenge = challenge.strip()
padded_pwd = struct.pack(
"%ds" % MAX_PASSWORD_LENGTH, password.encode(
'utf-8').strip())

m = hashlib.md5()
m.update(challenge)
m.update(padded_pwd)
encoded_pwd = m.digest()

if six.PY2:
encoded_pwd = encoded_pwd.replace('\x00', '\x01')
elif b'\x00' in encoded_pwd:
if b'\x00' in encoded_pwd:
encoded_pwd_array = bytearray(encoded_pwd)
encoded_pwd = bytes(encoded_pwd_array.replace(b'\x00', b'\x01'))

Expand Down
10 changes: 4 additions & 6 deletions irods/data_object.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import absolute_import
import io
import sys
import logging
import six
import os
import ast

Expand All @@ -26,7 +24,7 @@ def irods_basename(path):
return path.rsplit('/', 1)[1]


class iRODSReplica(object):
class iRODSReplica:

def __init__(self, number, status, resource_name, path, resc_hier, **kwargs):
self.number = number
Expand All @@ -46,13 +44,13 @@ def __repr__(self):
)


class iRODSDataObject(object):
class iRODSDataObject:

def __init__(self, manager, parent=None, results=None):
self.manager = manager
if parent and results:
self.collection = parent
for attr, value in six.iteritems(DataObject.__dict__):
for attr, value in DataObject.__dict__.items():
if not attr.startswith('_'):
try:
setattr(self, attr, results[0][value])
Expand Down Expand Up @@ -80,7 +78,7 @@ def __init__(self, manager, parent=None, results=None):


def __repr__(self):
return "<iRODSDataObject {id} {name}>".format(**vars(self))
return f"<iRODSDataObject {self.id} {self.name}>"

@property
def metadata(self):
Expand Down
5 changes: 1 addition & 4 deletions irods/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
# s/\(\w\+\)\s\+\(-\d\+\)/class \1(SystemException):\r code = \2/g


from __future__ import absolute_import
from __future__ import print_function
import errno
import numbers
import os
import six
import sys


Expand Down Expand Up @@ -114,7 +111,7 @@ def __int__(self):
return self.int_code


class iRODSException(six.with_metaclass(iRODSExceptionMeta, Exception)):
class iRODSException(Exception, metaclass = iRODSExceptionMeta):
"""An exception that originates from a server error.
Exception classes that are derived from this base and represent a concrete error, should
store a unique error code (X*1000) in their 'code' attribute, where X < 0.
Expand Down
2 changes: 1 addition & 1 deletion irods/genquery2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from irods.message import GenQuery2Request, STR_PI, iRODSMessage


class GenQuery2(object):
class GenQuery2:
"""Interface to the GenQuery2 API
This class provides an interface to the GenQuery2 API, an experimental
Expand Down
2 changes: 1 addition & 1 deletion irods/manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Manager(object):
class Manager:

__server_version = ()

Expand Down
6 changes: 2 additions & 4 deletions irods/manager/access_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from os.path import basename, dirname

from irods.manager import Manager
Expand All @@ -12,7 +11,6 @@
from irods.column import In
from irods.user import iRODSUser

import six
import logging
import warnings

Expand All @@ -22,7 +20,7 @@ def users_by_ids(session,ids=()):
try:
ids=list(iter(ids))
except TypeError:
if type(ids) in (str,) + six.integer_types: ids=int(ids)
if type(ids) in (str,int): ids=int(ids)
else: raise
cond = () if not ids \
else (In(User.id,list(map(int,ids))),) if len(ids)>1 \
Expand Down Expand Up @@ -138,7 +136,7 @@ def set(self, acl, recursive=False, admin=False, **kw):
acl = acl.copy(decanonicalize = True)
message_body = ModAclRequest(
recursiveFlag=int(recursive),
accessLevel='{prefix}{access_name}'.format(prefix=prefix, **vars(acl)),
accessLevel=f'{prefix}{acl.access_name}',
userName=userName_,
zone=zone_,
path=acl.path
Expand Down
1 change: 0 additions & 1 deletion irods/manager/collection_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from irods.models import Collection, DataObject
from irods.manager import Manager
from irods.manager._internal import _api_impl
Expand Down
8 changes: 3 additions & 5 deletions irods/manager/data_object_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import absolute_import
import ast
import collections
import io
import json
import logging
import os
import six
import weakref
from irods.models import DataObject, Collection
from irods.manager import Manager
Expand Down Expand Up @@ -176,13 +174,13 @@ def should_parallelize_transfer( self,
else:
pos = obj_sz.tell()
size = obj_sz.seek(0,os.SEEK_END)
if not isinstance(size,six.integer_types):
if not isinstance(size,int):
size = obj_sz.tell()
obj_sz.seek(pos,os.SEEK_SET)
if isinstance(measured_obj_size,list):
measured_obj_size[:] = [size]
return size > MAXIMUM_SINGLE_THREADED_TRANSFER_SIZE
elif isinstance(obj_sz,six.integer_types):
elif isinstance(obj_sz,int):
return obj_sz > MAXIMUM_SINGLE_THREADED_TRANSFER_SIZE
message = 'obj_sz of {obj_sz!r} is neither an integer nor a seekable object'.format(**locals())
raise RuntimeError(message)
Expand Down Expand Up @@ -507,7 +505,7 @@ def make_FileOpenRequest(**extra_opts):
returned_values['session'] = directed_sess
conn.release()
conn = directed_sess.pool.get_connection()
logger.debug(u'redirect_to_host = %s', redirected_host)
logger.debug('redirect_to_host = %s', redirected_host)

# Restore RESC HIER for DATA_OBJ_OPEN call
if requested_hierarchy is not None:
Expand Down
2 changes: 0 additions & 2 deletions irods/manager/metadata_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function
from __future__ import absolute_import
import logging
import copy
from os.path import dirname, basename
Expand Down
1 change: 0 additions & 1 deletion irods/manager/resource_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from irods.models import Resource
from irods.manager import Manager
from irods.message import GeneralAdminRequest, iRODSMessage
Expand Down
7 changes: 3 additions & 4 deletions irods/manager/user_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import logging
import os
import warnings
Expand Down Expand Up @@ -76,7 +75,7 @@ def create(self, user_name, user_type, user_zone="", auth_str=""):
"add",
"user",
user_name if not user_zone or user_zone == self.sess.zone \
else "{}#{}".format(user_name,user_zone),
else f"{user_name}#{user_zone}",
user_type,
user_zone,
auth_str
Expand Down Expand Up @@ -189,8 +188,8 @@ def modify_password(self, old_value, new_value, modify_irods_authentication_file
with open(auth_file) as f:
stored_pw = obf.decode(f.read())
if stored_pw != old_value:
message = "Not changing contents of '{}' - "\
"stored password is non-native or false match to old password".format(auth_file)
message = f"Not changing contents of '{auth_file}' - "\
"stored password is non-native or false match to old password"
raise UserManager.EnvStoredPasswordNotEdited(message)
with open(auth_file,'w') as f:
f.write(obf.encode(new_value))
Expand Down
Loading

0 comments on commit d50d70e

Please sign in to comment.