def subscribe(self, pubsubListener): self.__listener = pubsubListener if ( self.__listener is None) else self.__listener if self.__listener is None: raise ParameterError('Subscriber callback should not be None') elif self.__listener != pubsubListener: raise ParameterError( 'PubsubHandler only supports single Subscriber callback') def opflowListener(channel, method, properties, body, replyToName): headers = properties.headers requestId = Util.getRequestId(headers) if logger.isEnabledFor(logging.DEBUG): logger.debug('Request[%s] - subscribe() receive a message' % requestId) try: pubsubListener(body, headers) if logger.isEnabledFor(logging.DEBUG): logger.debug( 'Request[%s] - subscribe() has processed successfully' % requestId) except Exception as exception: redeliveredCount = 0 if 'redeliveredCount' in headers and type( headers['redeliveredCount']) is int: redeliveredCount = headers['redeliveredCount'] redeliveredCount += 1 if logger.isEnabledFor(logging.DEBUG): logger.debug( 'Request[%s] - redeliveredCount: %s/%s' % (requestId, redeliveredCount, self.__redeliveredLimit)) headers['redeliveredCount'] = redeliveredCount props = properties if redeliveredCount <= self.__redeliveredLimit: self.__sendToQueue(content=body, properties=props, queueName=self.__subscriberName, channel=channel) else: if self.__recyclebinName is not None: self.__sendToQueue(content=body, properties=props, queueName=self.__recyclebinName, channel=channel) return True return self.__engine.consume(opflowListener, { 'noAck': True, 'queueName': self.__subscriberName })
def getcmd(): argv = sys.argv[1:] if len(argv) <= 0: raise ParameterError('No parameter assinged', argv) return argv[0]
def __init__(self, *args, **kwargs): if args: if len(args) % 2 != 0: raise ParameterError( "Config requires an equal number of values and scores") for i in range(len(args) / 2): setattr(self, args[i * 2], args[i * 2 + 1]) for key in kwargs: setattr(self, key, kwargs[key]) # 默认创建前缀索引 if 'prefix_index_enable' not in kwargs: self.prefix_index_enable = True
def getargv(cmd): iargv = sys.argv[1:] if len(iargv) <= 1: raise ParameterError('Two or more parameters are required to execute', iargv) argv = iargv[1:] i = 0 param = {'argv': iargv} while True: val = argv[i] if cmd == 'forwarding': if re.match(r"-n|--no-shell", val): param['noshell'] = argv[i + 1] elif re.match(r"-s|--source", val): param['source'] = argv[i + 1] elif re.match(r"-o|--source-port", val): param['source_port'] = argv[i + 1] elif re.match(r"-d|--destination", val): param['destination'] = argv[i + 1] elif re.match(r"-r|--destination-port", val): param['destination_port'] = argv[i + 1] elif re.match(r"-x|--exit", val): param['stop'] = True elif cmd == 'copy': if re.match(r"-s|--source", val): param['source'] = argv[i + 1] elif re.match(r"-S|--remote-source", val): param['remote_source'] = argv[i + 1] elif re.match(r"-d|--destination", val): param['destination'] = argv[i + 1] elif re.match(r"-D|--remote-destination", val): param['remote_destination'] = argv[i + 1] if re.match(r"-t|--target", val): param['target'] = argv[i + 1] elif re.match(r"-p|--ssh-destination-port", val): param['ssh_destination_port'] = argv[i + 1] elif re.match(r"-i|--identity-file", val): param['pem_file'] = argv[i + 1] elif re.match(r"-h|--host", val): param['host'] = argv[i + 1] i += 2 if len(argv) <= i: break return param
def __init__(self, *args, **kwargs): # 参数检查 if args: if len(args) % 2 != 0: raise ParameterError("Config requires an equal number of values and scores") # 动态初始化实例变量 for i in range(len(args) / 2): setattr(self, args[i * 2], args[i * 2 + 1]) for key in kwargs: setattr(self, key, kwargs[key]) # redis pool = redis.ConnectionPool(host=self.config.redis['host'], port=self.config.redis['port'], db=self.config.redis['db']) self.r = redis.Redis(connection_pool=pool) # self.r = redis.StrictRedis(host=self.config.redis['host'], port=self.config.redis['port'], db=self.config.redis['db']) self.pipeline = self.r.pipeline() # 加载分词 mmseg.dict_load_defaults()
def checkcmd(cmd): if not re.match(r"^forwarding$|^remote$|^copy$|^checkconf$|^help$", cmd): raise ParameterError( 'First parameter must be "forwarding", "remote", "checkconf" or "help"' )
def checkargv(cmd, argv): if not 'target' in argv: raise ParameterError('Target data must be selected', argv['argv']) return True