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 more Python2 #251

Open
wants to merge 1 commit 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
4 changes: 1 addition & 3 deletions ais/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
import codecs
import sys

import six

import ais.nmea_queue


Expand Down Expand Up @@ -100,7 +98,7 @@ def open(name, mode='r', **kwargs):

if name == '-':
fobj = sys.stdin
elif isinstance(name, six.string_types):
elif isinstance(name, str):
fobj = codecs.open(name, **kwargs)
elif hasattr(name, 'close') and \
(hasattr(name, 'next') or hasattr(name, '__next__')):
Expand Down
2 changes: 1 addition & 1 deletion ais/nmea_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

TODO(schwehr): Add support for decoding non-AIS NMEA messages (e.g. ZDA).
"""
import queue as Queue

from ais import nmea
from ais import tag_block
from ais import uscg
from ais import vdm
import six.moves.queue as Queue


class Error(Exception):
Expand Down
6 changes: 2 additions & 4 deletions ais/tag_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import hashlib
import logging
import re

import six
import six.moves.queue as Queue
import queue as Queue

import ais
from ais import nmea
Expand Down Expand Up @@ -80,7 +78,7 @@ def Parse(data):
return

result.update({k: util.MaybeToNumber(v)
for k, v in six.iteritems(result) if k in NUMERIC_FIELDS})
for k, v in result.items() if k in NUMERIC_FIELDS})

actual = nmea.Checksum(result['metadata'])
expected = result['tag_checksum'].upper()
Expand Down
6 changes: 2 additions & 4 deletions ais/uscg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
import hashlib
import logging
import re

import six
import six.moves.queue as Queue
import queue as Queue

import ais
from ais import util
Expand Down Expand Up @@ -98,7 +96,7 @@ def Parse(data):
return None

result.update({k: util.MaybeToNumber(v)
for k, v in six.iteritems(result) if k in NUMERIC_FIELDS})
for k, v in result.items() if k in NUMERIC_FIELDS})

return result

Expand Down
8 changes: 3 additions & 5 deletions ais/vdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
import hashlib
import logging
import re

import six
import six.moves.queue as Queue
import queue as Queue

import ais
from ais import nmea
Expand Down Expand Up @@ -108,7 +106,7 @@ def VdmLines(lines):
def Parse(data):
"""Unpack a NMEA VDM AIS message line(s)."""

if not isinstance(data, six.string_types):
if not isinstance(data, str):
raise NotImplementedError

try:
Expand All @@ -117,7 +115,7 @@ def Parse(data):
return

result.update({k: util.MaybeToNumber(v)
for k, v in six.iteritems(result) if k in NUMERIC_FIELDS})
for k, v in result.items() if k in NUMERIC_FIELDS})

actual = nmea.Checksum(result['vdm'])
expected = result['checksum']
Expand Down
4 changes: 2 additions & 2 deletions docs/mid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
text = td.get_text()
except AttributeError:
continue
if re.match('^\d{3}', text):
if re.match(r'^\d{3}', text):
# print 'td', td
# print text
mid_vals = [int(val) for val in text.split(',')]
Expand All @@ -47,7 +47,7 @@
mid_out.write('%s,"%s"\n' % (mid, country))
except UnicodeEncodeError:
mid_out.write('BAD mid %s\n"' % mid)
print 'BAD mid', mid
print('BAD mid', mid)

for mid in mid_vals:
try:
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
'Operating System :: iOS',
'Operating System :: POSIX',
'Programming Language :: C++',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Communications',
Expand All @@ -109,7 +108,6 @@

ext_modules=[AIS_MODULE],
packages=find_packages(exclude=['test']),
install_requires=['six'],
extras_require={
'tests': tests_require,
},
Expand Down
13 changes: 6 additions & 7 deletions test/compatibility/gpsd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os
import re
import subprocess
import six
from .. import testutils

known_problems = {
Expand Down Expand Up @@ -115,10 +114,10 @@ def Libais():

try:
while True:
gmsg = six.advance_iterator(g)
amsg = six.advance_iterator(a)
gmsg = next(g)
amsg = next(a)
while amsg['type'] != gmsg['type']:
amsg = six.advance_iterator(a)
amsg = next(a)

if gmsg['type'] in known_problems:
for key in known_problems[gmsg['type']]:
Expand Down Expand Up @@ -181,10 +180,10 @@ def Libais():

try:
while True:
gmsg = six.advance_iterator(g)
amsg = six.advance_iterator(a)
gmsg = next(g)
amsg = next(a)
while amsg['type'] != gmsg['type']:
amsg = six.advance_iterator(a)
amsg = next(a)

if gmsg['type'] in known_problems:
for key in known_problems[gmsg['type']]:
Expand Down
2 changes: 1 addition & 1 deletion test/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import contextlib
import sys
from io import StringIO

import ais

import pytest
from six.moves import StringIO


def test_open_right_object(typeexamples_nmea_path):
Expand Down
11 changes: 5 additions & 6 deletions test/nmea_queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import contextlib
import unittest
from io import StringIO

import pytest
import six
from six.moves import StringIO

import ais
from ais import nmea
Expand Down Expand Up @@ -273,10 +272,10 @@ def testMixedLines(self):


@pytest.mark.parametrize("nmea", [
six.text_type(BARE_NMEA.strip()),
six.text_type(TAG_BLOCK.strip()),
six.text_type(USCG.strip()),
six.text_type(MIXED.strip())
BARE_NMEA.strip(),
TAG_BLOCK.strip(),
USCG.strip(),
MIXED.strip()
])
def test_NmeaFile_against_queue(nmea):

Expand Down
9 changes: 4 additions & 5 deletions test/testutils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import six

known_bad = set((
'addressed',
Expand All @@ -24,7 +23,7 @@ def TextToNumber(text):
def IsNumber(value):
if isinstance(value, float):
return True
if isinstance(value, six.integer_types):
if isinstance(value, int):
return True
return False

Expand All @@ -49,10 +48,10 @@ def Compare(x, y):
return True
x = TextToNumber(x)
y = TextToNumber(y)
if isinstance(x, six.string_types) and isinstance(y, six.string_types):
if isinstance(x, str) and isinstance(y, str):
# Collapse strings to just lower case a-z to avoid simple mismatches.
new_x = re.sub(r'[^a-z]', r'', six.text_type(x).lower())
new_y = re.sub(r'[^a-z]', r'', six.text_type(y).lower())
new_x = re.sub(r'[^a-z]', r'', str(x).lower())
new_y = re.sub(r'[^a-z]', r'', str(y).lower())
if new_x == new_y:
return True
if IsNumber(x) and IsNumber(y):
Expand Down
3 changes: 1 addition & 2 deletions test/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import unittest
from ais import util
import six


class UtilTest(unittest.TestCase):
Expand All @@ -25,7 +24,7 @@ def testMaybeToNumber(self):
value = 9999999999999999999999999
value_str = '9999999999999999999999999'
self.assertEqual(util.MaybeToNumber(value_str), value)
self.assertIsInstance(util.MaybeToNumber(value_str), six.integer_types)
self.assertIsInstance(util.MaybeToNumber(value_str), int)

self.assertEqual(
util.MaybeToNumber('1e99999999999999999999999'), float('inf'))
Expand Down
5 changes: 2 additions & 3 deletions test/vdm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import unittest

from ais import vdm
import six


class TestCase(unittest.TestCase):
Expand Down Expand Up @@ -82,8 +81,8 @@ def testVdmLinesGenerator(self):
r'\g:3-3-42349,n:111460*1E\$',
)
generator = vdm.VdmLines(lines)
self.assertEqual(six.next(generator), '!AIVDM,2,2,2,B,00000000000,2*25')
self.assertRaises(StopIteration, six.next, generator)
self.assertEqual(next(generator), '!AIVDM,2,2,2,B,00000000000,2*25')
self.assertRaises(StopIteration, next, generator)


class ParseTest(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions utils/collecttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
files.append(arg)

if "help" in args:
print """Usage: collecttypes.py < INFILE.nmea > OUTFILE.nmea
print("""Usage: collecttypes.py < INFILE.nmea > OUTFILE.nmea

Collects one message of each type.
"""
""")
sys.exit(0)

types = set()
Expand Down
1 change: 0 additions & 1 deletion utils/maritime_id_codes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function

import sys
import urllib,re
Expand Down