Python client 模块,Client() 实例源码

我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用client.Client()

项目:loving-ai    作者:opencog    | 项目源码 | 文件源码
def playback_history(df):
    from client import Client
    client = Client(os.environ.get('HR_CHATBOT_AUTHKEY', 'AAAAB3NzaD'), test=True)
    pattern_column = []
    for question in df.Question:
        answer = client.ask(question, True)
        traces = answer.get('trace')
        patterns = []
        if traces:
            for trace in traces:
                match_obj = trace_pattern.match(trace)
                if match_obj:
                    patterns.append(match_obj.group('pname'))
        pattern_column.append(patterns)
    df.loc[:,'Pattern'] = pd.Series(pattern_column, index=df.index)
    return df
项目:chkit.old    作者:containerum    | 项目源码 | 文件源码
def main():
    client = Client(VERSION)
    client.go()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def __init__(self, address, verbose = client.VERBOSE):
        client.Client.__init__(self, address, verbose)
项目:CPPS-PCL    作者:relrelb    | 项目源码 | 文件源码
def get_client(cpps, server):
    login_ip, login_port, game_ip, game_port, magic, single_quotes = get_server(cpps, server)
    return pcl.Client(login_ip, login_port, game_ip, game_port, magic, single_quotes)
项目:CPPS-PCL    作者:relrelb    | 项目源码 | 文件源码
def room(client, id):
    try:
        id = int(id)
    except ValueError:
        name = id
        id = client.Client.get_room_id(name)
        if not id:
            return "Room '" + name + "' not found"
    for client in clients:
        client.room = id
项目:indoor-localization    作者:luca-morreale    | 项目源码 | 文件源码
def createCommunicators(self):
        self.client = Client(10019)
        self.measurements_publisher = rospy.Publisher('measurements', MeasurementList, queue_size=10)
        self.request_subscriber = rospy.Subscriber('measurements_request', String, self.pushbackRequest)
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def sendPos(self, position):
        '''
        sendet ueber den Client die X und Y Position des Spielers an den Server
        Parameter:      position, x und y position des Spielers
        return values:  -
        '''
        self.c.sendPos(position)
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def sendShot(self, eventPosition):
        '''
        sendet ueber den Client die Position und das Ziel des Schusses des Spielers an den Server
        Parameter:      playerPosition, Koord des Spielers
                        eventPosition, Koord des Zieles des Schusses
        return values:  -
        '''
        self.c.sendShot(eventPosition)
项目:CSC376KnowledgeManagement    作者:WCotterman    | 项目源码 | 文件源码
def __init__(self, user):
        """
        Binds the UI object to a Client object so we can call
        client functions from within the UI class.

        :param user: an instantiated Client object
        """

        self.user = user
项目:Programming101-Python-2016    作者:HackBulgaria    | 项目源码 | 文件源码
def setUp(self):
        self.test_client = Client(1, "Ivo", 200000.00, "Bitcoin mining makes me rich")
项目:Programming101-Python-2016    作者:HackBulgaria    | 项目源码 | 文件源码
def login(username, password):
    select_query = "SELECT id, username, balance, message FROM clients WHERE username = '%s' AND password = '%s' LIMIT 1" % (username, password)

    cursor.execute(select_query)
    user = cursor.fetchone()

    if(user):
        return Client(user[0], user[1], user[2], user[3])
    else:
        return False
项目:XFLTReaT    作者:earthquake    | 项目源码 | 文件源码
def setup_authenticated_client(self, control_message, additional_data):
        addr = additional_data # UDP specific
        client_local = client.Client()
        common.init_client_stateless(control_message, addr, client_local, self.packetselector, self.clients)
        self.clients.append(client_local)
        self.packetselector.add_client(client_local)
        if client_local.get_pipe_r() not in self.rlist:
            self.rlist.append(client_local.get_pipe_r())
        self.send(common.CONTROL_CHANNEL_BYTE, common.CONTROL_AUTH_OK, additional_data)

        return
项目:XFLTReaT    作者:earthquake    | 项目源码 | 文件源码
def communication_initialization(self):
        self.client = client.Client()
        self.client.set_socket(self.comms_socket)

        return

    # check request: generating a challenge and sending it to the server
    # in case the answer is that is expected, the targer is a valid server
