Exemplo n.º 1
0
 def __call__(self, request):
     if request.method == 'GET':
         key = request.GET.get('key')
         if key:
             notify = request.GET.get('notify')
             if notify is not None:
                 if notify and notify not in self.callbacks:
                     # add a notify callback
                     callback = lambda new_value, old_value, key=key: self.callback(
                         key, new_value, old_value)
                     settings.add_callback(key, callback)
                     self.callbacks[key] = callback
                 elif not notify and notify in self.callbacks:
                     # remove callback
                     settings.remove_callback(key, self.callbacks[key])
                     del self.callbacks[key]
             # return the value of a setting
             value = str(settings.get(key, ''))
             return webob.Response(json.dumps(value), content_type='json')
         else:
             # return all of the keys
             return webob.Response(json.dumps(settings),
                                   content_type='json')
     if request.method == 'POST':
         # set a value
         key = request.POST.get('key')
         if key:
             value = request.POST.get('value')
             # remove the setting if no value is given
             if value is None or value == 'undefined':
                 settings.pop(key, None)
             # figure out if the value is an int
             try:
                 value = int(value)
             except:
                 try:
                     value = float(value)
                 except:
                     pass
             # set the value
             settings[key] = value
             return  #success
     else:
         return webob.exc.HTTPMethodNotAllowed()
Exemplo n.º 2
0
 def __call__(self, request):
     if request.method == 'GET':
         key = request.GET.get('key')
         if key:
             notify = request.GET.get('notify')
             if notify is not None:
                 if notify and notify not in self.callbacks:
                     # add a notify callback
                     callback = lambda new_value, old_value, key=key: self.callback(key, new_value, old_value)
                     settings.add_callback(key, callback)
                     self.callbacks[key] = callback
                 elif not notify and notify in self.callbacks:
                     # remove callback
                     settings.remove_callback(key, self.callbacks[key])
                     del self.callbacks[key]
             # return the value of a setting
             value = str(settings.get(key, ''))
             return webob.Response(json.dumps(value), content_type='json')
         else:
             # return all of the keys
             return webob.Response(json.dumps(settings), content_type='json')
     if request.method == 'POST':
         # set a value
         key = request.POST.get('key')
         if key:
             value = request.POST.get('value')
             # remove the setting if no value is given
             if value is None or value == 'undefined':
                 settings.pop(key, None)
             # figure out if the value is an int
             try:
                 value = int(value)
             except:
                 try:
                     value = float(value)
                 except:
                     pass
             # set the value
             settings[key] = value
             return #success
     else:
         return webob.exc.HTTPMethodNotAllowed()
Exemplo n.º 3
0
 def __init__(self, rci_process_request=None):
     # TCP socket
     self.sock = None
     # Current low-level state
     self.state = self.EDP_STATE_CLOSED
     # Higher level protocol phase
     self.phase = self.PHASE_INIT
     # original URI
     self.uri = "en://" + settings['idigi_server']
     # Redirected URI (or None for first try)
     self.red_uri = None
     # Facility handlers - {facility_id: function pointer}
     self.fac = {}
     # Timeout interval (sec) for foll.
     self.rx_intvl = 0
     # RX keepalive timer - use this to send KAs to server if no messages sent in the interval.
     self.rx_ka = 0
     # Timeout interval (sec) for foll.
     self.tx_intvl = 0
     # TX keepalive timer.  This is set to WAIT * TX in the initial negotiation. 
     # If no KAs received from server in this interval, close the connection."""        
     self.tx_ka = 0
     # Received message type
     self.msg_type = 0
     # Length of the current message
     self.msg_len = 0
     # Buffer to read in current message.
     self.rxdata = ""
     # Session start time (time.time())
     self.epoch = 0
     # RCI State information for receiving RCI commands
     self.rci_state = self.RCI_STATE_READY
     # Total length of RCI message
     self.rci_len = 0
     # Buffer to store incoming RCI messages
     self.rci_rxdata = ""
     # Function pointer to handle RCI requests
     self.rci_process_request = rci_process_request
 
     # tell EDP to close and restart when any of these settings change
     settings.add_callback('idigi_server', self.settings_change)
     settings.add_callback('device_id', self.settings_change)
     settings.add_callback('mac', self.settings_change)
     settings.add_callback('device_type', self.settings_change)
     settings.add_callback('vendor_id', self.settings_change)
     settings.add_callback('idigi_certs_file', self.settings_change)
Exemplo n.º 4
0
    def __init__(self, rci_process_request=None):
        # TCP socket
        self.sock = None
        # Current low-level state
        self.state = self.EDP_STATE_CLOSED
        # Higher level protocol phase
        self.phase = self.PHASE_INIT
        # original URI
        self.uri = "en://" + settings['idigi_server']
        # Redirected URI (or None for first try)
        self.red_uri = None
        # Facility handlers - {facility_id: function pointer}
        self.fac = {}
        # Timeout interval (sec) for foll.
        self.rx_intvl = 0
        # RX keepalive timer - use this to send KAs to server if no messages sent in the interval.
        self.rx_ka = 0
        # Timeout interval (sec) for foll.
        self.tx_intvl = 0
        # TX keepalive timer.  This is set to WAIT * TX in the initial negotiation.
        # If no KAs received from server in this interval, close the connection."""
        self.tx_ka = 0
        # Received message type
        self.msg_type = 0
        # Length of the current message
        self.msg_len = 0
        # Buffer to read in current message.
        self.rxdata = ""
        # Session start time (time.time())
        self.epoch = 0
        # RCI State information for receiving RCI commands
        self.rci_state = self.RCI_STATE_READY
        # Total length of RCI message
        self.rci_len = 0
        # Buffer to store incoming RCI messages
        self.rci_rxdata = ""
        # Function pointer to handle RCI requests
        self.rci_process_request = rci_process_request

        # tell EDP to close and restart when any of these settings change
        settings.add_callback('idigi_server', self.settings_change)
        settings.add_callback('device_id', self.settings_change)
        settings.add_callback('mac', self.settings_change)
        settings.add_callback('device_type', self.settings_change)
        settings.add_callback('vendor_id', self.settings_change)
        settings.add_callback('idigi_certs_file', self.settings_change)