Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ggallagher01 committed Feb 9, 2017
1 parent e99024f commit 9253224
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions clients/rospy/src/rospy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
except ImportError:
import pickle
import inspect
import hashlib
import logging
import os
import signal
Expand Down Expand Up @@ -112,7 +111,7 @@ def parse_rosrpc_uri(uri):
@raise ParameterInvalid: if uri is not a valid ROSRPC URI
"""
if uri.startswith(ROSRPC):
dest_addr = uri[len(ROSRPC):]
dest_addr = uri[len(ROSRPC):]
else:
raise ParameterInvalid("Invalid protocol for ROS service URL: %s"%uri)
try:
Expand All @@ -125,7 +124,7 @@ def parse_rosrpc_uri(uri):
return dest_addr, dest_port

#########################################################

# rospy logger
_rospy_logger = logging.getLogger("rospy.internal")

Expand All @@ -145,7 +144,7 @@ def rospyerr(msg, *args):
def rospywarn(msg, *args):
"""Internal rospy client library warn logging"""
_rospy_logger.warn(msg, *args)


def _base_logger(msg, *args, **kwargs):

Expand All @@ -170,7 +169,7 @@ def _base_logger(msg, *args, **kwargs):
logfunc = getattr(rospy_logger, level)

if throttle:
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
caller_id = _frame_record_to_caller_id(inspect.stack()[2])
_logging_throttle(caller_id, logfunc, throttle, msg, *args)
else:
logfunc(msg, *args)
Expand Down Expand Up @@ -208,20 +207,13 @@ def __call__(self, caller_id, logging_func, period, msg, *args):
now = rospy.Time.now()

last = self.last_log_entry.get(caller_id, self.LogEntry(time=None, digest=None))
digest = _get_digest(msg, *args)
digest = hash(*args + tuple([str(msg)]))

if (last.time is None or (now - last.time) > rospy.Duration(period) or digest != last.digest):
logging_func(msg, *args)
self.last_log_entry[caller_id] = self.LogEntry(time=now, digest=digest)


def _get_digest(*args):
m = hashlib.md5()
for arg in args:
m.update(str(args))
return m.hexdigest()


_logging_throttle = LoggingThrottle()


Expand Down Expand Up @@ -341,10 +333,10 @@ def configure_logging(node_name, level=logging.INFO):
class NullHandler(logging.Handler):
def emit(self, record):
pass

# keep logging happy until we have the node name to configure with
logging.getLogger('rospy').addHandler(NullHandler())
logging.getLogger('rospy').addHandler(NullHandler())


#########################################################
# Init/Shutdown/Exit API and Handlers
Expand Down Expand Up @@ -403,7 +395,7 @@ def is_shutdown_requested():
received and continues until client shutdown handlers have been
called. After client shutdown handlers have been serviced, the
is_shutdown state becomes true.
@return: True if shutdown has been requested (but possibly not yet initiated)
@rtype: bool
"""
Expand Down Expand Up @@ -452,7 +444,7 @@ def add_client_shutdown_hook(h):
Add client method to invoke when system shuts down. Unlike
L{add_shutdown_hook} and L{add_preshutdown_hooks}, these methods
will be called before any rospy internal shutdown code.
@param h: function with zero args
@type h: fn()
"""
Expand All @@ -463,7 +455,7 @@ def add_preshutdown_hook(h):
Add method to invoke when system shuts down. Unlike
L{add_shutdown_hook}, these methods will be called before any
other shutdown hooks.
@param h: function that takes in a single string argument (shutdown reason)
@type h: fn(str)
"""
Expand Down Expand Up @@ -556,17 +548,17 @@ def register_signals():
"""
_signalChain[signal.SIGTERM] = signal.signal(signal.SIGTERM, _ros_signal)
_signalChain[signal.SIGINT] = signal.signal(signal.SIGINT, _ros_signal)

# Validators ######################################

def is_topic(param_name):
"""
Validator that checks that parameter is a valid ROS topic name
"""
"""
def validator(param_value, caller_id):
v = valid_name_validator_resolved(param_name, param_value, caller_id)
if param_value == '/':
raise ParameterInvalid("ERROR: parameter [%s] cannot be the global namespace"%param_name)
raise ParameterInvalid("ERROR: parameter [%s] cannot be the global namespace"%param_name)
return v
return validator

Expand All @@ -581,4 +573,3 @@ def xmlrpcapi(uri):
if not uriValidate[0] or not uriValidate[1]:
return None
return xmlrpcclient.ServerProxy(uri)

0 comments on commit 9253224

Please sign in to comment.