From 769e20f2a9749db802b544531a4ce71575d3a90a Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Tue, 31 May 2016 00:41:44 +0530 Subject: [PATCH 1/3] Py3: Use range from six.moves --- pathod/language/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pathod/language/__init__.py b/pathod/language/__init__.py index 399baa3e7..0841196e8 100644 --- a/pathod/language/__init__.py +++ b/pathod/language/__init__.py @@ -3,6 +3,7 @@ from __future__ import absolute_import import itertools import time +from six.moves import range import pyparsing as pp from . import http, http2, websockets, writer, exceptions @@ -19,7 +20,7 @@ __all__ = [ def expand(msg): times = getattr(msg, "times", None) if times: - for j_ in xrange(int(times.value)): + for j_ in range(int(times.value)): yield msg.strike_token("times") else: yield msg From 42f16d5d403667609416427d823e6793a5cc1640 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Tue, 31 May 2016 00:49:44 +0530 Subject: [PATCH 2/3] Py3: Use six.string_types instead of basestring --- pathod/language/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pathod/language/base.py b/pathod/language/base.py index 97111ed63..1f4edb6f1 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -3,6 +3,7 @@ import os import abc import pyparsing as pp +import six from six.moves import reduce from netlib.utils import escaped_str_to_bytes, bytes_to_escaped_str from netlib import human @@ -341,7 +342,7 @@ class OptionsOrValue(_Component): # it to be canonical. The user can specify a different case by using a # string value literal. self.option_used = False - if isinstance(value, basestring): + if isinstance(value, six.string_types): for i in self.options: # Find the exact option value in a case-insensitive way if i.lower() == value.lower(): From 25e30f42be1f7823a3934907dd2113969303ed94 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Tue, 31 May 2016 01:13:50 +0530 Subject: [PATCH 3/3] Py3: Use byte literals for comparison --- test/pathod/test_language_base.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/pathod/test_language_base.py b/test/pathod/test_language_base.py index 22355a3ae..47e51bb07 100644 --- a/test/pathod/test_language_base.py +++ b/test/pathod/test_language_base.py @@ -41,11 +41,11 @@ class TestTokValueLiteral: def test_espr(self): v = base.TokValueLiteral("foo") assert v.expr() - assert v.val == "foo" + assert v.val == b"foo" v = base.TokValueLiteral("foo\n") assert v.expr() - assert v.val == "foo\n" + assert v.val == b"foo\n" assert repr(v) def test_spec(self): @@ -171,19 +171,19 @@ class TestMisc: def test_generators(self): v = base.TokValue.parseString("'val'")[0] g = v.get_generator({}) - assert g[:] == "val" + assert g[:] == b"val" def test_value(self): - assert base.TokValue.parseString("'val'")[0].val == "val" - assert base.TokValue.parseString('"val"')[0].val == "val" - assert base.TokValue.parseString('"\'val\'"')[0].val == "'val'" + assert base.TokValue.parseString("'val'")[0].val == b"val" + assert base.TokValue.parseString('"val"')[0].val == b"val" + assert base.TokValue.parseString('"\'val\'"')[0].val == b"'val'" def test_value2(self): class TT(base.Value): preamble = "m" e = TT.expr() v = e.parseString("m'msg'")[0] - assert v.value.val == "msg" + assert v.value.val == b"msg" s = v.spec() assert s == e.parseString(s)[0].spec() @@ -235,8 +235,8 @@ class TestKeyValue: def test_simple(self): e = TKeyValue.expr() v = e.parseString("h'foo'='bar'")[0] - assert v.key.val == "foo" - assert v.value.val == "bar" + assert v.key.val == b"foo" + assert v.value.val == b"bar" v2 = e.parseString(v.spec())[0] assert v2.key.val == v.key.val @@ -289,9 +289,9 @@ def test_options_or_value(): "three" ] e = TT.expr() - assert e.parseString("one")[0].value.val == "one" - assert e.parseString("'foo'")[0].value.val == "foo" - assert e.parseString("'get'")[0].value.val == "get" + assert e.parseString("one")[0].value.val == b"one" + assert e.parseString("'foo'")[0].value.val == b"foo" + assert e.parseString("'get'")[0].value.val == b"get" assert e.parseString("one")[0].spec() == "one" assert e.parseString("'foo'")[0].spec() == "'foo'"