示例#1
0
    def Download(self, xml, req):
        try:
            username = req.Username
            password = req.Password
        except:
            username = password = None

        try:
            (code, starttime,
             endtime) = self.impl.Download(command_key=req.CommandKey,
                                           file_type=req.FileType,
                                           url=req.URL,
                                           username=username,
                                           password=password,
                                           file_size=int(req.FileSize),
                                           target_filename=req.TargetFileName,
                                           delay_seconds=int(req.DelaySeconds),
                                           success_url=req.SuccessURL,
                                           failure_url=req.FailureURL)
        except core.ResourcesExceededError as e:
            return soap.SimpleFault(xml, soap.CpeFault.RESOURCES_EXCEEDED,
                                    str(e))
        except core.FileTransferProtocolError as e:
            return soap.SimpleFault(xml, soap.CpeFault.FILE_TRANSFER_PROTOCOL,
                                    str(e))

        with xml['cwmp:DownloadResponse']:
            xml.Status(str(code))
            xml.StartTime(cwmpdate.format(starttime))
            xml.CompleteTime(cwmpdate.format(endtime))
        return xml
示例#2
0
 def TransferComplete(self, command_key, faultcode, faultstring,
                      starttime=None, endtime=None):
   with self._Envelope() as xml:
     with xml['cwmp:TransferComplete']:
       xml.CommandKey(str(command_key))
       with xml['FaultStruct']:
         xml.FaultCode(str(faultcode))
         xml.FaultString(str(faultstring))
       xml.StartTime(cwmpdate.format(starttime))
       xml.CompleteTime(cwmpdate.format(endtime))
   return xml
示例#3
0
 def TransferComplete(self, command_key, faultcode, faultstring,
                      starttime=None, endtime=None):
   with self._Envelope() as xml:
     with xml['cwmp:TransferComplete']:
       xml.CommandKey(str(command_key))
       with xml['FaultStruct']:
         xml.FaultCode(str(faultcode))
         xml.FaultString(str(faultstring))
       xml.StartTime(cwmpdate.format(starttime))
       xml.CompleteTime(cwmpdate.format(endtime))
   return xml
  def testPeriodicLongInterval(self):
    ms.PERIODIC_CALLBACK = MockPeriodicCallback
    io = MockIoloop()
    cpe_ms = ms.CpeManagementServer(platform_config=FakePlatformConfig(), port=0, ping_path='/',
                                    start_periodic_session=self.start_session,
                                    ioloop=io)
    cpe_ms.PeriodicInformEnable = 'true'
    cpe_ms.PeriodicInformTime = cwmpdate.format(datetime.datetime.now())
    cpe_ms.PeriodicInformInterval = '1200'

    # Just check that the delay is reasonable
    self.assertNotEqual(io.timeout_time, datetime.timedelta(seconds=0))
示例#5
0
def Soapify(value):
    if hasattr(value, 'xsitype'):
        return (value.xsitype, str(value))
    elif isinstance(value, bool):
        return ('xsd:boolean', cwmpbool.format(value))
    elif isinstance(value, int):
        return ('xsd:unsignedInt', str(value))
    elif isinstance(value, float):
        return ('xsd:double', str(value))
    elif isinstance(value, datetime.datetime):
        return ('xsd:dateTime', cwmpdate.format(value))
    else:
        return ('xsd:string', str(value))
示例#6
0
def Soapify(value):
  if hasattr(value, 'xsitype'):
    return (value.xsitype, str(value))
  elif isinstance(value, bool):
    return ('xsd:boolean', cwmpbool.format(value))
  elif isinstance(value, int):
    return ('xsd:unsignedInt', str(value))
  elif isinstance(value, float):
    return ('xsd:double', str(value))
  elif isinstance(value, datetime.datetime):
    return ('xsd:dateTime', cwmpdate.format(value))
  else:
    return ('xsd:string', str(value))
    def testPeriodicLongInterval(self):
        ms.PERIODIC_CALLBACK = MockPeriodicCallback
        io = MockIoloop()
        cpe_ms = ms.CpeManagementServer(
            platform_config=FakePlatformConfig(),
            port=0,
            ping_path='/',
            start_periodic_session=self.start_session,
            ioloop=io)
        cpe_ms.PeriodicInformEnable = 'true'
        cpe_ms.PeriodicInformTime = cwmpdate.format(datetime.datetime.now())
        cpe_ms.PeriodicInformInterval = '1200'

        # Just check that the delay is reasonable
        self.assertNotEqual(io.timeout_time, datetime.timedelta(seconds=0))