项目:XFLTReaT    作者:earthquake    | 项目源码 | 文件源码
def recv(self):
        message = ""
        length2b = self.comms_socket.recv(2, socket.MSG_PEEK)

        if len(length2b) == 0:
            if self.serverorclient:
                common.internal_print("Client lost. Closing down thread.", -1)
            else:
                common.internal_print("Server lost. Closing down.", -1)
            self.stop()
            self.cleanup()

            return ""

        if len(length2b) != 2:

            return ""

        length = struct.unpack(">H", length2b)[0]+2
        received = 0
        while received < length:
            message += self.comms_socket.recv(length-received)
            received = len(message)

        if (length != len(message)):
            common.internal_print("Error length mismatch", -1)
            return ""
        common.internal_print("TCP read: {0}".format(len(message)), 0, self.verbosity, common.DEBUG)

        return self.transform(message[2:],0)
项目:XFLTReaT    作者:earthquake    | 项目源码 | 文件源码
def serve(self):
        client_socket = server_socket = None
        self.threads = []
        threadsnum = 0

        if not self.sanity_check():
            return 

        common.internal_print("Starting server: {0} on {1}:{2}".format(self.get_module_name(), self.config.get("Global", "serverbind"), int(self.config.get(self.get_module_configname(), "serverport"))))

        server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        try:
            server_socket.bind((self.config.get("Global", "serverbind"), int(self.config.get(self.get_module_configname(), "serverport"))))
            while not self._stop:
                server_socket.listen(1) #?? 1 ??
                client_socket, client_addr = server_socket.accept()
                common.internal_print(("Client connected: {0}".format(client_addr)), 0, self.verbosity, common.DEBUG)

                threadsnum = threadsnum + 1
                thread = TCP_generic_thread(threadsnum, 1, self.tunnel, self.packetselector, client_socket, client_addr, self.verbosity, self.config, self.get_module_name())
                thread.start()
                self.threads.append(thread)

        except socket.error as exception:
            # [Errno 98] Address already in use
            if exception.args[0] != 98:
                raise
            else:
                common.internal_print("Starting failed, port is in use: {0} on {1}:{2}".format(self.get_module_name(), self.config.get("Global", "serverbind"), int(self.config.get(self.get_module_configname(), "serverport"))), -1)

        self.cleanup(server_socket)

        return
项目:raw-data-repository    作者:all-of-us    | 项目源码 | 文件源码
def main():
  client = Client()

  request = {
      'facets':['HPO_ID'],
      'start_date': '2017-03-26',
      'end_date': '2017-03-26'
  }

  response = client.request_json('Metrics', 'POST', request)
  logging.info(json.dumps(response, indent=2, sort_keys=True))
项目:raw-data-repository    作者:all-of-us    | 项目源码 | 文件源码
def main():
  client = Client()

  response = client.request_json('Participant', 'POST')
  logging.info(pprint.pformat(response))

  participant_id = response['participantId']
  # Fetch that participant and print it out.
  response = client.request_json('Participant/{}'.format(participant_id))
  logging.info(pprint.pformat(response))
项目:raw-data-repository    作者:all-of-us    | 项目源码 | 文件源码
def main():
  client = Client(base_path='offline')

  response = client.request_json('MetricsRecalculate', 'GET', cron=True)
  logging.info(json.dumps(response, indent=2, sort_keys=True))
项目:raw-data-repository    作者:all-of-us    | 项目源码 | 文件源码
def setUp(self):
    super(BaseClientTest, self).setUp()
    configure_logging()
    self.maxDiff = None
    instance = os.environ.get('PMI_DRC_RDR_INSTANCE') or _DEFAULT_INSTANCE
    creds_file = os.environ.get('TESTING_CREDS_FILE')
    self.client = Client(parse_cli=False, default_instance=instance, creds_file=creds_file)
    self.offline_client = Client(
        base_path=_OFFLINE_BASE_PATH,
        parse_cli=False,
        default_instance=instance,
        creds_file=creds_file)
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def __init__(self):
        '''
        Initialisation vom Game
        Achtet durchgehend, welche Spieler noch leben, bewegt die Schuesse,
        achtet auf Kollisionen und zeigt die Spielerpositionen
        Beendet das Spiel sobald nur noch ein Spieler am leben ist
        Parameter:      -
        return values:  -
        '''
        self.roommap = createRoommap.createRoommap(None)
        self.myRoom  = self.roommap.getStartRoom()
        self.mymap   = self.myRoom.getCol()
        #mapPath = "0.png" 
        self.screen = pygame.display.set_mode([self.mymap.getWidth(), self.mymap.getHeight()])
        pygame.key.set_repeat(1,10)
        self.background = self.myRoom.getBg().convert()
        self.rooms = self.roommap.getRooms()

        self.c = Client(self)
        self.done = False
        self.allPlayers = pygame.sprite.Group()
        self.allBots    = pygame.sprite.Group()
        self.drawBots   = pygame.sprite.Group()
        self.allBullets = pygame.sprite.Group()
        self.allWeapons = pygame.sprite.Group()
        self.allDoors0   = pygame.sprite.Group()
        self.allDoors1   = pygame.sprite.Group()
        self.player1 = Player()
        self.player1.nick = self.c.ipAtServer
        self.playerList = []
        self.weaponList = []
        self.player1.rect.x = 20
        self.player1.rect.y = 20
        self.allPlayers.add(self.player1)
        door1 = Door(0,0,'0',0,0)
        door2 = Door(0,0,'0',0,0)
        door1.rect.center = (230,50)
        door2.rect.center = (220,400)
        self.allDoors0.add(door1)
        self.allDoors1.add(door2)
        self.clock = pygame.time.Clock()


        self._shader     = shaderoverlay.ShaderOverlay(positionmap = self.mymap)
        self._shader.addLightsource(self.player1, 400, (255, 245, 240), 220, 40)
        self.shaderScreen = self._shader.getOverlay(self.screen.get_rect())
        self.shaderUpdate = False

