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


Python ServerProxy.removal方法代码示例

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


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

示例1: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import removal [as 别名]
class Client(Cmd):
    '''
    A node in a peer-to-peer network.
    '''
    prompt = '>>'
    def __init__(self):
        '''
        Constructor of client, used to start the XML-RPC and command line interface.
        '''
        Cmd.__init__(self)
        self._path()
        self._connect()
        self._start()
        self.cmdloop()
        # url is the URL of this client.
        # main_server_url is the URL of the centralized server in a peer-to-peer network.
        # directory is the directory where this client save files. 
        # main_server is the centralized server in a peer-to-peer network.

    def _path(self):
        '''
        Input the path of files
        '''
        # Iput the path and check.
        global DIRECTORY
        DIRECTORY=input('Input the path of files which your want to share: ')
        if os.path.exists(DIRECTORY):
            print('Input path successfully')
        else:
            self._path()
            
    def _connect(self):
        '''
        Connect with main server.
        '''
        # Try connect with main server.
        main_server_url=input('Input the URL of main server: ')
        try:
            self.main_server_url='http://'+main_server_url
            self.main_server = ServerProxy(self.main_server_url)
        except:
            print('Cannot connect with this main server,please try again.')
            self._connect()

        # Check it is a main server or not.
        try:
            self.main_server.hello()
            print('Connect with main server successfully.')
        except:
            print('Cannot connect with sever, please try again.')
            self._connect()

    def _start(self):
        s=Server()
        t = Thread(target=s._start)
        t.daemon=True
        t.start()
        print('Start P2P client successfully.')
            
    def do_register(self,arg):
        '''
        Registration by a user on the system.
        '''
        user_name = input('Input user name: ')
        password = input('Input password: ')
        if self.main_server.registration(user_name, password):
            print('Registration success.')
        else:
            print('The user name is already be used, please try again.')

    def do_remove(self,arg):
        '''
        Removal by a user of themselves from the system.
        '''
        user_name = input('Input user name: ')
        password = input('Input password: ')
        if self.main_server.removal(user_name, password):
            print('Removal success.')
        else:
            print('The user name or password is wrong, please try again.')
    
    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')
#.........这里部分代码省略.........
开发者ID:byebyebymyai,项目名称:P2P-Files-Sharing-System,代码行数:103,代码来源:Client.py

示例2: GUIClient

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import removal [as 别名]
class GUIClient(Frame):
    def __init__(self, master=None):
        '''
        Constructor of client, used to start the XML-RPC and command line interface.
        '''
        master.title("P2P File Sharing System Client")
        master.minsize(500,510)
        master.maxsize(500,510)
        Frame.__init__(self, master)
        self.pack(fill=BOTH, expand=1)
        self.createWidgets()

    def createWidgets(self):

        self.columnconfigure(1, weight=1)
        self.columnconfigure(1, pad=1)
        self.rowconfigure(1, weight=1)
        self.rowconfigure(11, pad=1)

        userNameText = Label(self, text='User Name:')
        passwordText = Label(self, text='Password: ')
        fileNameText = Label(self, text='File Name:')

        userNameText.grid(sticky=W+N, row=0,column=0)
        passwordText.grid(sticky=W+N, row=1,column=0)
        fileNameText.grid(sticky=W+N, row=2,column=0)

        self.userName = Entry(self)
        self.password = Entry(self)
        self.fileName = Entry(self)

        self.userName.grid(sticky=W+N+E, row=0,column=1,columnspan=3)
        self.password.grid(sticky=W+N+E, row=1,column=1,columnspan=3)
        self.fileName.grid(sticky=W+N+E, row=2,column=1,columnspan=3)

        self.text = Text(self)
        self.text.grid(sticky=W+N+E, row=3,column=0,rowspan=6,columnspan=3)

        registion = Button(self, text='Register', command=self.register)
        removal = Button(self, text='Remove', command=self.remove)
        logIn = Button(self, text='Log In', command=self.logIn)
        logOut = Button(self, text='Log Out', command=self.logOut)
        download = Button(self, text='Download', command=self.download)
        inquire = Button(self, text='Inquire', command=self.inquire)

        registion.grid(sticky=W+E,row=3,column=3)
        removal.grid(sticky=W+E,row=4,column=3)
        logIn.grid(sticky=W+E,row=5,column=3)
        logOut.grid(sticky=W+E,row=6,column=3)
        download.grid(sticky=W+E,row=7,column=3)
        inquire.grid(sticky=W+E,row=8,column=3)

        start = Button(self, text='Start',command=self.init)
        exit = Button(self, text='Exit',command=self.exit)

        exit.grid(sticky=W+N+E,row=10,column=0)
        start.grid(sticky=W+N+E,row=10,column=1)

        URLText = Label(self, text='Server URL:')
        directoryText = Label(self, text='Directory:')

        URLText.grid(sticky=W+N,row=9,column=2)
        directoryText.grid(sticky=W+N,row=10,column=2)

        self.URL = Entry(self)
        self.directory = Entry(self)

        self.URL.grid(sticky=W+N,row=9,column=3)
        self.directory.grid(sticky=W+N,row=10,column=3)

    def init(self):
        global LOGIN
        global USERNAME
        global PASSWORD
        
        LOGIN=False
        USERNAME=None
        PASSWORD=None
        self._path()

    def _path(self):
        '''
        Input the path of files
        '''
        # Iput the path and check.
        global DIRECTORY
        DIRECTORY=self.directory.get()
        if os.path.exists(DIRECTORY):
            self.text.insert(INSERT,'Input path successfully\n')
            self._connect()
        else:
            self.onDirError()

    def _connect(self):
        '''
        Connect with main server.
        '''
        # Try connect with main server.
        # Check it is a main server or not.
        global START
#.........这里部分代码省略.........
开发者ID:byebyebymyai,项目名称:P2P-Files-Sharing-System,代码行数:103,代码来源:GUIClient.py


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