def main():
    a = None
    commands = ['!', 'delete', 'literal', 'prompt', 'send',
                '?', 'debug', 'ls', 'put', 'status', 'port',
                'append', 'dir', 'mdelete', 'pwd', 'trace',
                'ascii', 'disconnect', 'mdir', 'quit', 'type',
                'bell', 'get', 'mget', 'quote', 'user',
                'binary', 'glob', 'mkdir', 'recv', 'verbose',
                'bye', 'hash', 'mls', 'remotehelp',
                'cd', 'help', 'mput', 'rename',
                'close', 'lcd', 'open', 'rmdir']
    connected = False
    ser = 'None'
    while ser[0] not in ['quit', 'bye']:
        ser = raw_input(start_line).split(' ')
        if ser[0] == "open":
            if not connected:
                a = Client()
                if len(ser) == 1:
                    address = raw_input("To ")
                else:
                    address = ser[1]
                connected = a.init_connection(address)
            else:
                print "Already connected to a server, please disconnect first"
        if ser[0] == "close" and connected:
            a.QUIT()
            connected = False
        if ser[0] in commands:
            handle.handle(a, ser, connected)
        else:
            print "invalid command"
    if connected:
        a.QUIT()
Exemple #2
0
 def on_post(self, req, res):
     try:
         handle.handle(req.media)
     except Exception as ex:
         logger.exception(ex)
         report(str(ex))
         logger.error(str(req.media))
         report(str(req.media))
Exemple #3
0
def main():
    pygame.init()
    screen = pygame.display.set_mode([800,500])
    screen_title = pygame.display.set_caption("Issac")
    background = pygame.image.load(background_img_name).convert()
    level_info = room.generate_environment()
    for item in level_info:
        print(item)
        print()
    handle.handle(0, background, screen, screen_title, player_img_name)
 def run(self): 
     running = 1 
     while running: 
         data = self.client.recv(self.size) 
         if data: 
             #self.client.send(data) 
             handle(data, self.client)
         else: 
             self.client.close() 
             printthreadid()
             print "Client closed its socket....terminating"
             running = 0 
Exemple #5
0
 def run(self):
     running = 1
     while running:
         data = self.client.recv(self.size)
         if data:
             #self.client.send(data)
             handle(data, self.client)
         else:
             self.client.close()
             printthreadid()
             print "Client closed its socket....terminating"
             running = 0
Exemple #6
0
def update(show_key, table, con_key):

    if table == "" or show_key == "":
        print("update需要输入参数")
    else:
        if "=" in show_key:
            show_list = show_key.strip().split("=")
            if show_list[0].strip() == "staff_id":
                exit("staff_id不允许改动")
            else:
                message = file_read(table)
                title = message[0]
                context = message[1]

                if show_list[0] == "phone":
                    if not show_list[1].isdigit() or len(show_list[1]) != 11 or [True for line in context if show_list[1] in line]:
                        exit("phone键值对冲突")
                    else:
                        pass
                else:
                    pass

                show_index = title.index(show_list[0].strip())
                suit_list = handle(table, con_key)

                for line in suit_list:
                    staff_index = int(line[0]) - 1
                    context[staff_index][show_index] = show_list[1].strip("\",\'")

                print("\033[32mupdate语句执行完成\033[0m")
                print("影响条数:\033[31m%s\033[0m" % len(suit_list))
                file_write(message, table)
        else:
            exit("update语句错误")
Exemple #7
0
def select(show_key, table, con_key):

    if table == "" or show_key == "":
        print("select需要输入参数")
    else:
        title = file_read(table)[0]
        suit_list = handle(table, con_key)
        if show_key == "*":
            show_key = ''
            for key in title:
                if show_key == '':
                    show_key = key
                else:
                    show_key = '%s,%s' % (show_key, key)
        else:
            pass

        if suit_list:
            show_list = show_key.strip().split(",")
            for line in suit_list:
                for show_name in show_list:
                    name_index = title.index(show_name.strip())
                    print(line[name_index], end="\t")
                print()
        print("查询到的条数:%s" % len(suit_list))
Exemple #8
0
def response(request):
    if request.method == "GET":
        signature = request.GET.get('signature', None)
        timestamp = request.GET.get('timestamp', None)
        echostr = request.GET.get('echostr', None)
        nonce = request.GET.get('nonce', None)

        if wechat_base.check_signature(signature, timestamp, nonce):
            return HttpResponse(echostr)
        else:
            return HttpResponse("error")
    else:
        xml_str = smart_str(request.body)
        response_str = handle.handle(wechat_base, xml_str)
    return HttpResponse(response_str)
Exemple #9
0
def handle_server(websocket, path):
    request_count = 0
    logfile = open(nginx_log_file_path)
    lines = tail_f(logfile)
    log_dicts = handle(lines)

    start = time.time()
    for log_dict in log_dicts:
        # await websocket.send(str(log_dict))
        request_count += 1
        during_time = time.time() - start
        log_dict.update({
            'request_per_second': round(
                (request_count / during_time), 2
            )
        })
        yield from websocket.send(str(json.dumps(log_dict)))