##        self.screen.blit(self.background, [0,0])
##        self.__drawAllSprites()
##        pygame.display.flip()
##        
        self.__startGame()
项目:upmctl    作者:tschaefer    | 项目源码 | 文件源码
def run(args):
    client = Client(base_url=args.base_url,
                    base_auth=args.base_authentication)

    try:

        if hasattr(args, 'list'):
            if args.user:
                plugins = list_plugins(client, key='userInstalled',
                                       value='boolean', pattern='true')
            elif args.system:
                plugins = list_plugins(client, key='userInstalled',
                                       value='boolean', pattern='false')
            elif args.key:
                plugins = list_plugins(client, key='key', value='regex',
                                       pattern=args.key)
            elif args.key_configuration_file:
                config = read_config(args.key_configuration_file)
                key = get_key_config(config)
                plugins = list_plugins(client, key='key', value='regex',
                                       pattern=key)
            else:
                plugins = list_plugins(client)
            if plugins is not None:
                print plugins
        elif hasattr(args, 'show'):
            plugin = show_plugin(client, args.key)
            print plugin
        elif hasattr(args, 'install'):
            token = get_upm_token(client)
            client.request.url = args.base_url
            install_plugin(client, token, args.plugin)
        elif hasattr(args, 'delete'):
            delete_plugin(client, args.key)
        elif hasattr(args, 'activate'):
            activate_plugin(client, args.key)
        elif hasattr(args, 'deactivate'):
            deactivate_plugin(client, args.key)

    except ClientError as e:
        print >> sys.stderr, "%s: %s" % ('upmctl', e)
        sys.exit(1)

    sys.exit(0)
项目:3PC    作者:dkmiller    | 项目源码 | 文件源码
def main():
  global address, client, root_port, processes, outgoing_conns

  print sys.argv
  pid = int(sys.argv[1])
  my_pid = pid
  num_processes = int(sys.argv[2])
  myport = int(sys.argv[3])

  # Timeouts
  coordinator_timeout_vote_req = TimeoutThread(timeout_wait, 'coordinator-vote-req')
  coordinator_timeout_precommit = TimeoutThread(timeout_wait, 'coordinator-precommit')
  coordinator_timeout_commit = TimeoutThread(timeout_wait, 'coordinator-commit')
  process_timeout_vote = TimeoutThread(timeout_wait, 'process-vote')
  process_timeout_acks = TimeoutThread(timeout_wait, 'process-acks')
  coordinator_timeout_vote_req.start()
  coordinator_timeout_precommit.start()
  coordinator_timeout_commit.start()
  process_timeout_vote.start()
  process_timeout_acks.start()

  # Connection with MASTER
  mhandler = MasterHandler(pid, address, myport)
  outgoing_conns[-1] = mhandler

  # All incoming connections
  handler = WorkerThread(address, root_port+pid, pid)
  handler.start()

  # All outgoing connections
##  for pno in range(num_processes):
##    if pno == pid:
##      continue
##    handler = ClientHandler(pno, address, root_port+pno)
##    outgoing_conns[pno] = handler
##    handler.start()

  client = Client(pid, num_processes, send_many, coordinator_timeout_vote_req, coordinator_timeout_precommit, coordinator_timeout_commit, process_timeout_vote, process_timeout_acks)
  print "Client has been inited"
  client.load_state()
  mhandler.start()

  coordinator_timeout_vote_req.restart()

  while True:
    a = 1