use six module to support python 2 and 3 instead of conditional imports

This commit is contained in:
Alexander Kukushkin
2015-07-15 12:03:28 +02:00
parent 6d1a0d2a2c
commit 9df783cf9d
7 changed files with 10 additions and 29 deletions
+2 -8
View File
@@ -1,17 +1,11 @@
import json
import logging
import psycopg2
import sys
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from six.moves.socketserver import ThreadingMixIn
from threading import Thread
if sys.hexversion >= 0x03000000:
from http.server import BaseHTTPRequestHandler, HTTPServer
from socketserver import ThreadingMixIn
else:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn
logger = logging.getLogger(__name__)
+1 -6
View File
@@ -1,13 +1,8 @@
import abc
import sys
from collections import namedtuple
from helpers.utils import calculate_ttl, sleep
if sys.hexversion >= 0x03000000:
from urllib.parse import urlparse, urlunparse, parse_qsl
else:
from urlparse import urlparse, urlunparse, parse_qsl
from six.moves.urllib_parse import urlparse, urlunparse, parse_qsl
def parse_connection_string(value):
+3 -5
View File
@@ -3,15 +3,13 @@ import os
import psycopg2
import shutil
import subprocess
import sys
import six
from helpers.utils import sleep
from six.moves.urllib_parse import urlparse
if sys.hexversion >= 0x03000000:
from urllib.parse import urlparse
if six.PY3:
long = int
else:
from urlparse import urlparse
logger = logging.getLogger(__name__)
+1
View File
@@ -3,4 +3,5 @@ dnspython
psycopg2
PyYAML
requests
six
kazoo>=2.2.1
+1
View File
@@ -3,4 +3,5 @@ dnspython3
psycopg2
PyYAML
requests
six
kazoo>=2.2.1
+1 -5
View File
@@ -4,11 +4,7 @@ import unittest
from helpers.api import RestApiHandler, RestApiServer
from test_postgresql import psycopg2_connect
if sys.hexversion >= 0x03000000:
from io import BytesIO as IO
else:
from StringIO import StringIO as IO
from six import BytesIO as IO
def throws(*args, **kwargs):
+1 -5
View File
@@ -11,16 +11,12 @@ import yaml
from patroni import Patroni, main
from helpers.dcs import Cluster, Member
from helpers.zookeeper import ZooKeeper
from six.moves import BaseHTTPServer
from test_etcd import requests_get, requests_put, requests_delete
from test_ha import true, false
from test_postgresql import Postgresql, subprocess_call, psycopg2_connect
from test_zookeeper import MockKazooClient
if sys.hexversion >= 0x03000000:
import http.server as BaseHTTPServer
else:
import BaseHTTPServer
def nop(*args, **kwargs):
pass