Skip to content

Commit

Permalink
remove remaining "six" and "object" dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
d-w-moore committed Oct 16, 2024
1 parent 3ca3094 commit 79558eb
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 62 deletions.
3 changes: 1 addition & 2 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
3 changes: 1 addition & 2 deletions irods/column.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
from datetime import datetime
from calendar import timegm

Expand Down Expand Up @@ -136,7 +135,7 @@ 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
Expand Down
1 change: 0 additions & 1 deletion irods/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import struct
import hashlib
import six
import os
import ssl
import datetime
Expand Down
3 changes: 1 addition & 2 deletions irods/data_object.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
import sys
import logging
import six
import os
import ast

Expand Down Expand Up @@ -51,7 +50,7 @@ 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
3 changes: 1 addition & 2 deletions irods/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import errno
import numbers
import os
import six
import sys


Expand Down Expand Up @@ -112,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/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
3 changes: 1 addition & 2 deletions irods/manager/access_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from irods.column import In
from irods.user import iRODSUser

import six
import logging
import warnings

Expand All @@ -21,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
5 changes: 2 additions & 3 deletions irods/manager/data_object_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -175,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
3 changes: 1 addition & 2 deletions irods/message/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# http://askawizard.blogspot.com/2008/10/ordered-properties-python-saga-part-5.html
from irods.message.ordered import OrderedMetaclass, OrderedClass
import six


class MessageMetaclass(OrderedMetaclass):
Expand All @@ -11,7 +10,7 @@ def __init__(self, name, bases, attys):
prop.dub(name)


class Message(six.with_metaclass(MessageMetaclass, OrderedClass)):
class Message(OrderedClass, metaclass = MessageMetaclass):

def __init__(self, *args, **kwargs):
super(Message, self).__init__()
Expand Down
1 change: 0 additions & 1 deletion irods/message/property.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from base64 import b64encode, b64decode

from irods.message.ordered import OrderedProperty
import six
from html import escape

class MessageProperty(OrderedProperty):
Expand Down
34 changes: 5 additions & 29 deletions irods/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
import concurrent.futures
import threading
import multiprocessing
import six

from irods.data_object import iRODSDataObject
from irods.exception import DataObjectDoesNotExist
import irods.keywords as kw
from six.moves.queue import Queue,Full,Empty
from queue import Queue,Full,Empty


logger = logging.getLogger( __name__ )
Expand Down Expand Up @@ -48,30 +47,7 @@ def __call__(self):
return self.function(*self.args, **self.keywords)


try:
from threading import Barrier # Use 'Barrier' class if included (as in Python >= 3.2) ...
except ImportError: # ... but otherwise, use this ad hoc:
# Based on https://stackoverflow.com/questions/26622745/implementing-barrier-in-python2-7 :
class Barrier(object):
def __init__(self, n):
"""Initialize a Barrier to wait on n threads."""
self.n = n
self.count = 0
self.mutex = threading.Semaphore(1)
self.barrier = threading.Semaphore(0)
def wait(self):
"""Per-thread wait function.
As in Python3.2 threading, returns 0 <= wait_serial_int < n
"""
self.mutex.acquire()
self.count += 1
count = self.count
self.mutex.release()
if count == self.n: self.barrier.release()
self.barrier.acquire()
self.barrier.release()
return count - 1
from threading import Barrier

RECOMMENDED_NUM_THREADS_PER_TRANSFER = 3

Expand Down Expand Up @@ -121,7 +97,7 @@ def _progress(Q,this): # - thread to update progress indicator
except Empty:
pass
if i is not None:
if isinstance(i,six.integer_types) and i >= 0: this.progress[0] += i
if isinstance(i,int) and i >= 0: this.progress[0] += i
else: break
self._progress_fn = _progress
self._progress_thread = threading.Thread( target = self._progress_fn, args = (progress_Queue, self))
Expand Down Expand Up @@ -335,7 +311,7 @@ def bytes_range_for_thread( i, num_threads, total_bytes, chunk ):
end_offs = (i + 1) * chunk
else:
end_offs = total_bytes
return six.moves.range(begin_offs, end_offs)
return range(begin_offs, end_offs)

bytes_per_thread = total_size // num_threads

Expand Down Expand Up @@ -406,7 +382,7 @@ def io_main( session, Data, opr_, fname, R='', **kwopt):
if isinstance(Data,tuple):
(Data, Io) = Data[:2]

if isinstance (Data, six.string_types):
if isinstance (Data, str):
d_path = Data
try:
Data = session.data_objects.get( Data )
Expand Down
5 changes: 2 additions & 3 deletions irods/password_obfuscation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time
import random
import string
import six
from irods import MAX_PASSWORD_LENGTH

