Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Python2 crumbs #2833

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions contrib/memcache_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
CAN_LOCK = False

if sys.version_info[0] == 3:
xrange = range
# This `file` hack avoids linter warnings under Python-3,
# but this code likely only works with Python-2.
file = None
Expand Down Expand Up @@ -144,7 +143,7 @@ def __readHeader(fh):
packedMetadata = fh.read(metadataSize)
(lastUpdate,maxRetention,xff,archiveCount) = struct.unpack(metadataFormat,packedMetadata)
archives = []
for i in xrange(archiveCount):
for i in range(archiveCount):
packedArchiveInfo = fh.read(archiveInfoSize)
(offset,secondsPerPoint,points) = struct.unpack(archiveInfoFormat,packedArchiveInfo)
archiveInfo = {
Expand Down Expand Up @@ -256,7 +255,7 @@ def __propagate(fh,timestamp,xff,higher,lower):
neighborValues = [None] * points
currentInterval = lowerIntervalStart
step = higher['secondsPerPoint']
for i in xrange(0,len(unpackedSeries),2):
for i in range(0,len(unpackedSeries),2):
pointTime = unpackedSeries[i]
if pointTime == currentInterval:
neighborValues[i/2] = unpackedSeries[i+1]
Expand Down Expand Up @@ -533,7 +532,7 @@ def fetch(path,fromTime,untilTime=None):
valueList = [None] * points #pre-allocate entire list for speed
currentInterval = fromInterval
step = archive['secondsPerPoint']
for i in xrange(0,len(unpackedSeries),2):
for i in range(0,len(unpackedSeries),2):
pointTime = unpackedSeries[i]
if pointTime == currentInterval:
pointValue = unpackedSeries[i+1]
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python

from __future__ import with_statement

import os
from configparser import ConfigParser, DuplicateSectionError # Python 3
from configparser import ConfigParser, DuplicateSectionError

from glob import glob
from collections import defaultdict
from io import StringIO # Python 3
from io import StringIO

# Graphite historically has an install prefix set in setup.cfg. Being in a
# configuration file, it's not easy to override it or unset it (for installing
Expand Down
2 changes: 0 additions & 2 deletions webapp/graphite/account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-06-14 11:22
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
Expand Down
5 changes: 1 addition & 4 deletions webapp/graphite/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
limitations under the License."""

from django.contrib.auth import authenticate, login, logout
try:
from django.urls import reverse
except ImportError: # Django < 1.10
from django.urls import reverse
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render
from graphite.user_util import getProfile, isAuthenticated
Expand Down
7 changes: 1 addition & 6 deletions webapp/graphite/carbonlink.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pickle
import time
import socket
import struct
Expand All @@ -11,12 +12,6 @@
from graphite.singleton import ThreadSafeSingleton


try:
import six.moves.cPickle as pickle
except ImportError:
import pickle


def load_keyfunc():
if settings.CARBONLINK_HASHING_KEYFUNC:
module_path, func_name = settings.CARBONLINK_HASHING_KEYFUNC.rsplit(':', 1)
Expand Down
2 changes: 0 additions & 2 deletions webapp/graphite/dashboard/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-06-14 11:22
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
2 changes: 0 additions & 2 deletions webapp/graphite/events/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-06-14 11:22
from __future__ import unicode_literals

from django.db import migrations, models
import tagging.fields

Expand Down
2 changes: 0 additions & 2 deletions webapp/graphite/finders/ceres.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import os.path

# Use the built-in version of walk if possible, otherwise
Expand Down
1 change: 0 additions & 1 deletion webapp/graphite/functions/safe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# make / work consistently between python 2.x and 3.x
# https://www.python.org/dev/peps/pep-0238/
from __future__ import division
from functools import reduce
import math

Expand Down
5 changes: 1 addition & 4 deletions webapp/graphite/middleware.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from graphite.logger import log
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError: # Django < 1.10
MiddlewareMixin = object
from django.utils.deprecation import MiddlewareMixin


class LogExceptionsMiddleware(MiddlewareMixin):
Expand Down
2 changes: 0 additions & 2 deletions webapp/graphite/readers/ceres.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from graphite.intervals import Interval, IntervalSet
from graphite.readers.utils import merge_with_carbonlink, BaseReader

Expand Down
6 changes: 1 addition & 5 deletions webapp/graphite/readers/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from __future__ import division

import abc

from graphite.logger import log


class BaseReader(object):
__metaclass__ = abc.ABCMeta

class BaseReader(metaclass=abc.ABCMeta):
supported = True

@abc.abstractmethod
Expand Down
1 change: 0 additions & 1 deletion webapp/graphite/readers/whisper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import time

# Use the built-in version of scandir/stat if possible, otherwise
Expand Down
6 changes: 1 addition & 5 deletions webapp/graphite/render/datalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""
from __future__ import division

import collections
import re
Expand All @@ -26,10 +25,7 @@
from graphite.util import timebounds, logtime


try:
from collections import UserDict
except ImportError:
from UserDict import IterableUserDict as UserDict
from collections import UserDict


class Tags(UserDict):
Expand Down
12 changes: 2 additions & 10 deletions webapp/graphite/render/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@

# make / work consistently between python 2.x and 3.x
# https://www.python.org/dev/peps/pep-0238/
from __future__ import division

import math
import random
import re
import time

from datetime import datetime, timedelta
from functools import reduce
from six.moves import range, zip
import six
try:
from itertools import izip, izip_longest
except ImportError:
# Python 3
from itertools import zip_longest as izip_longest
izip = zip
from itertools import zip_longest as izip_longest
from os import environ

from django.conf import settings
Expand Down Expand Up @@ -131,7 +123,7 @@ def normalize(seriesLists):

def matchSeries(seriesList1, seriesList2):
assert len(seriesList2) == len(seriesList1), "The number of series in each argument must be the same"
return izip(sorted(seriesList1, key=lambda a: a.name), sorted(seriesList2, key=lambda a: a.name))
return zip(sorted(seriesList1, key=lambda a: a.name), sorted(seriesList2, key=lambda a: a.name))


def trimRecent(seriesList):
Expand Down
3 changes: 1 addition & 2 deletions webapp/graphite/render/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import itertools
import math
import re
from configparser import ConfigParser
from datetime import datetime, timedelta

from six.moves import range, zip
from six.moves.urllib.parse import unquote_plus
from six.moves.configparser import ConfigParser
from django.conf import settings
import pytz
import six
Expand Down
15 changes: 4 additions & 11 deletions webapp/graphite/render/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from hashlib import md5
from itertools import chain
import bisect
import sys

try:
import mmh3
Expand All @@ -38,16 +37,10 @@ def fnv32a(data, seed=0x811c9dc5):
hval = seed
fnv_32_prime = 0x01000193
uint32_max = 2 ** 32
if sys.version_info >= (3, 0):
# data is a bytes object, s is an integer
for s in data:
hval = hval ^ s
hval = (hval * fnv_32_prime) % uint32_max
else:
# data is an str object, s is a single character
for s in data:
hval = hval ^ ord(s)
hval = (hval * fnv_32_prime) % uint32_max
# data is a bytes object, s is an integer
for s in data:
hval = hval ^ s
hval = (hval * fnv_32_prime) % uint32_max
return hval


Expand Down
1 change: 0 additions & 1 deletion webapp/graphite/render/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.utils.cache import add_never_cache_headers, patch_response_headers
from six.moves import zip


loadFunctions()
Expand Down
6 changes: 1 addition & 5 deletions webapp/graphite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
limitations under the License."""
# Django settings for graphite project.
# DO NOT MODIFY THIS FILE DIRECTLY - use local_settings.py instead
from __future__ import print_function
import os
import sys
from os.path import abspath, dirname, join
from warnings import warn
from importlib import import_module

from django import VERSION as DJANGO_VERSION
try:
from django.urls import reverse_lazy
except ImportError: # Django < 1.10
from django.urls import reverse_lazy
from django.urls import reverse_lazy


GRAPHITE_WEB_APP_SETTINGS_LOADED = False
Expand Down
21 changes: 5 additions & 16 deletions webapp/graphite/storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import
import os
import random
import sys
import time
import traceback
import types
Expand All @@ -13,12 +11,8 @@

from django.conf import settings
from django.core.cache import cache
import six

try:
from importlib import import_module
except ImportError: # python < 2.7 compatibility
from django.utils.importlib import import_module
from importlib import import_module

from graphite.logger import log
from graphite.errors import InputParameterError
Expand All @@ -40,14 +34,9 @@ def get_finders(finder_path):

# monkey patch so legacy finders will work
finder = cls()
if sys.version_info[0] >= 3:
finder.fetch = types.MethodType(BaseFinder.fetch, finder)
finder.find_multi = types.MethodType(BaseFinder.find_multi, finder)
finder.get_index = types.MethodType(BaseFinder.get_index, finder)
else:
finder.fetch = types.MethodType(BaseFinder.fetch.__func__, finder)
finder.find_multi = types.MethodType(BaseFinder.find_multi.__func__, finder)
finder.get_index = types.MethodType(BaseFinder.get_index.__func__, finder)
finder.fetch = types.MethodType(BaseFinder.fetch, finder)
finder.find_multi = types.MethodType(BaseFinder.find_multi, finder)
finder.get_index = types.MethodType(BaseFinder.get_index, finder)

return [finder]

Expand Down Expand Up @@ -307,7 +296,7 @@ def _list_nodes(self, query, nodes_by_path):
# Reduce matching nodes for each path to a minimal set
found_branch_nodes = set()

items = list(six.iteritems(nodes_by_path))
items = list(nodes_by_path.items())
random.shuffle(items)

for path, nodes in items:
Expand Down
8 changes: 1 addition & 7 deletions webapp/graphite/tags/http.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import absolute_import

from binascii import b2a_base64
import sys

from graphite.http_pool import http
from graphite.util import json
Expand All @@ -24,10 +21,7 @@ def request(self, method, url, fields, requestContext=None):
headers = requestContext.get('forwardHeaders') if requestContext else {}
if 'Authorization' not in headers and self.username and self.password:
user_pw = '%s:%s' % (self.username, self.password)
if sys.version_info[0] >= 3:
user_pw_b64 = b2a_base64(user_pw.encode('utf-8')).decode('ascii')
else:
user_pw_b64 = user_pw.encode('base64')
user_pw_b64 = b2a_base64(user_pw.encode('utf-8')).decode('ascii')
headers['Authorization'] = 'Basic ' + user_pw_b64

req_fields = []
Expand Down
2 changes: 0 additions & 2 deletions webapp/graphite/tags/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.11 on 2017-08-31 17:38
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

Expand Down
5 changes: 1 addition & 4 deletions webapp/graphite/tags/redis.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import absolute_import

import re
import bisect
import sys

from graphite.tags.base import BaseTagDB, TaggedSeries

Expand Down Expand Up @@ -33,7 +30,7 @@ def __init__(self, settings, *args, **kwargs):
port=settings.TAGDB_REDIS_PORT,
db=settings.TAGDB_REDIS_DB,
password=settings.TAGDB_REDIS_PASSWORD,
decode_responses=(sys.version_info[0] >= 3),
decode_responses=True,
)

def _find_series(self, tags, requestContext=None):
Expand Down
Loading