Skip to content

Commit

Permalink
Merge pull request #761 from adobe-apiplatform/Remove_six_dependency
Browse files Browse the repository at this point in the history
remove six pkg references
  • Loading branch information
adorton-adobe authored Mar 29, 2022
2 parents ae60e59 + 3d32976 commit 0102f2c
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 85 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
'pycryptodome==3.9.7',
'ldap3',
'PyYAML',
'six',
'umapi-client==2.19',
'click',
'click-default-group',
Expand Down
8 changes: 4 additions & 4 deletions user_sync/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ def begin_work_umapi(config_loader: UMAPIConfigLoader):
# make sure that all the adobe groups are from known umapi connector names
primary_umapi_config, secondary_umapi_configs = config_loader.get_target_options()
referenced_umapi_names = set()
for groups in six.itervalues(directory_groups):
for groups in directory_groups.values():
for group in groups:
umapi_name = group.umapi_name
if umapi_name != PRIMARY_TARGET_NAME:
referenced_umapi_names.add(umapi_name)
referenced_umapi_names.difference_update(six.iterkeys(secondary_umapi_configs))
referenced_umapi_names.difference_update(secondary_umapi_configs.keys())
if len(referenced_umapi_names) > 0:
raise AssertionException('Adobe groups reference unknown umapi connectors: %s' % referenced_umapi_names)

Expand All @@ -380,7 +380,7 @@ def begin_work_umapi(config_loader: UMAPIConfigLoader):
primary_name = '.primary' if secondary_umapi_configs else ''
umapi_primary_connector = UmapiConnector(primary_name, primary_umapi_config, True)
umapi_other_connectors = {}
for secondary_umapi_name, secondary_config in six.iteritems(secondary_umapi_configs):
for secondary_umapi_name, secondary_config in secondary_umapi_configs.items():
umapi_secondary_conector = UmapiConnector(".secondary.%s" % secondary_umapi_name,
secondary_config)
umapi_other_connectors[secondary_umapi_name] = umapi_secondary_conector
Expand Down Expand Up @@ -646,7 +646,7 @@ def log_parameters(argv, config_loader):
logger.info('------- Command line arguments -------')
logger.info(' '.join(argv))
logger.debug('-------- Resulting invocation options --------')
for parameter_name, parameter_value in six.iteritems(config_loader.get_invocation_options()):
for parameter_name, parameter_value in config_loader.get_invocation_options().items():
logger.debug(' %s: %s', parameter_name, parameter_value)
logger.info('-------------------------------------')

Expand Down
12 changes: 6 additions & 6 deletions user_sync/certgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def create_key():
def create_cert(subject_fields, key):
try:
subject = issuer = x509.Name([
x509.NameAttribute(NameOID.COUNTRY_NAME, six.text_type(subject_fields['countryName'])),
x509.NameAttribute(NameOID.COUNTRY_NAME, str(subject_fields['countryName'])),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME,
six.text_type(subject_fields['stateOrProvinceName'])),
x509.NameAttribute(NameOID.LOCALITY_NAME, six.text_type(subject_fields['localityName'])),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, six.text_type(subject_fields['organizationName'])),
x509.NameAttribute(NameOID.COMMON_NAME, six.text_type(subject_fields['commonName'])),
x509.NameAttribute(NameOID.EMAIL_ADDRESS, six.text_type(subject_fields['emailAddress']))
str(subject_fields['stateOrProvinceName'])),
x509.NameAttribute(NameOID.LOCALITY_NAME, str(subject_fields['localityName'])),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, str(subject_fields['organizationName'])),
x509.NameAttribute(NameOID.COMMON_NAME, str(subject_fields['commonName'])),
x509.NameAttribute(NameOID.EMAIL_ADDRESS, str(subject_fields['emailAddress']))
])