seq_list = [
Expand Down Expand Up @@ -228,7 +227,7 @@ def unscramble(s, key=default_password_key, scramble_prefix=default_scramble_pre
for c in to_unscramble:
if c in wheel:
#the index of the target character in wheel
wheel_index = (wheel.index(c) - six.indexbytes(encoder_ring, encoder_ring_index % 61) - chain) % len(wheel)
wheel_index = (wheel.index(c) - encoder_ring[encoder_ring_index % 61] - chain) % len(wheel)
unscrambled_string += wheel[wheel_index]
if block_chaining:
chain = ord(c) & 0xff
Expand Down Expand Up @@ -256,7 +255,7 @@ def scramble(s, key=default_password_key, scramble_prefix=default_scramble_prefi
for c in to_scramble:
if c in wheel:
#the index of the target character in wheel
wheel_index = (wheel.index(c) + six.indexbytes(encoder_ring, encoder_ring_index % 61) + chain) % len(wheel)
wheel_index = (wheel.index(c) + encoder_ring[encoder_ring_index % 61] + chain) % len(wheel)
scrambled_string += wheel[wheel_index]
if block_chaining:
chain = ord(scrambled_string[-1]) & 0xff
Expand Down
3 changes: 1 addition & 2 deletions irods/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import irods.exception as ex
from io import open as io_open
from irods.message import Message, StringProperty
import six

class RemoveRuleMessage(Message):
#define RULE_EXEC_DEL_INP_PI "str ruleExecId[NAME_LEN];"
Expand Down Expand Up @@ -86,7 +85,7 @@ def load(self, rule_file, encoding = 'utf-8'):
self.body = '@external\n'


with (io_open(rule_file, encoding = encoding) if isinstance(rule_file,six.string_types) else rule_file
with (io_open(rule_file, encoding = encoding) if isinstance(rule_file,str) else rule_file
) as f:

# parse rule file line-by-line
Expand Down
1 change: 0 additions & 1 deletion irods/test/collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from irods.models import Collection, DataObject
import irods.test.helpers as helpers
import irods.keywords as kw
from six.moves import range
from irods.test.helpers import my_function_name, unique_name
from irods.collection import iRODSCollection

Expand Down
1 change: 0 additions & 1 deletion irods/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from irods.message import (iRODSMessage, IRODS_VERSION)
from irods.password_obfuscation import encode
from irods import env_filename_from_keyword_args
from six.moves import range

class iRODSUserLogins:
"""A class which creates users and set passwords from a given dict or list of tuples of
Expand Down
1 change: 0 additions & 1 deletion irods/test/meta_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import irods.test.helpers as helpers
import irods.keywords as kw
from irods.session import iRODSSession
from six.moves import range
from irods.message import Bad_AVU_Field
from irods.column import Like, NotLike

Expand Down
1 change: 0 additions & 1 deletion irods/test/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-

import os
import six
import sys
import tempfile
import unittest
Expand Down
7 changes: 3 additions & 4 deletions irods/test/resource_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/env python

import os
import six
import sys
import unittest

Expand Down Expand Up @@ -44,13 +43,13 @@ def test_resource_properties_for_parent_and_hierarchy_at_3_levels__392(self):
self.assertEqual(resc.parent_id, (None if n == 0 else parent_resc.id))
self.assertEqual(resc.parent_name, (None if n == 0 else parent_resc.name))
self.assertEqual(resc.hierarchy_string, hier_str)
self.assertIs(type(resc.hierarchy_string), str) # type of hierarchy field is string.
self.assertIs(type(resc.hierarchy_string), str) # type of hierarchy field is string.
if resc.parent is None:
self.assertIs(resc.parent_id, None)
self.assertIs(resc.parent_name, None)
else:
self.assertIn(type(resc.parent_id), six.integer_types) # type of a non-null id field is integer.
self.assertIs(type(resc.parent_name), str) # type of a non-null name field is string.
self.assertIs(type(resc.parent_id), int) # type of a non-null id field is integer.
self.assertIs(type(resc.parent_name), str) # type of a non-null name field is string.
parent_resc = resc
finally:
ses.resources.remove_child(root, pt + "_0")
Expand Down
1 change: 0 additions & 1 deletion irods/test/rule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from irods.exception import (FAIL_ACTION_ENCOUNTERED_ERR, RULE_ENGINE_ERROR, UnknowniRODSError)
import irods.test.helpers as helpers
from irods.rule import Rule
import six
from io import open as io_open
import io

Expand Down
1 change: 0 additions & 1 deletion irods/test/user_group_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import irods.exception as ex
import irods.test.helpers as helpers
from irods.user import iRODSUser, Bad_password_change_parameter
from six.moves import range

def user_quotas_implemented():
return getattr(iRODSUser, "set_quota", None) is not None
Expand Down

0 comments on commit 79558eb

Please sign in to comment.