示例#1
0
 def testUnsupportedProtocolExtensionError(self):
     try:
         protocol.getExtension("__invalid_extension__")
     except extension.UnsupportedProtocolExtensionError:
         pass
     except:
         self.failIf(True)
     else:
         self.failIf(True)
示例#2
0
 def testUnsupportedProtocolExtensionError(self):
     try:
         protocol.getExtension("__invalid_extension__")
     except extension.UnsupportedProtocolExtensionError:
         pass
     except:
         self.failIf(True)
     else:
         self.failIf(True)
示例#3
0
 def extension(self, name, **params):
     ext = protocol.getExtension(name)
     status, params = ext.response(**ext.request(**params))
     result = [status]
     for name in sorted(params):
         result.append(params[name])
     return tuple(result) if len(result) else status
示例#4
0
 def setUp(self):
     self.dirFiles = protocol.getExtension("dirfiles")
     self.failUnless(self.dirFiles)
     self._fileNameMaps = {}
     for item in self._TEST_FILE_TREE:
         dir, file = item[:-1], item[-1]
         dir = os.path.join(self._TEST_ROOT_DIR, *dir)
         if not os.path.exists(dir):
             os.makedirs(dir)
         if isinstance(file, (tuple, list)):
             path = os.path.join(dir, file[0])
             os.symlink(os.path.join(*file[1]), path)
         else:
             path = os.path.join(dir, file)
             size = random.randint(256, 4096)
             fd = open(path, "wb")
             try:
                 n = 0
                 k = random.randint(len(self._TEST_CHAR_SET) / 4, len(self._TEST_CHAR_SET) / 2)
                 while n < size:
                     fd.write("".join(random.sample(self._TEST_CHAR_SET, k)))
                     n += k
             finally:
                 fd.close()
         self._fileNameMaps[os.path.basename(path)] = path
示例#5
0
 def setUp(self):
     self.dirFiles = protocol.getExtension("dirfiles")
     self.failUnless(self.dirFiles)
     self._fileNameMaps = {}
     for item in self._TEST_FILE_TREE:
         dir, file = item[:-1], item[-1]
         dir = os.path.join(self._TEST_ROOT_DIR, *dir)
         if not os.path.exists(dir):
             os.makedirs(dir)
         if isinstance(file, (tuple, list)):
             path = os.path.join(dir, file[0])
             os.symlink(os.path.join(*file[1]), path)
         else:
             path = os.path.join(dir, file)
             size = random.randint(256, 4096)
             fd = open(path, "wb")
             try:
                 n = 0
                 k = random.randint(
                     len(self._TEST_CHAR_SET) / 4,
                     len(self._TEST_CHAR_SET) / 2)
                 while n < size:
                     fd.write(''.join(random.sample(self._TEST_CHAR_SET,
                                                    k)))
                     n += k
             finally:
                 fd.close()
         self._fileNameMaps[os.path.basename(path)] = path
示例#6
0
 def extension(self, name, **params):
     ext = protocol.getExtension(name)
     status, params = ext.response(**ext.request(**params))
     result = [status]
     for name in sorted(params):
         result.append(params[name])
     return tuple(result) if len(result) else status
示例#7
0
    def requestExtension(self, name, **params):
        '''
        Sends a request defined by a protocol extension of the given name and
        the specified parameters.

        :param name: A name of a protocol extension
        :type name: string
        :param params: Parameters of a request
        :type params: dictionary
        :return: Id of the sent request
        :rtype: integer
        '''
        if name not in self.extensions:
            raise protocol.extension.UnsupportedProtocolExtensionError(name)
        return self.request(protocol.MSG_TARGET_EXTENSION, name,
                            protocol.getExtension(name).request(**params))
