python3: Avoid applying ord() to integers
In python3, b'abc'[0] isn't a string but a int value and ord() should not be used. Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
2749f9d4ed
commit
f4b405f31a
@ -14,8 +14,15 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from ryu.lib import addrconv
|
from ryu.lib import addrconv
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
_ord = int
|
||||||
|
else:
|
||||||
|
_ord = ord
|
||||||
|
|
||||||
# string representation
|
# string representation
|
||||||
HADDR_PATTERN = r'([0-9a-f]{2}:){5}[0-9a-f]{2}'
|
HADDR_PATTERN = r'([0-9a-f]{2}:){5}[0-9a-f]{2}'
|
||||||
|
|
||||||
@ -28,7 +35,7 @@ UNICAST = '01:00:00:00:00:00'
|
|||||||
|
|
||||||
|
|
||||||
def is_multicast(addr):
|
def is_multicast(addr):
|
||||||
return bool(ord(addr[0]) & 0x01)
|
return bool(_ord(addr[0]) & 0x01)
|
||||||
|
|
||||||
|
|
||||||
def haddr_to_str(addr):
|
def haddr_to_str(addr):
|
||||||
@ -52,5 +59,5 @@ def haddr_to_bin(string):
|
|||||||
|
|
||||||
|
|
||||||
def haddr_bitand(addr, mask):
|
def haddr_bitand(addr, mask):
|
||||||
return ''.join(chr(ord(a) & ord(m)) for (a, m)
|
return b''.join(six.int2byte(_ord(a) & _ord(m)) for (a, m)
|
||||||
in zip(addr, mask))
|
in zip(addr, mask))
|
||||||
|
@ -750,7 +750,7 @@ class _AddrPrefix(StringifyMixin):
|
|||||||
# clear trailing bits in the last octet.
|
# clear trailing bits in the last octet.
|
||||||
# rfc doesn't require this.
|
# rfc doesn't require this.
|
||||||
mask = 0xff00 >> (self.length % 8)
|
mask = 0xff00 >> (self.length % 8)
|
||||||
last_byte = chr(ord(bin_addr[byte_length - 1]) & mask)
|
last_byte = chr(six.indexbytes(bin_addr, byte_length - 1) & mask)
|
||||||
bin_addr = bin_addr[:byte_length - 1] + last_byte
|
bin_addr = bin_addr[:byte_length - 1] + last_byte
|
||||||
self.addr = self._from_bin(bin_addr)
|
self.addr = self._from_bin(bin_addr)
|
||||||
|
|
||||||
|
@ -24,12 +24,18 @@
|
|||||||
# mask is None if no mask.
|
# mask is None if no mask.
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
import six
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from ryu.ofproto import ofproto_common
|
from ryu.ofproto import ofproto_common
|
||||||
from ryu.lib.pack_utils import msg_pack_into
|
from ryu.lib.pack_utils import msg_pack_into
|
||||||
from ryu.lib import type_desc
|
from ryu.lib import type_desc
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
_ord = int
|
||||||
|
else:
|
||||||
|
_ord = ord
|
||||||
|
|
||||||
# 'OFPXXC_EXPERIMENTER' has not corresponding field in the specification.
|
# 'OFPXXC_EXPERIMENTER' has not corresponding field in the specification.
|
||||||
# This is transparently value for Experimenter class ID for OXM/OXS.
|
# This is transparently value for Experimenter class ID for OXM/OXS.
|
||||||
OFPXXC_EXPERIMENTER = 0xffff
|
OFPXXC_EXPERIMENTER = 0xffff
|
||||||
@ -122,7 +128,7 @@ def _normalize_user(oxx, mod, k, uv):
|
|||||||
return (k, uv)
|
return (k, uv)
|
||||||
# apply mask
|
# apply mask
|
||||||
if m is not None:
|
if m is not None:
|
||||||
v = ''.join(chr(ord(x) & ord(y)) for (x, y) in itertools.izip(v, m))
|
v = b''.join(six.int2byte(_ord(x) & _ord(y)) for (x, y) in zip(v, m))
|
||||||
try:
|
try:
|
||||||
to_user = getattr(mod, oxx + '_to_user')
|
to_user = getattr(mod, oxx + '_to_user')
|
||||||
(k2, uv2) = to_user(n, v, m)
|
(k2, uv2) = to_user(n, v, m)
|
||||||
|
Loading…
Reference in New Issue
Block a user