Ejemplo n.º 1
0
    def call(self, request, device):
        if request.headers['X-ADP-Reason'] == 'Poll':
            return DummyResponse(headers=_POLL_HEADERS, data=_POLL_BODY)
        q = request.get_query_params()
        reason = q.get('reason')
        if reason == 'Poll':
            return DummyResponse(headers=_POLL_HEADERS, data=_POLL_BODY)

        if device.is_provisional():
            # tell the device to do a full snapshot upload, so that we can get the device serial and identify it
            return DummyResponse(headers=_POLL_HEADERS,
                                 data=_first_contact(request, device))

        if reason == 'ServiceRefresh':
            return DummyResponse(headers=_POLL_HEADERS,
                                 data=_service_refresh(request, device))

        lto = q.get('device_lto', -1)
        if lto != -1:
            try:
                device.lto = int(lto)
            except:
                pass

        response = self.call_upstream(request, device)
        if response.status == 200:
            # use default UTF-8 encoding
            with minidom.parseString(response.body_text()) as doc:
                if _process_xml(request, doc, device):
                    xml = doc.toxml('UTF-8')
                    response.update_body(xml)

        return response
Ejemplo n.º 2
0
	def call(self, request, device):
		if request.headers['X-ADP-Reason'] == 'Poll':
			return DummyResponse(headers = _POLL_HEADERS, data = _POLL_BODY)
		q = request.get_query_params()
		reason = q.get('reason')
		if reason == 'Poll':
			return DummyResponse(headers = _POLL_HEADERS, data = _POLL_BODY)

		if device.is_provisional():
			# tell the device to do a full snapshot upload, so that we can get the device serial and identify it
			return DummyResponse(headers = _POLL_HEADERS, data = _first_contact(request, device))

		if reason == 'ServiceRefresh':
			return DummyResponse(headers = _POLL_HEADERS, data = _service_refresh(request, device))

		lto = q.get('device_lto', -1)
		if lto != -1:
			try: device.lto = int(lto)
			except: pass

		response = self.call_upstream(request, device)
		if response.status == 200:
			# use default UTF-8 encoding
			with minidom.parseString(response.body_text()) as doc:
				if _process_xml(request, doc, device):
					xml = doc.toxml('UTF-8')
					response.update_body(xml)

		return response
Ejemplo n.º 3
0
	def call(self, request, device):
		q = request.get_query_params()
		if q.get('reason') == 'Poll':
			return DummyResponse(data = _POLL_RESPONSE)

		if device.is_provisional():
			# tell the device to do a full snapshot upload, so that we can get the device serial and identify it
			return DummyResponse(headers = { 'Content-Type': 'text/xml;charset=UTF-8' }, data = _first_contact(device))

		lto = q.get('device_lto', -1)
		if lto != -1:
			try: device.lto = int(lto)
			except: pass

		response = self.call_upstream(request, device)
		if response.status == 200:
			# use default UTF-8 encoding
			with minidom.parseString(response.body_text()) as doc:
				if _process_xml(doc, device, q.get('reason')):
					xml = doc.toxml('UTF-8')
					response.update_body(xml)

		return response