Executing Error in python -


import unittest  service = ('u', 'urn:schemas-upnp-org:service:switchpower:1') binary_light_type = 'urn:schemas-upnp-org:device:binarylight:1'  def on_new_device(dev):     """ callback triggered when new device found.     """     print 'got new device:', dev.udn     print "type 'list' see whole list"      if not dev:         return  def get_switch_service(device):     return device.services[service[1]]  def create_control_point():     """ creates control point , binds callbacks device events.     """     c = controlpoint()     c.subscribe('new_device_event', on_new_device)     c.subscribe('removed_device_event', on_removed_device)     return c  def main():     """ main loop iteration receiving input commands.     """     c = create_control_point()     c.start()     run_async_function(_handle_cmds, (c, ))     reactor.add_after_stop_func(c.stop)     reactor.main()   def _exit(c):     """ stops _handle_cmds loop     """     global running_handle_cmds     running_handle_cmds = false  def _search(c):     """ start searching devices of type upnp:rootdevice , repeat     search every 600 seconds (upnp default)     """     c.start_search(600, 'upnp:rootdevice')  def _get_status(c):     """ gets binary light status , print if it's on or off.     """     try:         service = get_switch_service(c.current_server)         status_response = service.getstatus()         if status_response['resultstatus'] == '1':             print 'binary light status on'         else:             print 'binary light status off'     except exception, e:         if not hasattr(c, 'current_server') or not c.current_server:             print 'binarylight device not set.please use set_light <n>'         else:             print 'error in get_status():', e  def _get_target(c):     """ gets binary light target , print if it's on or off.     """     try:         service = get_switch_service(c.current_server)         status_response = service.gettarget()         if status_response['rettargetvalue'] == '1':             print 'binary light target on'         else:             print 'binary light target off'     except exception, e:         if not hasattr(c, 'current_server') or not c.current_server:             print 'binarylight device not set.please use set_light <n>'         else:             print 'error in get_target():', e def _stop(c):     """ stop searching     """     c.stop_search()  def _list_devices(c):     """ lists devices in network.     """     k = 0     d in c.get_devices().values():         print 'device no.:', k         print 'udn:', d.udn         print 'name:', d.friendly_name         print 'device type:', d.device_type         print 'services:', d.services.keys() # print services name         print 'embedded devices:', [dev.friendly_name dev in \              d.devices.values()] # print embedded devices names         print         k += 1  running_handle_cmds = true commands = {'exit': _exit,               'search': _search,             'stop': _stop,             'list': _list_devices,               'get_status': _get_status,             'get_target': _get_target}   def _handle_cmds(c):     while running_handle_cmds:         try:             input = raw_input('>>> ').strip()             if len(input.split(" ")) > 0:                 try:                     if len(input.split(" ")) > 1:                         commands[input.split(" ")[0]](c, input.split(" ")[1])                     else:                         commands[input.split(" ")[0]](c)                 except keyerror, indexerror:                     print 'invalid command, try help'                 except typeerror:                     print 'wrong usage, try see'         except keyboardinterrupt, eoferror:             c.stop()             break      # stops main loop     reactor.main_quit()  # here's our "unit tests". class isoddtests(unittest.testcase):      def testone(self):         self.failunless(_search(c))      def testtwo(self):         self.failif(_search(upnp:rootdevice))  def main():     unittest.main() 

when try run file , throws me 2 errors:the above code wriiten test cases.

====================================================================== error: testone (__main__.isoddtests) ---------------------------------------------------------------------- traceback (most recent call last):   file "controlpt.py", line 145, in testone     self.failunless(_get_status(c)) nameerror: global name 'c' not defined  ====================================================================== error: testtwo (__main__.isoddtests) ---------------------------------------------------------------------- traceback (most recent call last):   file "controlpt.py", line 148, in testtwo     self.failif(_search(0))   file "controlpt.py", line 55, in _search     c.start_search(600, 'upnp:rootdevice') attributeerror: 'int' object has no attribute 'start_search'  ---------------------------------------------------------------------- ran 2 tests in 0.000s 

the first 1 simple: call is defined.

the second 1 simple: call object has start_search attribute.

beyond don't know. haven't explained of code , it's supposed do.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -