Example #1
0
 def _methodCall(self, name, **kwargs):
     arglist = []
     dsunittest.trace("called %s(%s)"%(name, 
             ', '.join([ ('%s=%s'%x) for x in kwargs.items()])
                       ))
     if self.scpd:
         self.scpd.checkCall(name, **kwargs)
     for k,v in kwargs.items():
         if v is None:
             arglist.append('<%s></%s>'%(k,k))
         else:
             arglist.append('<%s>%s</%s>'%(k,v,k))
     arglist = '\r\n'.join(arglist)
     # If/when stan gets broken out of Nevow, I'll look at using it here,
     # instead of the canned XML. I'm not happy to make shtoom depend on
     # Nevow for all platforms, particularly if it's only for this piece
     # of trivial code.
     body = _CannedSoapHorror % dict(arglist=arglist, 
                                    prefix=self._prefix, 
                                    method=name)
     body = body.encode('utf-8')
     headers = { 'SOAPAction': '"%s#%s"'%(self._prefix,name) } 
     req = urllib2.Request(self.url, body, headers)
     req.soapURN = self._prefix
     req.soapMethod = name
     req.soapArgs = kwargs
     return req
Example #2
0
def SOAPResponseFactory(request, response):
    urn = request.soapURN
    method = request.soapMethod
    data = response.read()
    # Netgear's on my f*****g list of death!
    if data[-1] == chr(0):
        data = data[:-1]
    bs = BeautifulSoap(data)
    key = '%sResponse'%(request.soapMethod)
    dsunittest.trace('response for %s'%request.soapMethod)
    r = bs.fetchNameNoNS(key)
    if not r:
        raise SOAPError("couldn't find %s in response"%(key))
    r = r[0]
    out = {}
    for c in r.contents:
        if isinstance(c, Tag): 
            if len(c.contents) == 1:
                if out.get(c.name):
                    print "duplicated %s in response"%(c)
                else:
                    out[c.name] = str(c.contents[0])
            elif not c.contents:
                out[c.name] = None
            else:
                print "got value for %s with contents %r"%(c.name, c)
        elif str(c).strip():
            print "got unexpected %s in response"%(c)
    return out
Example #3
0
 def _print(self, status, task):
     if task:
         taskString = str(task.id())
     else:
         taskString = ""
     dsunittest.trace("TaskList(id=%u): %s %s (active %u, waiting %u)" %
                      (id(self), status, taskString, self.activeTasks_, len(self.waitingTasks_)))
Example #4
0
def sleep(time):
    assert testingTime is not None
    event = threading.Event()
    eventQueue.put((testingTime+time, event))
    if time > 1:
        dsunittest.trace("dstime.sleep: going to sleep for %s" % time)
    event.wait()
Example #5
0
def SOAPErrorFactory(request, httperror):
    # At this point, response is a HTTPError object
    if not hasattr(httperror, "read"):
        raise SOAPError("weird http error: %s" % httperror)
    data = httperror.read()
    if data[-1] == chr(0):
        data = data[:-1]
    body = BeautifulSoap(data)
    error = body.first('errorDescription')
    if error:
        dsunittest.trace('error %s for %s'%(error, request.soapMethod))
        raise SOAPError(str(error.contents[0]))
    else:
        dsunittest.trace('unspecified error for %s'%(request.soapMethod))
        raise SOAPError(str(body))
Example #6
0
 def _deferredLookup(self, name, cls, type, timeout):
     # name is foo.bt.redheron.com
     dsunittest.trace(
         "_deferredLookup name %s, cls %s type %s timeout %s" % (name, cls, type, timeout))
     nodeAddress, serviceName = kenosis.dns.nodeAddressAndServiceNameFrom(domain=name)
     if nodeAddress:
         print "looking up nodeAddress %s for service %s" % (nodeAddress, serviceName)
         found = self.node_.findNearestNodes(nodeAddress=nodeAddress, serviceName=serviceName)
         if found:
             nodeAddress, netAddress = found[0]
             host, port = netAddress.split(":", 1)
             parts = host.split(".")
             if re.match("\d+\.\d+\.\d+\.\d+", host):
                 records = [dns.Record_A(address=host)]
             else:
                 records = [dns.Record_CNAME(host)]
         else:
             records = []
         print "found results %s, records is %s" % (found, records)
         self.records[name.lower()] = records
     return authority.PySourceAuthority._lookup(self, name, cls, type, timeout)
Example #7
0
 def func():
     for i in range(100):
         dsunittest.trace("entering")
         dsthread.blockEnterNamedSection(name="hello2")
         dsunittest.trace("leaving")
         dsthread.leaveNamedSection(name="hello2")
Example #8
0
 def removeService(self, server, type, name):
     dsunittest.trace("Service %r removed" % name)
Example #9
0
 def _set_prefix(self, prefix):
     if self._prefix is not None:
         dsunittest.trace('warning: resetting soap prefix from %s to %s'%(
                                                 self._prefix, prefix))
     self._prefix=prefix
Example #10
0
 def runOneTask(self, task):
     self.tasks_.remove(task)
     dsunittest.trace("running task: %s" % task)
     self.results_.append(task())
     self.numTasksCompleted_ += 1
Example #11
0
 def msg(self, text, system):
     dsunittest.trace("msg: %s" % text)