当前位置: 首页>>代码示例>>Python>>正文


Python ServerProxy.searchFile方法代码示例

本文整理汇总了Python中xmlrpc.client.ServerProxy.searchFile方法的典型用法代码示例。如果您正苦于以下问题:Python ServerProxy.searchFile方法的具体用法?Python ServerProxy.searchFile怎么用?Python ServerProxy.searchFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xmlrpc.client.ServerProxy的用法示例。


在下文中一共展示了ServerProxy.searchFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import searchFile [as 别名]

#.........这里部分代码省略.........
    
    def do_logIn(self,arg):
        '''
        Ability by a user to "log in" from the system.
        '''
        global PORT
        global ADDRESS
        global LOGIN
        global USERNAME
        global PASSWORD
        if LOGIN:
            print('Already log in, please logout first.')
        else:
            user_name = input('Input user name: ')
            password = input('Input password: ')
            if self.main_server.logIn(user_name, password, 'http://'+ADDRESS+':'+str(PORT)):
                LOGIN=True
                USERNAME=user_name
                PASSWORD=password
                print('Log in success')
            else:
                print('The user name or password is wrong, please try again.')
        
    def do_logOut(self,arg):
        '''
        Ability by a user to "log out" from the system.
        '''
        global LOGIN
        global USERNAME
        global PASSWORD
        if LOGIN:
            if self.main_server.logOut(USERNAME, PASSWORD):
                LOGIN=False
                USERNAME=None
                PASSWORD=None
                print('Log out success')
            else:
                print('The user name or password is wrong, please try again.')
        else:
            print('Did not log in,please log in first ')
    
    def do_download(self,arg):
        '''
        Used to make the Node find a file and download it.
        '''
        # client_url is the URL of the client which has file.
        if LOGIN:
            file_name=input('Input the file name: ')
            client_url=self._search(file_name)
            try :
                client=ServerProxy(client_url)
                self._fetch(file_name,client.send(file_name))
                print('Download success.')
            except:
                print('Cannot find file')
        else:
            print('Did not log in,please log in first ')

    def do_exit(self,arg):
        '''
        Exit the client
        '''
        global LOGIN
        global USERNAME
        global PASSWORD
        if LOGIN:
            self.main_server.logOut(USERNAME, PASSWORD)
        print('Good bye.')
        sys.exit()

    def do_inquire(self,arg):
        '''
        Ability by a user to see what files are available to transfer in the local.
        '''
        global DIRECTORY
        files=os.listdir(DIRECTORY)
        for file in files:
            print(file)
       
    def _search(self,file_name):
        '''
        Performs a query for a file, possibly asking other known Nodes for
        help.
        '''
        return self.main_server.searchFile(file_name)

    def _fetch(self,file_name,result):
        '''
        Returns the file as a string.
        '''
        global DIRECTORY
        f=open(DIRECTORY+file_name,'w')
        f.write(result)
        f.close()

    def do_hello(self,arg):
        '''
        Test for the connecting with main sever
        '''
        print(self.main_server.hello())
开发者ID:byebyebymyai,项目名称:P2P-Files-Sharing-System,代码行数:104,代码来源:Client.py

示例2: GUIClient

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import searchFile [as 别名]

#.........这里部分代码省略.........
                    self.text.insert(INSERT,'Log out success.\n')
                else:
                    self.onAccountError()
            else:
                self.onLogOutError()
        else:
            self.onStartError()

    def download(self):
        '''
        Used to make the Node find a file and download it.
        '''
        # client_url is the URL of the client which has file.
        global START

        if START:
            if LOGIN:
                file_name=self.fileName.get()
                if file_name == '':
                    self.onFileError()
                else:
                    client_url=self._search(file_name)
                    try :
                        client=ServerProxy(client_url)
                        self._fetch(file_name,client.send(file_name))
                        self.text.insert(INSERT,'Download success.\n')
                    except:
                        self.text.insert(INSERT,'Cannot find file.\n')
            else:
                self.onLogOutError()
        else:
            self.onStartError()

    def exit(self):
        '''
        Exit the client
        '''
        global LOGIN
        global USERNAME
        global PASSWORD
        if LOGIN:
            self.main_server.logOut(USERNAME, PASSWORD)
        self.text.insert(INSERT,'Good bye-bye.')
        sys.exit()

    def inquire(self):
        '''
        Ability by a user to see what files are available to transfer in the local.
        '''
        global START
        if START:
            global DIRECTORY
            files=os.listdir(DIRECTORY)
            for file in files:
                self.text.insert(INSERT,file+'\n')
        else:
            self.onStartError()

    def _search(self,file_name):
        '''
        Performs a query for a file, possibly asking other known Nodes for
        help.
        '''
        return self.main_server.searchFile(file_name)

    def _fetch(self,file_name,result):
        '''
        Returns the file as a string.
        '''
        global DIRECTORY
        f=open(DIRECTORY+file_name,'w')
        f.write(result)
        f.close()

    def do_hello(self,arg):
        '''
        Test for the connecting with main sever
        '''
        print(self.main_server.hello())

    def onURLError(self):
        showerror(title='Error',message='Please input URL of server.')

    def onDirError(self):
        showerror(title='Error',message='Please input directory.')

    def onFileError(self):
        showerror(title='Error',message='Please input file.')

    def onAccountError(self):
        showerror(title='Error',message='Please input correct username of password.')

    def onLogInError(self):
        showerror(title='Error',message='Already log in, please logout first.')

    def onLogOutError(self):
        showerror(title='Error',message='Did not log in,please log in first.')

    def onStartError(self):
        showerror(title='Error',message='Please start client.')
开发者ID:byebyebymyai,项目名称:P2P-Files-Sharing-System,代码行数:104,代码来源:GUIClient.py


注:本文中的xmlrpc.client.ServerProxy.searchFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。