Skip to content

Commit

Permalink
Pyupgrade and drop six
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz authored and Ch3LL committed Jul 6, 2021
1 parent 0d71775 commit d9b5065
Show file tree
Hide file tree
Showing 1,565 changed files with 8,268 additions and 16,733 deletions.
1 change: 0 additions & 1 deletion pkg/rpm/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /bin/env python
from __future__ import print_function

import argparse
import os
Expand Down
1 change: 0 additions & 1 deletion pkg/smartos/esky/sodium_grabber_installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
The setup script for sodium_grabber
"""
Expand Down
6 changes: 2 additions & 4 deletions pkg/windows/portable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
from __future__ import print_function

import getopt
import os
Expand Down Expand Up @@ -49,9 +48,8 @@ def main(argv):
if target == "":
display_help()

if sys.version_info >= (3, 0):
search = search.encode("utf-8")
replace = replace.encode("utf-8")
search = search.encode("utf-8")
replace = replace.encode("utf-8")
f = open(target, "rb").read()
f = f.replace(search, replace)
f = f.replace(search.lower(), replace)
Expand Down
3 changes: 0 additions & 3 deletions salt/_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
salt._logging
~~~~~~~~~~~~~
Expand All @@ -11,7 +10,5 @@
the python's logging system.
"""

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

from salt._logging.impl import * # pylint: disable=wildcard-import
22 changes: 9 additions & 13 deletions salt/_logging/handlers.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# -*- coding: utf-8 -*-
"""
salt._logging.handlers
~~~~~~~~~~~~~~~~~~~~~~
Salt's logging handlers
"""

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import copy
import logging
import logging.handlers
import queue
import sys
from collections import deque

# Import salt libs
from salt._logging.mixins import ExcInfoOnLogLevelFormatMixin, NewStyleClassMixin
from salt.ext.six.moves import queue # pylint: disable=import-error,no-name-in-module

# from salt.utils.versions import warn_until_date

Expand Down Expand Up @@ -48,7 +44,7 @@ def __init__(self, level=logging.NOTSET, max_queue_size=10000):
# '{{date}}.'.format(name=__name__)
# )
self.__max_queue_size = max_queue_size
super(TemporaryLoggingHandler, self).__init__(level=level)
super().__init__(level=level)
self.__messages = deque(maxlen=max_queue_size)

def handle(self, record):
Expand Down Expand Up @@ -117,7 +113,7 @@ def handleError(self, record):
del exc_type, exc, exc_traceback

if not handled:
super(SysLogHandler, self).handleError(record)
super().handleError(record)


class RotatingFileHandler(
Expand Down Expand Up @@ -152,7 +148,7 @@ def handleError(self, record):
):
if self.level <= logging.WARNING:
sys.stderr.write(
'[WARNING ] Unable to rotate the log file "{0}" '
'[WARNING ] Unable to rotate the log file "{}" '
"because it is in use\n".format(self.baseFilename)
)
handled = True
Expand All @@ -162,7 +158,7 @@ def handleError(self, record):
del exc_type, exc, exc_traceback

if not handled:
super(RotatingFileHandler, self).handleError(record)
super().handleError(record)


