Skip to content

Commit

Permalink
Merge pull request #18 from dirk-thomas/hydro-devel
Browse files Browse the repository at this point in the history
python 3 compatibility
  • Loading branch information
dirk-thomas committed Nov 26, 2013
2 parents eef9162 + 6f38a13 commit a1ea589
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 9 additions & 6 deletions actionlib_msgs/scripts/genaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
# Author: Stuart Glaser

import sys
import cStringIO
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import re
import os, os.path
import errno
Expand All @@ -41,10 +44,10 @@
class ActionSpecException(Exception): pass

def parse_action_spec(text, package_context = ''):
pieces = [cStringIO.StringIO()]
pieces = [StringIO()]
for l in text.split('\n'):
if l.startswith(IODELIM):
pieces.append(cStringIO.StringIO())
pieces.append(StringIO())
else:
pieces[-1].write(l + '\n')
return [p.getvalue() for p in pieces]
Expand All @@ -70,15 +73,15 @@ def main():
# Try to make the directory, but silently continue if it already exists
try:
os.makedirs(output_dir)
except OSError, e:
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise

action_file = args[1]
if not action_file.endswith('.action'):
print "The file specified has the wrong extension. It must end in .action"
print("The file specified has the wrong extension. It must end in .action")
else:
filename = action_file

Expand All @@ -87,7 +90,7 @@ def main():
f.close()

name = os.path.basename(filename)[:-7]
print "Generating for action %s" % name
print("Generating for action %s" % name)

pieces = parse_action_spec(action_spec)
if len(pieces) != 3:
Expand Down
12 changes: 7 additions & 5 deletions sensor_msgs/src/sensor_msgs/point_cloud2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function

"""
Serialization of sensor_msgs.PointCloud2 messages.
Expand Down Expand Up @@ -88,9 +90,9 @@ def read_points(cloud, field_names=None, skip_nans=False, uvs=[]):
if not has_nan:
yield p
else:
for v in xrange(height):
for v in range(height):
offset = row_step * v
for u in xrange(width):
for u in range(width):
p = unpack_from(data, offset)
has_nan = False
for pv in p:
Expand All @@ -105,9 +107,9 @@ def read_points(cloud, field_names=None, skip_nans=False, uvs=[]):
for u, v in uvs:
yield unpack_from(data, (row_step * v) + (point_step * u))
else:
for v in xrange(height):
for v in range(height):
offset = row_step * v
for u in xrange(width):
for u in range(width):
yield unpack_from(data, offset)
offset += point_step

Expand Down Expand Up @@ -172,7 +174,7 @@ def _get_struct_fmt(is_bigendian, fields, field_names=None):
fmt += 'x' * (field.offset - offset)
offset = field.offset
if field.datatype not in _DATATYPES:
print >> sys.stderr, 'Skipping unknown PointField datatype [%d]' % field.datatype
print('Skipping unknown PointField datatype [%d]' % field.datatype, file=sys.stderr)
else:
datatype_fmt, datatype_length = _DATATYPES[field.datatype]
fmt += field.count * datatype_fmt
Expand Down

0 comments on commit a1ea589

Please sign in to comment.