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


Python ServerProxy.hello方法代码示例

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


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

示例1: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [as 别名]
class Client(Cmd):
    prompt = '> '

    def __init__(self, url, dirname, urlfile):
        Cmd.__init__(self)
        self.secret = randomString(SECRET_LENGTH)
        n = Node(url, dirname, self.secret)
        t = Thread(target=n._start)
        t.setDaemon(1)
        t.start()

        sleep(HEAD_START)
        self.server = ServerProxy(url)
        urlfile = path.join(dirname, urlfile)
        for line in open(urlfile):
            line = line.strip()
            self.server.hello(line)

    def do_fetch(self, arg):
        try:
            self.server.fetch(arg, self.secret)
        except Fault as f:
            if f.faultCode != UNHANDLED: raise
            print("Couldn't find the file", arg)

    def do_exit(self, arg):
        print()
        sys.exit()

    do_EOF = do_exit
开发者ID:panda0881,项目名称:Beginning-Python,代码行数:32,代码来源:client.py

示例2: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [as 别名]
class Client(Cmd):
    intro = 'Welcome to the p2p file share shell.\n\
Type help or ? to list commands.'
    prompt = '>'

    def __init__(self, url, dirname, urlfile):
        Cmd.__init__(self)
        self.secret = random_string(SECRET_LENGTH)
        n = Node(url, dirname, self.secret)
        t = Thread(target=n.serve_forever)
        t.setDaemon(1)
        t.start()
        time.sleep(HEAD_START)
        self.server = ServerProxy(url)
        for line in open(urlfile):
            line = line.strip()
            self.server.hello(line)

    def do_fetch(self, arg):
        try:
            self.server.fetch(arg, self.secret)
        except Fault as f:
            if f.faultCode != UNHANDLED:
                raise
            print("Couldn't find the file ", arg)

    def do_exit(self, arg):
        sys.exit()

    do_EOF = do_exit
开发者ID:dust8,项目名称:bpfntp,代码行数:32,代码来源:client.py

示例3: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [as 别名]
class Client(wx.App):
    def __init__(self, url, dirname, urlfile):
        self.secret = randomString(SECRET_LENGTH)
        n = ListableNode(url, dirname, self.secret)
        t = Thread(target=n._start)
        t.setDaemon(1)
        t.start()

        sleep(HEAD_START)
        self.server = ServerProxy(url)
        for line in open(urlfile):
            line = line.strip()
            self.server.hello(line)

        # run gui
        super(Client, self).__init__()

    def updateList(self):
        self.files.Set(self.server.list())

    def OnInit(self):
        win = wx.Frame(None, title="File Sharing Client", size=(400, 399))

        bkg = wx.Panel(win)

        self.input = input = wx.TextCtrl(bkg)

        submit = wx.Button(bkg, label="Fetch", size=(80, 25))
        submit.Bind(wx.EVT_BUTTON, self.fetchHandler)

        hbox = wx.BoxSizer()

        hbox.Add(input, proportion=1, flag=wx.ALL | wx.EXPAND, border=10)
        hbox.Add(submit, flag=wx.TOP | wx.BOTTOM | wx.RIGHT, border=10)

        self.files = files = wx.ListBox(bkg)
        self.updateList()

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(hbox, proportion=0, flag=wx.EXPAND)
        vbox.Add(files, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10)

        bkg.SetSizer(vbox)

        win.Show()

        return True
开发者ID:panda0881,项目名称:Beginning-Python,代码行数:49,代码来源:guiclient.py

示例4: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [as 别名]
class Client(Cmd):
    """
    A simple text-based interface to the Node class.
    """

    prompt = '> '


    def __init__(self, url, dirname, urlfile):
        """
        Sets the url, dirname, and urlfile, and starts the Node
        Server in a separate thread.
        """
        Cmd.__init__(self)
        self.secret = randomString(SECRET_LENGTH)
        n = Node(url, dirname, self.secret)
        t = Thread(target=n._start)
        t.setDaemon(1)
        t.start()
        # Give the server a head start:
        sleep(HEAD_START)
        self.server = ServerProxy(url)
        for line in open(urlfile):
            line = line.strip()
            self.server.hello(line)

    def do_fetch(self, arg):
        "Call the fetch method of the Server."
        try:
            self.server.fetch(arg, self.secret)
        except Fault as f:
            if f.faultCode != UNHANDLED: raise
            print("Couldn't find the file", arg)

    def do_exit(self, arg):
        "Exit the program."
        print()
        sys.exit()

    do_EOF = do_exit # End-Of-File is synonymous with 'exit'
开发者ID:quietcoolwu,项目名称:Beginning_Python,代码行数:42,代码来源:listing27-3.py