示例#8
0
    def requestExtension(self, name, **params):
        '''
        Sends a request defined by a protocol extension of the given name and
        the specified parameters.

        :param name: A name of a protocol extension
        :type name: string
        :param params: Parameters of a request
        :type params: dictionary
        :return: Id of the sent request
        :rtype: integer
        '''
        if name not in self.extensions:
            raise protocol.extension.UnsupportedProtocolExtensionError(name)
        return self.request(protocol.MSG_TARGET_EXTENSION, name,
                            protocol.getExtension(name).request(**params))
示例#9
0
 def __call__(self, request):
     '''
     Processes the given request.
     '''
     log.debug(locals())
     extras = {"status": False}
     if request.target == protocol.MSG_TARGET_ACCESSIBILITY:
         if request.name == protocol.MSG_NAME_GET:
             params = {}
             for param in request.include:
                 params[str(param)] = True
             status, accessible = accessibilityGet(self, request.path,
                                                   request.depth, **params)
             extras = {"status": status, "accessible": accessible}
         elif request.name == protocol.MSG_NAME_SEARCH:
             status, accessible = accessibilitySearch(
                 self, request.path, request.method, **request.predicates)
             extras = {"status": status, "accessible": accessible}
         elif request.name == protocol.MSG_NAME_PUT:
             if hasattr(request, 'text'):
                 status = accessibilityPutText(self, request.path,
                                               request.text)
             elif hasattr(request, 'value'):
                 status = accessibilityPutValue(self, request.path,
                                                request.value)
             else:
                 raise protocol.UnsupportedMessageError(
                     request.type, request.target, request.name,
                     *request.getParams())
             extras = {"status": status}
         elif request.name == protocol.MSG_NAME_EXEC:
             if hasattr(request, 'action'):
                 status = accessibilityExecAction(self, request.path,
                                                  request.action)
             elif (hasattr(request, 'keycode')
                   and hasattr(request, 'modifiers')):
                 status = accessibilityExecKeyboard(self, request.path,
                                                    request.keycode,
                                                    request.modifiers)
             elif (hasattr(request, 'event') and hasattr(request, 'button')
                   and hasattr(request, 'coordinates')):
                 status = accessibilityExecMouse(self, request.path,
                                                 request.event,
                                                 request.button,
                                                 request.coordinates)
             else:
                 raise protocol.UnsupportedMessageError(
                     request.type, request.target, request.name,
                     *request.getParams())
             extras = {"status": status}
         else:
             raise protocol.UnsupportedMessageError(request.type,
                                                    request.target,
                                                    request.name,
                                                    *request.getParams())
     elif request.target == protocol.MSG_TARGET_SYSTEM:
         if request.name == protocol.MSG_NAME_GET:
             status, data = systemGet(self, request.path)
             extras = {"status": status, "data": data}
         elif request.name == protocol.MSG_NAME_PUT:
             status = systemPut(self, request.path, request.data)
             extras = {"status": status}
         elif request.name == protocol.MSG_NAME_EXEC:
             status, stdout, stderr = systemExec(self, request.command,
                                                 request.wait)
             extras = {"status": status, "stdout": stdout, "stderr": stderr}
         else:
             raise protocol.UnsupportedMessageError(request.type,
                                                    request.target,
                                                    request.name,
                                                    *request.getParams())
     elif request.target == protocol.MSG_TARGET_EXTENSION:
         params = {}
         for name in request.getParams():
             params[name] = getattr(request, name)
         try:
             ext = protocol.getExtension(request.name)
         except:
             protocol.UnsupportedMessageError(request.type, request.target,
                                              request.name,
                                              *request.getParams())
         status, extras = ext.response(**params)
         extras["status"] = status
     else:
         raise protocol.UnsupportedMessageError(request.type,
                                                request.target,
                                                request.name,
                                                *request.getParams())
     return protocol.create(protocol.MSG_TYPE_RESPONSE, request.target,
                            request.name, **extras)
示例#10
0
 def testGetExtension(self):
     try:
         ext = protocol.getExtension(_TestProtocolExtension.name)
     except extension.UnsupportedProtocolExtensionError:
         self.failIf(True)
     self.failUnless(isinstance(ext, _TestProtocolExtension))
