本文整理汇总了Python中xmlrpc.client.ServerProxy.registration方法的典型用法代码示例。如果您正苦于以下问题:Python ServerProxy.registration方法的具体用法?Python ServerProxy.registration怎么用?Python ServerProxy.registration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpc.client.ServerProxy
的用法示例。
在下文中一共展示了ServerProxy.registration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import registration [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')
#.........这里部分代码省略.........
示例2: GUIClient
# 需要导入模块: from xmlrpc.client import ServerProxy [as 别名]
# 或者: from xmlrpc.client.ServerProxy import registration [as 别名]
#.........这里部分代码省略.........
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.
'''
global START
if START:
user_name = self.userName.get()
password = self.password.get()
if self.main_server.removal(user_name, password):
self.text.insert(INSERT,'Removal success.\n')
else:
self.onAccountError()
else:
self.onStartError()
def logIn(self):
'''
Ability by a user to "log in" from the system.
'''
global PORT
global ADDRESS
global LOGIN
global USERNAME
global PASSWORD
global START