Skip to content

Commit 8b1e6e2

Browse files
committed
More bytes/str changes that fix tests on Python 3.8
1 parent 3a7529b commit 8b1e6e2

File tree

11 files changed

+27
-23
lines changed

11 files changed

+27
-23
lines changed

shinysdr/i/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def serve_web(self,
127127
self._not_finished()
128128
# TODO: See if we're reinventing bits of Twisted service stuff here
129129

130-
http_base_url = _coerce_and_validate_base_url(http_base_url, 'http_base_url', ('http', 'https'))
131-
ws_base_url = _coerce_and_validate_base_url(ws_base_url, 'ws_base_url', ('ws', 'wss'), allow_path=True)
130+
http_base_url = _coerce_and_validate_base_url(http_base_url, 'http_base_url', (b'http', b'https'))
131+
ws_base_url = _coerce_and_validate_base_url(ws_base_url, 'ws_base_url', (b'ws', b'wss'), allow_path=True)
132132

133133
if root_cap is not None:
134134
root_cap = six.text_type(root_cap)
@@ -198,11 +198,11 @@ def _coerce_and_validate_base_url(url_value, label, allowed_schemes, allow_path=
198198
if url_value is not None:
199199
url_value = str(url_value)
200200

201-
scheme, _netloc, path_bytes, _params, _query_bytes, _fragment = urlparse(bytes_or_ascii(url_value))
201+
scheme, _netloc, path_bytes, _params, _query_bytes, _fragment = urlparse(six.ensure_binary(url_value))
202202

203203
# Ensure that the protocol is compatible.
204204
if scheme.lower() not in allowed_schemes:
205-
raise ConfigException('config.serve_web: {} must be a {} URL but was {}'.format(label, ' or '.join(repr_no_string_tag(s + ':') for s in allowed_schemes), repr_no_string_tag(url_value)))
205+
raise ConfigException('config.serve_web: {} must be a {} URL but was {}'.format(label, ' or '.join(repr_no_string_tag(six.ensure_str(s) + ':') for s in allowed_schemes), repr_no_string_tag(url_value)))
206206

207207
# Ensure that there are no path components. There are two reasons for this:
208208
# 1. The client makes use of host-relative URLs.

shinysdr/i/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ def render_POST(self, request):
207207
dbdict[rkey] = record
208208
self.__database.dirty() # TODO: There is no test that this is done.
209209
self.__instantiate(rkey)
210-
url = request.prePathURL() + str(rkey)
210+
url = request.prePathURL() + six.ensure_binary(str(rkey))
211211
request.setResponseCode(http.CREATED)
212212
request.setHeader(b'Content-Type', b'text/plain')
213213
request.setHeader(b'Location', url)
214-
return url.encode()
214+
return url
215215

216216

217217
class _RecordResource(resource.Resource):

shinysdr/i/depgraph.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
from __future__ import absolute_import, division, print_function, unicode_literals
2222

23+
import six
24+
2325
from twisted.internet import defer
2426
from twisted.internet.task import deferLater
2527
from twisted.logger import Logger
@@ -115,7 +117,7 @@ def get_fitting(self, other_ff, requester_ff=None):
115117

116118
def _schedule_change(self, reason):
117119
"""Internal for _ActiveFittingHolder -- asynchronously trigger a reevaluation of the graph"""
118-
self.__log.debug('scheduled change ({reason})', reason=unicode(reason))
120+
self.__log.debug('scheduled change ({reason})', reason=six.ensure_text(reason))
119121
self.__scheduled_change.start()
120122

121123
def _mark_for_rebuild(self, fitting_factory):
@@ -153,7 +155,7 @@ def add_factory(ff, reason):
153155

154156
self.__log.debug('CHANGE: ...completed analysis')
155157

156-
newly_inactive_ffs = (set(self.__active_holders.iterkeys())
158+
newly_inactive_ffs = (set(self.__active_holders.keys())
157159
.difference(active_ffs)
158160
.union(self.__do_not_reuse))
159161
needs_configuration = newly_active_ffs or newly_inactive_ffs

shinysdr/i/network/export_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def render_GET(self, request):
204204
1: 'r',
205205
2: 2
206206
})
207-
process.pipes[0].write(self.__block.dot_graph())
207+
process.pipes[0].write(self.__block.dot_graph().encode('utf-8'))
208208
process.pipes[0].loseConnection()
209209
return NOT_DONE_YET
210210

shinysdr/i/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def test_traceback_processing(self):
354354
self.assertEqual(
355355
file_obj.getvalue()
356356
.replace(self.__files.dir, '<tempdir>')
357-
.replace(__file__, '<config.py>'),
357+
.replace(__file__, '<config.py>')
358+
.replace('shinysdr.i.config.ConfigException', 'ConfigException'), # Python 3 uses the full name
358359
textwrap.dedent("""\
359360
An error occurred while executing the ShinySDR configuration file:
360361
File "<tempdir>/config", line 1, in <module>

shinysdr/i/test_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_index_response(self):
240240
# TODO: Actually parse/check-that-parses the document
241241
self.assertSubstring(textwrap.dedent('''\
242242
<li><a href="foo%26bar/">foo&amp;bar</a></li>
243-
'''), data)
243+
'''), six.ensure_str(data))
244244

245245

246246
class TestDatabaseResource(unittest.TestCase):

shinysdr/i/test_dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_module_broken_import(self):
4747
'The following libraries/programs are not installed correctly:\n\t<dep name> (Check: shinysdr.i.test_dependencies_cases.imports failed to import (No module named nonexistent_module_in_dep).)\nPlease (re)install current versions.')
4848
else:
4949
self.assertEqual(self.t.report(),
50-
'The following libraries/programs are not installed correctly:\n\t<dep name> (Check: shinysdr.i.test_dependencies_cases.imports failed to import (No module named \'shinysdr.test.nonexistent_module_in_dep\').)\nPlease (re)install current versions.')
50+
'The following libraries/programs are not installed correctly:\n\t<dep name> (Check: shinysdr.i.test_dependencies_cases.imports failed to import (No module named \'shinysdr.nonexistent_module_in_dep\').)\nPlease (re)install current versions.')
5151

5252
def test_module_broken_other(self):
5353
self.t.check_module('shinysdr.i.test_dependencies_cases.misc', '<dep name>')

shinysdr/plugins/osmosdr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def __repr__(self):
115115

116116
def profile_from_device_string(device_string):
117117
# TODO: The input is actually an "args" string, which contains multiple devices space-separated. We should support this, but it is hard because osmosdr does not export the internal args_to_vector function and parsing it ourselves would need to be escaping-aware.
118-
params = {k: v for k, v in osmosdr.device_t(device_string).items()}
119-
for param_key in params.iterkeys():
118+
params = {k: v for k, v in osmosdr.device_t(six.ensure_str(device_string)).items()}
119+
for param_key in params:
120120
if param_key in _default_profiles:
121121
# is a device of this type
122122
return _default_profiles[param_key]
@@ -232,7 +232,7 @@ def OsmoSDRDevice(
232232
if profile is None:
233233
profile = profile_from_device_string(osmo_device)
234234

235-
source = osmosdr.source(b'numchan=1 ' + osmo_device)
235+
source = osmosdr.source(six.ensure_str('numchan=1 ' + osmo_device))
236236
if source.get_num_channels() < 1:
237237
# osmosdr.source doesn't throw an exception, allegedly because gnuradio can't handle it in a hier_block2 initializer. But we want to fail understandably, so recover by detecting it (sample rate = 0, which is otherwise nonsense)
238238
raise LookupError('OsmoSDR device not found (device string = %r)' % osmo_device)
@@ -392,7 +392,7 @@ def set_agc(self, value):
392392
label='Antenna')
393393
def get_antenna(self):
394394
if self.__source is None: return ''
395-
return six.text_type(self.__source.get_antenna(ch), 'ascii')
395+
return six.ensure_text(self.__source.get_antenna(ch), 'ascii')
396396

397397
@setter
398398
def set_antenna(self, value):

shinysdr/plugins/rtl_433.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, mode='433', input_rate=0, context=None):
9797
args=[
9898
b'env', b'rtl_433',
9999
b'-F', b'json', # output format
100-
b'-r', str(demod_rate) + b'sps:iq:cf32:-', # specify input format and to use stdin
100+
b'-r', b'%dsps:iq:cf32:-' % (demod_rate), # specify input format and to use stdin
101101
b'-M', 'newmodel',
102102
],
103103
childFDs={

shinysdr/test_devices.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from __future__ import absolute_import, division, print_function, unicode_literals
2121

22+
import six
2223
from twisted.trial import unittest
2324

2425
from gnuradio import blocks
@@ -121,15 +122,15 @@ def test_components_disjoint(self):
121122
Device(components={'b': StubComponent()})
122123
])
123124
self.assertEqual(d, IDevice(d))
124-
self.assertEqual(sorted(d.get_components_dict().iterkeys()), ['a', 'b'])
125+
self.assertEqual(sorted(six.iterkeys(d.get_components_dict())), ['a', 'b'])
125126

126127
def test_components_conflict(self):
127128
d = merge_devices([
128129
Device(components={'a': StubComponent()}),
129130
Device(components={'a': StubComponent()})
130131
])
131132
self.assertEqual(d, IDevice(d))
132-
self.assertEqual(sorted(d.get_components_dict().iterkeys()), ['0-a', '1-a'])
133+
self.assertEqual(sorted(six.iterkeys(d.get_components_dict())), ['0-a', '1-a'])
133134

134135
def test_vfos(self):
135136
d = merge_devices([

0 commit comments

Comments
 (0)