示例5: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [as 别名]
class Client(tk.Frame):

    def __init__(self, master, url, dirname, urlfile):
        super().__init__(master)
        self.node_setup(url, dirname, urlfile)
        self.pack()
        self.create_widgets()

    def node_setup(self, url, dirname, urlfile):
        self.secret = random_string(SECRET_LENGTH)
        n = Node(url, dirname, self.secret)
        t = Thread(target=n._start)
        t.setDaemon(1)
        t.start()
        # Give the server a head start:
        sleep(HEAD_START)
        self.server = ServerProxy(url)
        for line in open(urlfile):
            line = line.strip()
            self.server.hello(line)

    def create_widgets(self):
        self.input = input = tk.Entry(self)
        input.pack(side='left')

        self.submit = submit = tk.Button(self)
        submit['text'] = "Fetch"
        submit['command'] = self.fetch_handler
        submit.pack()

    def fetch_handler(self):
        query = self.input.get()
        try:
            self.server.fetch(query, self.secret)
        except Fault as f:
            if f.faultCode != UNHANDLED: raise
            print("Couldn't find the file", query)
开发者ID:BrandonSherlocking,项目名称:beginning-python-3ed,代码行数:39,代码来源:listing28-1.py

示例6: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [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

示例7: Client

# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import hello [as 别名]
class Client(wx.App):
    """
    The main client class, which takes care of setting up the GUI and
    starts a Node for serving files.
    """
    def __init__(self, url, dirname, urlfile):
        """
        Creates a random secret, instantiates a Node with that secret,
        starts a Thread with the Node's _start method (making sure the
        Thread is a daemon so it will quit when the application quits),
        reads all the URLs from the URL file and introduces the Node to
        them.
        """
        super(Client, self).__init__()
        self.secret = randomString(SECRET_LENGTH)
        n = Node(url, dirname, self.secret)
        t = Thread(target=n._start)
        t.setDaemon(1)
        t.start()
        # Give the server a head start:
        sleep(HEAD_START)
        self.server = ServerProxy(url)
        for line in open(urlfile):
            line = line.strip()
            self.server.hello(line)


    def OnInit(self):
        """
        Sets up the GUI. Creates a window, a text field, and a button, and
        lays them out. Binds the submit button to self.fetchHandler.
        """

        win = wx.Frame(None, title="File Sharing Client", size=(400, 45))

        bkg = wx.Panel(win)

        self.input = input = wx.TextCtrl(bkg);

        submit = wx.Button(bkg, label="Fetch", size=(80, 25))
        submit.Bind(wx.EVT_BUTTON, self.fetchHandler)

        hbox = wx.BoxSizer()

        hbox.Add(input, proportion=1, flag=wx.ALL | wx.EXPAND, border=10)
        hbox.Add(submit, flag=wx.TOP | wx.BOTTOM | wx.RIGHT, border=10)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(hbox, proportion=0, flag=wx.EXPAND)

        bkg.SetSizer(vbox)

        win.Show()

        return True

    def fetchHandler(self, event):
        """
        Called when the user clicks the 'Fetch' button. Reads the
        query from the text field, and calls the fetch method of the
        server Node. If the query is not handled, an error message is
        printed.
        """

        query = self.input.GetValue()
        try:
            self.server.fetch(query, self.secret)
        except Fault as f:
            if f.faultCode != UNHANDLED: raise
            print("Couldn't find the file", query)
开发者ID:quietcoolwu,项目名称:Beginning_Python,代码行数:72,代码来源:listing28-1.py

示例8: GUIClient

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

#.........这里部分代码省略.........
        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

        main_server_url=self.URL.get()
        try:
            self.main_server_url='http://'+main_server_url
            self.main_server = ServerProxy(self.main_server_url)
            self.main_server.hello()
            self.text.insert(INSERT,'Connect with main server successfully.\n')
            self._start()
            START=True
        except:
            self.onURLError()

    def _start(self):
        s=Server()
        t = Thread(target=s._start)
        t.daemon=True
        t.start()
        self.text.insert(INSERT,'Start P2P client successfully.\n')

    def register(self):
        '''
        Registration by a user on the system.
        '''
        global START

        if START:
            user_name = self.userName.get()
            password = self.password.get()
            if self.main_server.registration(user_name, password):
                self.text.insert(INSERT,'Registration success.\n')
            else:
                self.onAccountError()
        else:
            self.onStartError()

    def remove(self):
        '''
        Removal by a user of themselves from the system.
开发者ID:byebyebymyai,项目名称:P2P-Files-Sharing-System,代码行数:70,代码来源:GUIClient.py


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