示例#8
0
  def Download(self, xml, req):
    try:
      username = req.Username
      password = req.Password
    except:
      username = password = None

    try:
      (code, starttime, endtime) = self.impl.Download(
          command_key=req.CommandKey, file_type=req.FileType,
          url=req.URL, username=username, password=password,
          file_size=int(req.FileSize), target_filename=req.TargetFileName,
          delay_seconds=int(req.DelaySeconds),
          success_url=req.SuccessURL, failure_url=req.FailureURL)
    except core.ResourcesExceededError as e:
      return soap.SimpleFault(xml, soap.CpeFault.RESOURCES_EXCEEDED, str(e))
    except core.FileTransferProtocolError as e:
      return soap.SimpleFault(xml, soap.CpeFault.FILE_TRANSFER_PROTOCOL, str(e))

    with xml['cwmp:DownloadResponse']:
      xml.Status(str(code))
      xml.StartTime(cwmpdate.format(starttime))
      xml.CompleteTime(cwmpdate.format(endtime))
    return xml
示例#9
0
 def Inform(self,
            root,
            events=None,
            max_envelopes=1,
            current_time=None,
            retry_count=0,
            parameter_list=None):
     """Encode an Inform request to the server."""
     if not events: events = []
     if not parameter_list: parameter_list = []
     with self._Envelope() as xml:
         with xml['cwmp:Inform']:
             with xml.DeviceId:
                 try:
                     di = root.obj.Device.DeviceInfo
                 except AttributeError:
                     di = root.obj.InternetGatewayDevice.DeviceInfo
                 xml.Manufacturer(di.Manufacturer)
                 xml.OUI(di.ManufacturerOUI)
                 xml.ProductClass(di.ProductClass)
                 xml.SerialNumber(di.SerialNumber)
             soaptype = 'EventStruct[{0}]'.format(len(events))
             event_attrs = {'soap-enc:arrayType': soaptype}
             with xml.Event(**event_attrs):
                 for event in events:
                     with xml.EventStruct:
                         xml.EventCode(unicode(event[0]))
                         if event[1] is not None:
                             xml.CommandKey(unicode(event[1]))
                         else:
                             xml.CommandKey(None)
             if current_time is None:
                 current_time = time.time()
             xml.MaxEnvelopes(unicode(max_envelopes))
             xml.CurrentTime(cwmpdate.format(current_time))
             xml.RetryCount(unicode(retry_count))
             soaptype = 'cwmp:ParameterValueStruct[{0}]'.format(
                 len(parameter_list))
             parameter_list_attrs = {'soap-enc:arrayType': soaptype}
             with xml.ParameterList(**parameter_list_attrs):
                 for name, value in parameter_list:
                     with xml.ParameterValueStruct:
                         xml.Name(name)
                         soapyvalue = Soapify(value)
                         xml.Value(soapyvalue[1], xsi__type=soapyvalue[0])
     return xml