示例#11
0
 def testGetExtension(self):
     try:
         ext = protocol.getExtension(_TestProtocolExtension.name)
     except extension.UnsupportedProtocolExtensionError:
         self.failIf(True)
     self.failUnless(isinstance(ext, _TestProtocolExtension))
示例#12
0
 def __call__(self, request):
     '''
     Processes the given request.
     '''
     log.debug(locals())
     extras = {
         "status": False
     }
     if request.target == protocol.MSG_TARGET_ACCESSIBILITY:
         if request.name == protocol.MSG_NAME_GET:
             params = {}
             for param in request.include:
                 params[str(param)] = True
             status, accessible = accessibilityGet(self, request.path,
                                                   request.depth,
                                                   **params)
             extras = {
                 "status": status,
                 "accessible": accessible
             }
         elif request.name == protocol.MSG_NAME_SEARCH:
             status, accessible = accessibilitySearch(self, request.path,
                                                      request.method,
                                                      **request.predicates)
             extras = {
                 "status": status,
                 "accessible": accessible
             }
         elif request.name == protocol.MSG_NAME_PUT:
             if hasattr(request, 'text'):
                 status = accessibilityPutText(self, request.path,
                                               request.text)
             elif hasattr(request, 'value'):
                 status = accessibilityPutValue(self, request.path,
                                                request.value)
             else:
                 raise protocol.UnsupportedMessageError(request.type,
                                                     request.target,
                                                     request.name,
                                                     *request.getParams())
             extras = {
                 "status": status
             }
         elif request.name == protocol.MSG_NAME_EXEC:
             if hasattr(request, 'action'):
                 status = accessibilityExecAction(self, request.path,
                                                  request.action)
             elif (hasattr(request, 'keycode') and
                   hasattr(request, 'modifiers')):
                 status = accessibilityExecKeyboard(self, request.path,
                                                    request.keycode,
                                                    request.modifiers)
             elif (hasattr(request, 'event') and
                   hasattr(request, 'button') and
                   hasattr(request, 'coordinates')):
                 status = accessibilityExecMouse(self, request.path,
                                                 request.event,
                                                 request.button,
                                                 request.coordinates)
             else:
                 raise protocol.UnsupportedMessageError(request.type,
                                                     request.target,
                                                     request.name,
                                                     *request.getParams())
             extras = {
                 "status": status
             }
         else:
             raise protocol.UnsupportedMessageError(request.type,
                                                    request.target,
                                                    request.name,
                                                    *request.getParams())
     elif request.target == protocol.MSG_TARGET_SYSTEM:
         if request.name == protocol.MSG_NAME_GET:
             status, data = systemGet(self, request.path)
             extras = {
                 "status": status,
                 "data": data
             }
         elif request.name == protocol.MSG_NAME_PUT:
             status = systemPut(self, request.path, request.data)
             extras = {
                 "status": status
             }
         elif request.name == protocol.MSG_NAME_EXEC:
             status, stdout, stderr = systemExec(self, request.command,
                                                 request.wait)
             extras = {
                 "status": status,
                 "stdout": stdout,
                 "stderr": stderr
             }
         else:
             raise protocol.UnsupportedMessageError(request.type,
                                                    request.target,
                                                    request.name,
                                                    *request.getParams())
     elif request.target == protocol.MSG_TARGET_EXTENSION:
         params = {}
         for name in request.getParams():
             params[name] = getattr(request, name)
         try:
             ext = protocol.getExtension(request.name)
         except:
             protocol.UnsupportedMessageError(request.type,
                                              request.target,
                                              request.name,
                                              *request.getParams())
         status, extras = ext.response(**params)
         extras["status"] = status
     else:
         raise protocol.UnsupportedMessageError(request.type,
                                                request.target,
                                                request.name,
                                                *request.getParams())
     return protocol.create(protocol.MSG_TYPE_RESPONSE, request.target,
                            request.name, **extras)