Skip to content

Commit 7455589

Browse files
author
Bono de Visser
authored
Merge pull request #2 from ByteInternet/python3
Python3 compatibility
2 parents b70ea45 + 9c675db commit 7455589

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

runtests.py

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from varnishadm import VarnishManager
22
import unittest
33

4-
ADDR = raw_input('Varnish Management Address (ip:port) [localhost:2000]: ')
4+
ADDR = input('Varnish Management Address (ip:port) [localhost:2000]: ')
55
if not ADDR: ADDR = 'localhost:2000'
6-
WEB_ADDR = raw_input('Varnish Instance Address (ip:port) [localhost:8080]: ')
6+
WEB_ADDR = input('Varnish Instance Address (ip:port) [localhost:8080]: ')
77
if not WEB_ADDR: WEB_ADDR = 'localhost:8080'
88

99
class VarnishTests(unittest.TestCase):
@@ -13,7 +13,7 @@ def setUp(self):
1313
def test_ping(self):
1414
result = self.manager.run('ping')[0][0]
1515
self.assertEqual(len(result), 2)
16-
self.assert_(map(lambda x: isinstance(x, float), (True,True)))
16+
self.assertTrue([isinstance(x, float) for x in (True,True)])
1717

1818
def test_purge(self):
1919
resp = self.manager.run(
@@ -23,7 +23,7 @@ def test_purge(self):
2323
def test_ban(self):
2424
regex = '^/banned/*'
2525
self.manager.run('ban.url', regex)
26-
self.assert_(regex, str(self.manager.run('ban.list')))
26+
self.assertTrue(regex, str(self.manager.run('ban.list')))
2727

2828
def test_multiple(self):
2929
result = self.manager.run(( ('ping',None),('ping',None) ))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='python-varnishadm',
5-
version='0.2.2',
5+
version='1.0.0',
66
long_description=open('README.rst').read(),
77
description='Simple Python interface for the Varnish management port',
88
author='Justin Quick',

varnishadm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"""
3434
from telnetlib import Telnet
3535
from threading import Thread
36-
from httplib import HTTPConnection
37-
from urlparse import urlparse
36+
from http.client import HTTPConnection
37+
from urllib.parse import urlparse
3838
from hashlib import sha256
3939
import logging
4040

@@ -64,7 +64,7 @@ def http_purge_url(url):
6464

6565
class VarnishHandler(Telnet):
6666
def __init__(self, host_port_timeout, secret=None, **kwargs):
67-
if isinstance(host_port_timeout, basestring):
67+
if isinstance(host_port_timeout, str):
6868
host_port_timeout = host_port_timeout.split(':')
6969
Telnet.__init__(self, *host_port_timeout)
7070
(status, length), content = self._read()
@@ -74,7 +74,7 @@ def __init__(self, host_port_timeout, secret=None, **kwargs):
7474
logging.error('Connecting failed with status: %i' % status)
7575

7676
def _read(self):
77-
(status, length), content = map(int, self.read_until('\n').split()), ''
77+
(status, length), content = list(map(int, self.read_until('\n').split())), ''
7878
while len(content) < length:
7979
content += self.read_some()
8080
return (status, length), content[:-1]
@@ -90,7 +90,7 @@ def fetch(self, command):
9090
buffer = self.read_until('\n').strip()
9191
if len(buffer):
9292
break
93-
status, length = map(int, buffer.split())
93+
status, length = list(map(int, buffer.split()))
9494
content = ''
9595

9696
if status != 200:

0 commit comments

Comments
 (0)