Exemple #10
0
def main():
    topic_name, deadline = startup()

    parser = argparse.ArgumentParser()
    parser.add_argument("-p",
                        help="""TESport is the well-known port where the
                                     TES server accepts user requests, in TCP.
                                     This is an optional argument. If omitted,
                                     it assumes the value 59000.""",
                        metavar="TESport",
                        type=int)
    parser.add_argument("-n",
                        help="""ECPname is the name of the machine where
                                     the central evaluation contact point
                                     (ECP) runs. This is an optional
                                     argument. If this argument is omitted,
                                     the ECP should be running on the same
                                     machine.""",
                        metavar="ECPname",
                        type=str)

    parser.add_argument("-e",
                        help="""ECPport is the well-known port where the
                                     ECP server accepts user requests, in UDP.
                                     This is an optional argument. If omitted,
                                     it assumes the value 58009.""",
                        metavar="ECPport",
                        type=int)

    TESport = 59000
    ECPname = "localhost"
    ECPport = 58009

    args = parser.parse_args()
    if args.p and valid_port(args.p):
        TESport = args.p
    if args.n and args.n != ECPname:
        ECPname = args.n
    if args.e and valid_port(args.e):
        ECPport = args.e

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
        server.setblocking(True)
        server.bind(('', TESport))
        server.listen(10)
        print("Server bound on port {}".format(TESport))
        while True:
            with accept(server) as (conn, (ip, port)):
                try:
                    conn.settimeout(5.0)
                    print("Accepted {}:{}".format(ip, port))
                except socket.timeout as e:
                    traceback.print_exc()
                    print("Failed to accept connection:", str(e))
                    continue
                try:
                    pid = os.fork()
                    if pid == 0:
                        request = conn.makefile().readline()
                        print(request)
                        reply = handle.handle(request, deadline, topic_name,
                                              ECPname, ECPport)
                        conn.sendall(reply)
                except os.OSError as e:
                    traceback.print_exc()
                    print("Error: {}:{} : {}".format(ip, port, str(e)))
                    conn.sendall(error)
                finally:
                    if pid == 0:
                        sys.exit(0)
Exemple #11
0
  print "The default begin = 0,the end = 1, spider dbmm' image and upload to ftp"

  begin_time = int(time.time())
  argv_length = len(sys.argv) - 1

  # Python 2.X doesn't support variable length value and default value together
  # It has 2 vales
  if argv_length >= 1:
    for i in range(argv_length):
      config[i] = sys.argv[i+1]
    if (int(config[0]) >= int(config[1])):
      print "The begin page must smaller than end page!"
      sys.exit(1)
    # page is little, use single process
    if (int(config[1]) - int(config[0]) < process_number):
      handle.handle(config)
    # Use multiProcessing
    else:
      pages = int(config[1]) - int(config[0])
      process_pages = pages / process_number
      print 'Parent process is %s.' %(os.getpid())
      # Use processs_number processes
      pool = Pool(processes=process_number)
      # Make a copy to config
      temp_config = list(config)
      # Have process_number jobs to do  
      for i in xrange(process_number):
        temp_config[0] = int(config[0]) + i * process_pages
        if (i != process_number - 1 ):
          temp_config[1] = int(config[0]) + (i+1) * process_pages
        else:
Exemple #12
0
	def handle(self):
		handle(self)
Exemple #13
0
if __name__ == '__main__':
    if len(sys.argv) <= 1:
        print('Not enough arguments')
        sys.exit(-1)
    elif len(sys.argv) <= 2:
        import socket

        network_name = sys.argv[1]
        self_id = socket.gethostname()
    else:
        network_name = sys.argv[1]
        self_id = sys.argv[2]

    def ipvs_exec(cmd):
        #print(cmd)
        print_cmd(self, cmd)

    net = IPVSNet(client.networks.get(network_name), ipvs_exec)

    self = client.containers.get(self_id)
    if not net.connected(self):
        net.connect(self)

    for container in net.network.containers:
        if container is not self:
            net.add_real_server(container)

    for event in client.events():
        handle.handle(json.loads(event.decode('utf-8')))
def main():
    topic_name, deadline = startup()

    parser = argparse.ArgumentParser()
    parser.add_argument("-p", help = """TESport is the well-known port where the
                                     TES server accepts user requests, in TCP.
                                     This is an optional argument. If omitted,
                                     it assumes the value 59000."""
                            , metavar = "TESport"
                            , type = int)
    parser.add_argument("-n", help = """ECPname is the name of the machine where
                                     the central evaluation contact point
                                     (ECP) runs. This is an optional
                                     argument. If this argument is omitted,
                                     the ECP should be running on the same
                                     machine."""
                            , metavar = "ECPname"
                            , type = str)

    parser.add_argument("-e", help = """ECPport is the well-known port where the
                                     ECP server accepts user requests, in UDP.
                                     This is an optional argument. If omitted,
                                     it assumes the value 58009."""
                            , metavar = "ECPport"
                            , type = int)

    TESport = 59000
    ECPname = "localhost"
    ECPport = 58009

    args = parser.parse_args()
    if args.p and valid_port(args.p):
        TESport = args.p
    if args.n and args.n != ECPname:
        ECPname = args.n
    if args.e and valid_port(args.e):
        ECPport = args.e

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
        server.setblocking(True)
        server.bind(('', TESport))
        server.listen(10)
        print("Server bound on port {}".format(TESport))
        while True:
            with accept(server) as (conn, (ip, port)):
                try:
                    conn.settimeout(5.0)
                    print("Accepted {}:{}".format(ip, port))
                except socket.timeout as e:
                    traceback.print_exc()
                    print("Failed to accept connection:", str(e))
                    continue
                try:
                    pid = os.fork()
                    if pid == 0:
                        request = conn.makefile().readline()
                        print(request)
                        reply = handle.handle(request, deadline, topic_name, ECPname, ECPport)
                        conn.sendall(reply)
                except os.OSError as e:
                    traceback.print_exc()
                    print("Error: {}:{} : {}".format(ip, port, str(e)))
                    conn.sendall(error)
                finally:
                    if pid == 0:
                        sys.exit(0)
Exemple #15
0
 def setUpClass(cls):
     print u"________用例执行_________"
     cls._handle = handle.handle()
     setupsheet = data_read.get_xls('dict', u"dx_interauto_qa_case.xls",
                                    'setup')
     cls._handle.set_global(setupsheet)