Skip to content

Commit

Permalink
Clean up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
purple4reina committed Jan 8, 2025
1 parent d604177 commit 73548c1
Showing 1 changed file with 51 additions and 131 deletions.
182 changes: 51 additions & 131 deletions datadog/util/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,122 +139,60 @@ def conditional_lru_cache(func):
else:
class Compat(types.ModuleType):

# Python 3.x
if sys.version_info[0] >= 3:
@property
def builtins(self):
import builtins
return builtins

@property
def IterableUserDict(self):
from collections import UserDict
return UserDict

@property
def configparser(self):
import configparser
return configparser

@property
def ConfigParser(self):
from configparser import ConfigParser
return ConfigParser

@property
def StringIO(self):
from io import StringIO
return StringIO

@property
def urljoin(self):
from urllib.parse import urljoin
return urljoin

@property
def urlparse(self):
from urllib.parse import urlparse
return urlparse

@property
def url_lib(self):
import urllib.request
return urllib.request

@property
def urllib(self):
import urllib
return urllib

@property
def builtins(self):
import builtins
return builtins

@property
def IterableUserDict(self):
from collections import UserDict
return UserDict

@property
def configparser(self):
import configparser
return configparser

@property
def ConfigParser(self):
from configparser import ConfigParser
return ConfigParser

@property
def StringIO(self):
from io import StringIO
return StringIO

@property
def urljoin(self):
from urllib.parse import urljoin
return urljoin

@property
def urlparse(self):
from urllib.parse import urlparse
return urlparse

@property
def url_lib(self):
import urllib.request
return urllib.request

@property
def urllib(self):
import urllib
return urllib

imap = map
get_input = input
text = str

def iteritems(self, d):
return iter(d.items())

def iternext(self, iter):
return next(iter)


# Python 2.x
else:

@property
def builtins(self):
import __builtin__
return __builtin__

@property
def configparser(self):
import ConfigParser
return ConfigParser

@property
def ConfigParser(self):
from ConfigParser import ConfigParser
return ConfigParser

@property
def StringIO(self):
from StringIO import StringIO
return StringIO

@property
def imap(self):
from itertools import imap
return imap

@property
def url_lib(self):
import urllib2
return urllib2

@property
def urljoin(self):
from urlparse import urljoin
return urljoin

@property
def urlparse(self):
from urlparse import urlparse
return urlparse

@property
def IterableUserDict(self):
from UserDict import IterableUserDict
return IterableUserDict

get_input = raw_input
text = unicode

def iteritems(self, d):
return d.iteritems()
imap = map
get_input = input
text = str

def iternext(self, iter):
return iter.next()
def iteritems(self, d):
return iter(d.items())

def iternext(self, iter):
return next(iter)

# Python >= 3.5
if sys.version_info >= (3, 5):
Expand All @@ -271,24 +209,6 @@ def iscoroutinefunction(self, *args, **kwargs):
return False


# Python >= 2.7
if sys.version_info >= (2, 7):

@property
def NullHandler(self):
from logging import NullHandler
return NullHandler

# Python 2.6.x
else:

from logging import Handler

class NullHandler(Handler):
def emit(self, record):
pass


def _is_py_version_higher_than(self, major, minor=0):
"""
Assert that the Python version is higher than `$maj.$min`.
Expand Down

0 comments on commit 73548c1

Please sign in to comment.