示例#10
0
 def Inform(self, root, events=[], max_envelopes=1,
            current_time=None, retry_count=0, parameter_list=[]):
   with self._Envelope() as xml:
     with xml['cwmp:Inform']:
       with xml.DeviceId:
         try:
           di = root.GetExport('Device.DeviceInfo')
         except AttributeError:
           di = root.GetExport('InternetGatewayDevice.DeviceInfo')
         xml.Manufacturer(di.Manufacturer)
         xml.OUI(di.ManufacturerOUI)
         xml.ProductClass(di.ProductClass)
         xml.SerialNumber(di.SerialNumber)
       soaptype = 'EventStruct[{0}]'.format(len(events))
       event_attrs = {'soap-enc:arrayType': soaptype}
       with xml.Event(**event_attrs):
         for event in events:
           with xml.EventStruct:
             xml.EventCode(str(event[0]))
             if event[1] is not None:
               xml.CommandKey(str(event[1]))
             else:
               xml.CommandKey(None)
       if current_time is None:
         current_time = time.time()
       xml.MaxEnvelopes(str(max_envelopes))
       xml.CurrentTime(cwmpdate.format(current_time))
       xml.RetryCount(str(retry_count))
       soaptype = 'cwmp:ParameterValueStruct[{0}]'.format(len(parameter_list))
       parameter_list_attrs = {'soap-enc:arrayType': soaptype}
       with xml.ParameterList(**parameter_list_attrs):
         for name, value in parameter_list:
           with xml.ParameterValueStruct:
             xml.Name(name)
             soapyvalue = Soapify(value)
             xml.Value(soapyvalue[1], xsi__type=soapyvalue[0])
   return xml
示例#11
0
 def testDatetimeNaive(self):
   dt = datetime.datetime(1999, 12, 31, 23, 59, 58, 999999)
   self.assertEqual('1999-12-31T23:59:58.999999Z', cwmpdate.format(dt))
   dt2 = datetime.datetime(1999, 12, 31, 23, 59, 58)
   self.assertEqual('1999-12-31T23:59:58Z', cwmpdate.format(dt2))
示例#12
0
 def testDatetimeUTC(self):
   dt = datetime.datetime(1999, 12, 31, 23, 59, 58, 999999, tzinfo=UTC())
   self.assertEqual('1999-12-31T23:59:58.999999Z', cwmpdate.format(dt))
   dt2 = datetime.datetime(1999, 12, 31, 23, 59, 58, tzinfo=UTC())
   self.assertEqual('1999-12-31T23:59:58Z', cwmpdate.format(dt2))
示例#13
0
 def testTimedelta(self):
     t = 1234567890.987654
     self.assertEqual('2009-02-13T23:31:30.987654Z', cwmpdate.format(t))
示例#14
0
 def testDatetimeOTH(self):
     dt = datetime.datetime(1999, 12, 31, 23, 59, 58, 999999, tzinfo=OTH())
     self.assertEqual('1999-12-31T23:59:58.999999+01:00',
                      cwmpdate.format(dt))
示例#15
0
 def testDatetimeUTC(self):
     dt = datetime.datetime(1999, 12, 31, 23, 59, 58, 999999, tzinfo=UTC())
     self.assertEqual('1999-12-31T23:59:58.999999Z', cwmpdate.format(dt))
     dt2 = datetime.datetime(1999, 12, 31, 23, 59, 58, tzinfo=UTC())
     self.assertEqual('1999-12-31T23:59:58Z', cwmpdate.format(dt2))
示例#16
0
 def testDatetimeNaive(self):
     dt = datetime.datetime(1999, 12, 31, 23, 59, 58, 999999)
     self.assertEqual('1999-12-31T23:59:58.999999Z', cwmpdate.format(dt))
     dt2 = datetime.datetime(1999, 12, 31, 23, 59, 58)
     self.assertEqual('1999-12-31T23:59:58Z', cwmpdate.format(dt2))
示例#17
0
 def testDatetimeNone(self):
     self.assertEqual('0001-01-01T00:00:00Z', cwmpdate.format(None))
示例#18
0
 def testDatetimeNone(self):
   self.assertEqual('0001-01-01T00:00:00Z', cwmpdate.format(None))
示例#19
0
 def testDatetimeOTH(self):
   dt = datetime.datetime(1999, 12, 31, 23, 59, 58, 999999, tzinfo=OTH())
   self.assertEqual('1999-12-31T23:59:58.999999+01:00',
                    cwmpdate.format(dt))
示例#20
0
 def testTimedelta(self):
   t = 1234567890.987654
   self.assertEqual('2009-02-13T23:31:30.987654Z', cwmpdate.format(t))