class WatchedFileHandler(
Expand Down Expand Up @@ -217,7 +213,7 @@ def enqueue(self, record):
except queue.Full:
sys.stderr.write(
"[WARNING ] Message queue is full, "
'unable to write "{0}" to log'.format(record)
'unable to write "{}" to log'.format(record)
)

def prepare(self, record):
Expand Down Expand Up @@ -266,7 +262,7 @@ class QueueHandler(
ExcInfoOnLogLevelFormatMixin, logging.handlers.QueueHandler
): # pylint: disable=no-member,inconsistent-mro
def __init__(self, queue): # pylint: disable=useless-super-delegation
super(QueueHandler, self).__init__(queue)
super().__init__(queue)
# warn_until_date(
# '20220101',
# 'Please stop using \'{name}.QueueHandler\' and instead '
Expand Down Expand Up @@ -325,7 +321,7 @@ class QueueHandler(
ExcInfoOnLogLevelFormatMixin, logging.handlers.QueueHandler
): # pylint: disable=no-member,inconsistent-mro
def __init__(self, queue): # pylint: disable=useless-super-delegation
super(QueueHandler, self).__init__(queue)
super().__init__(queue)
# warn_until_date(
# '20220101',
# 'Please stop using \'{name}.QueueHandler\' and instead '
Expand All @@ -347,5 +343,5 @@ def enqueue(self, record):
except queue.Full:
sys.stderr.write(
"[WARNING ] Message queue is full, "
'unable to write "{0}" to log.\n'.format(record)
'unable to write "{}" to log.\n'.format(record)
)
4 changes: 0 additions & 4 deletions salt/_logging/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
Salt's logging implementation classes/functionality
"""


import logging
import re
import sys
Expand All @@ -30,8 +28,6 @@
from salt.utils.ctx import RequestContext # isort:skip
from salt.utils.textformat import TextFormat # isort:skip

# from salt.ext.six.moves.urllib.parse import urlparse # pylint: disable=import-error,no-name-in-module

LOG_LEVELS = {
"all": logging.NOTSET,
"debug": logging.DEBUG,
Expand Down
17 changes: 7 additions & 10 deletions salt/_logging/mixins.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-
"""
salt._logging.mixins
~~~~~~~~~~~~~~~~~~~~
Logging related mix-ins
"""

# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals

import logging
import sys


class NewStyleClassMixin(object):
class NewStyleClassMixin:
"""
Simple new style class to make pylint shut up!
This is required because SaltLoggingClass can't subclass object directly:
Expand All @@ -22,7 +19,7 @@ class NewStyleClassMixin(object):
"""


class LoggingProfileMixin(object):
class LoggingProfileMixin:
"""
Simple mix-in class to add a trace method to python's logging.
"""
Expand All @@ -31,7 +28,7 @@ def profile(self, msg, *args, **kwargs):
self.log(getattr(logging, "PROFILE", 15), msg, *args, **kwargs)


class LoggingTraceMixin(object):
class LoggingTraceMixin:
"""
Simple mix-in class to add a trace method to python's logging.
"""
Expand All @@ -40,7 +37,7 @@ def trace(self, msg, *args, **kwargs):
self.log(getattr(logging, "TRACE", 5), msg, *args, **kwargs)


class LoggingGarbageMixin(object):
class LoggingGarbageMixin:
"""
Simple mix-in class to add a garbage method to python's logging.
"""
Expand Down Expand Up @@ -74,10 +71,10 @@ def __new__(mcs, name, bases, attrs):
bases.append(LoggingTraceMixin)
if include_garbage:
bases.append(LoggingGarbageMixin)
return super(LoggingMixinMeta, mcs).__new__(mcs, name, tuple(bases), attrs)
return super().__new__(mcs, name, tuple(bases), attrs)


class ExcInfoOnLogLevelFormatMixin(object):
class ExcInfoOnLogLevelFormatMixin:
"""
Logging handler class mixin to properly handle including exc_info on a per logging handler basis
"""
Expand All @@ -86,7 +83,7 @@ def format(self, record):
"""
Format the log record to include exc_info if the handler is enabled for a specific log level
"""
formatted_record = super(ExcInfoOnLogLevelFormatMixin, self).format(record)
formatted_record = super().format(record)
exc_info_on_loglevel = getattr(record, "exc_info_on_loglevel", None)
exc_info_on_loglevel_formatted = getattr(
record, "exc_info_on_loglevel_formatted", None
Expand Down
10 changes: 2 additions & 8 deletions salt/acl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
The acl module handles publisher_acl operations
Expand All @@ -9,16 +8,11 @@
"""

# Import python libraries
from __future__ import absolute_import, print_function, unicode_literals

# Import salt libs
import salt.utils.stringutils

# Import 3rd-party libs
from salt.ext import six


class PublisherACL(object):
class PublisherACL:
"""
Represents the publisher ACL and provides methods
to query the ACL for given operations
Expand All @@ -38,7 +32,7 @@ def user_is_blacklisted(self, user):

def cmd_is_blacklisted(self, cmd):
# If this is a regular command, it is a single function
if isinstance(cmd, six.string_types):
if isinstance(cmd, str):
cmd = [cmd]
for fun in cmd:
if not salt.utils.stringutils.check_whitelist_blacklist(
Expand Down
1 change: 0 additions & 1 deletion salt/auth/auto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
An "Always Approved" eauth interface to test against, not intended for
production use
Expand Down
10 changes: 2 additions & 8 deletions salt/auth/django.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Provide authentication using Django Web Framework
Expand Down Expand Up @@ -47,16 +46,11 @@ class SaltExternalAuthModel(models.Model):
'SaltExternalAuthModel'.
"""

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import logging
import os
import sys

# Import 3rd-party libs
from salt.ext import six

# pylint: disable=import-error
try:
import django
Expand Down Expand Up @@ -118,7 +112,7 @@ def __django_auth_setup():
django_module_name, globals(), locals(), "SaltExternalAuthModel"
)
# pylint: enable=possibly-unused-variable
DJANGO_AUTH_CLASS_str = "django_auth_module.{0}".format(django_model_name)
DJANGO_AUTH_CLASS_str = "django_auth_module.{}".format(django_model_name)
DJANGO_AUTH_CLASS = eval(DJANGO_AUTH_CLASS_str) # pylint: disable=W0123


Expand Down Expand Up @@ -211,7 +205,7 @@ def acl(username):
found = False
for d in auth_dict[a.user_fk.username]:
if isinstance(d, dict):
if a.minion_or_fn_matcher in six.iterkeys(d):
if a.minion_or_fn_matcher in d.keys():
auth_dict[a.user_fk.username][a.minion_or_fn_matcher].append(
a.minion_fn
)
Expand Down
3 changes: 0 additions & 3 deletions salt/auth/file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Provide authentication using local files
Expand Down Expand Up @@ -95,8 +94,6 @@
"""

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import logging
import os
Expand Down
2 changes: 0 additions & 2 deletions salt/auth/keystone.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
"""
Provide authentication using OpenStack Keystone
:depends: - keystoneclient Python module
"""

from __future__ import absolute_import, print_function, unicode_literals

try:
from keystoneclient.v2_0 import client
Expand Down
3 changes: 0 additions & 3 deletions salt/auth/mysql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
Provide authentication using MySQL.
Expand Down Expand Up @@ -49,7 +47,6 @@
:depends: - MySQL-python Python module
"""

from __future__ import absolute_import, print_function, unicode_literals

import logging

Expand Down
Loading

0 comments on commit d9b5065

Please sign in to comment.