return x509.CertificateBuilder().subject_name(
Expand Down
26 changes: 13 additions & 13 deletions user_sync/config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

import re
import six
# import six
import yaml
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -72,7 +72,7 @@ def iter_configs(self):
:rtype iterable(ObjectConfig)
"""
yield self
for child_config in six.itervalues(self.child_configs):
for child_config in self.child_configs.values():
for subtree_config in child_config.iter_configs():
yield subtree_config

Expand All @@ -88,7 +88,7 @@ def create_assertion_error(self, message):
return AssertionException("%s in: %s" % (message, self.get_full_scope()))

def describe_types(self, types_to_describe):
if types_to_describe == six.string_types:
if types_to_describe == str:
result = self.describe_types(str)
elif isinstance(types_to_describe, tuple):
result = []
Expand Down Expand Up @@ -166,7 +166,7 @@ def __contains__(self, item):
return item in self.value

def iter_keys(self):
return six.iterkeys(self.value)
return self.value.keys()

def iter_unused_keys(self):
for key in self.iter_keys():
Expand Down Expand Up @@ -196,7 +196,7 @@ def get_string(self, key, none_allowed=False) -> str:
"""
:rtype: basestring
"""
return self.get_value(key, six.string_types, none_allowed)
return self.get_value(key, str, none_allowed)

def get_int(self, key, none_allowed=False):
"""
Expand Down Expand Up @@ -393,7 +393,7 @@ def load_from_yaml(self, filepath, path_keys):
if not isinstance(yml, dict):
# malformed YML files produce a non-dictionary
raise AssertionException("Configuration file or command '{}' does not contain settings".format(filepath))
for path_key, options in six.iteritems(path_keys):
for path_key, options in path_keys.items():
key_path = path_key
keys = path_key.split('/')
self.process_path_key(dirpath, filename, key_path, yml, keys, 1, *options)
Expand All @@ -419,7 +419,7 @@ def process_path_key(self, dirpath, filename, key_path, dictionary, keys, level,
# if a wildcard is specified at this level, that means we
# should process all keys as path values
if key == "*":
for key, val in six.iteritems(dictionary):
for key, val in dictionary.items():
dictionary[key] = self.process_path_value(dirpath, filename, key_path, val, must_exist, can_have_subdict)
elif key in dictionary:
dictionary[key] = self.process_path_value(dirpath, filename, key_path, dictionary[key], must_exist, can_have_subdict)
Expand Down Expand Up @@ -451,13 +451,13 @@ def process_path_value(self, dirpath, filename, key_path, val, must_exist, can_h
:param must_exist: whether there must be a value
:param can_have_subdict: whether the value can be a tagged string
"""
if isinstance(val, six.string_types):
if isinstance(val, str):
return self.relative_path(dirpath, filename, key_path, val, must_exist)
elif isinstance(val, list):
vals = []
for entry in val:
if can_have_subdict and isinstance(entry, dict):
for subkey, subval in six.iteritems(entry):
for subkey, subval in entry.items():
vals.append({subkey: self.relative_path(dirpath, filename, key_path, subval, must_exist)})
else:
vals.append(self.relative_path(dirpath, filename, key_path, entry, must_exist))
Expand All @@ -468,7 +468,7 @@ def relative_path(dirpath, filename, key_path, val, must_exist):
"""
returns an absolute path that is resolved relative to the file being loaded
"""
if not isinstance(val, six.string_types):
if not isinstance(val, str):
raise AssertionException("Expected pathname for setting {} in config file {}".format(key_path, filename))
if val.startswith('$(') and val.endswith(')'):
raise AssertionException("Shell execution is no longer supported: {}".format(val))
Expand Down Expand Up @@ -509,7 +509,7 @@ def set_string_value(self, key, default_value):
:type key: str
:type default_value: Optional(str)
"""
self.set_value(key, six.string_types, default_value)
self.set_value(key, str, default_value)

def set_dict_value(self, key, default_value):
"""
Expand All @@ -526,7 +526,7 @@ def set_value(self, key, allowed_types, default_value):
self.options[key] = value

def require_string_value(self, key):
return self.require_value(key, six.string_types)
return self.require_value(key, str)

def require_value(self, key, allowed_types):
config = self.default_config
Expand All @@ -539,7 +539,7 @@ def require_value(self, key, allowed_types):
def resolve_invocation_options(options: dict, invocation_config: DictConfig, invocation_defaults: dict, args: dict) -> dict:
# get overrides from the main config
if invocation_config:
for k, v in six.iteritems(invocation_defaults):
for k, v in invocation_defaults.items():
if isinstance(v, bool):
val = invocation_config.get_bool(k, True)
if val is not None:
Expand Down
2 changes: 1 addition & 1 deletion user_sync/config/sign_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_engine_options(self) -> dict:
sign_only_user_action = user_sync.get_value('sign_only_user_action', (str, int))
options['user_sync']['sign_only_user_action'] = sign_only_user_action
if options.get('directory_group_mapped'):
options['directory_group_filter'] = set(six.iterkeys(self.directory_groups))
options['directory_group_filter'] = set(self.directory_groups.keys())
options['cache'] = self.main_config.get_dict('cache')
return options

Expand Down
8 changes: 4 additions & 4 deletions user_sync/config/user_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ def get_target_options(self):
raise AssertionException("Secondary umapi configuration found with no prefix: " + item)
primary_config_sources.append(item)
elif isinstance(item, dict):
for key, val in six.iteritems(item):
for key, val in item.items():
secondary_config_sources[key] = as_list(val)
primary_config = self.create_umapi_options(primary_config_sources)
secondary_configs = {key: self.create_umapi_options(val)
for key, val in six.iteritems(secondary_config_sources)}
for key, val in secondary_config_sources.items()}
return primary_config, secondary_configs

def get_directory_connector_module_name(self):
Expand Down Expand Up @@ -431,7 +431,7 @@ def combine_dicts(dicts):
result = {}
for dict_item in dicts:
if isinstance(dict_item, dict):
for dict_key, dict_val in six.iteritems(dict_item):
for dict_key, dict_val in dict_item.items():
result_val = result.get(dict_key)
if isinstance(result_val, dict) and isinstance(dict_val, dict):
result_val.update(dict_val)
Expand Down Expand Up @@ -545,7 +545,7 @@ def get_engine_options(self):
# set the directory group filter from the mapping, if requested.
# This must come late, after any prior adds to the mapping from other parameters.
if options.get('directory_group_mapped'):
options['directory_group_filter'] = set(six.iterkeys(self.directory_groups))
options['directory_group_filter'] = set(self.directory_groups.keys())

# set the adobe group filter from the mapping, if requested.
if options.get('adobe_group_mapped') is True:
Expand Down
2 changes: 1 addition & 1 deletion user_sync/connector/connector_umapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def __len__(self):

def convert_user_attributes_to_params(self, attributes):
params = {}
for key, value in six.iteritems(attributes):
for key, value in attributes.items():
if key == 'firstname':
key = 'first_name'
elif key == 'lastname':
Expand Down
4 changes: 2 additions & 2 deletions user_sync/connector/directory_adobe_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def load_users_and_groups(self, groups, extended_attributes, all_users):
self.logger.debug('Count of users in any groups: %d', len(grouped_user_records))
self.logger.debug('Count of users not in any groups: %d',
len(self.user_by_usr_key) - len(grouped_user_records))
return six.itervalues(self.user_by_usr_key)
return self.user_by_usr_key.values()
else:
return six.itervalues(grouped_user_records)
return grouped_user_records.values()

def convert_user(self, record):

Expand Down
2 changes: 1 addition & 1 deletion user_sync/connector/directory_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def load_users_and_groups(self, groups, extended_attributes, all_users):
self.logger.debug('Reading from: %s', file_path)
self.users = users = self.read_users(file_path, extended_attributes)
self.logger.debug('Number of users loaded: %d', len(users))
return six.itervalues(users)
return users.values()

def read_users(self, file_path, extended_attributes):
"""
Expand Down
Loading

0 comments on commit 0102f2c

Please sign in to comment.