本文整理汇总了Python中twisted.spread.pb.PBClientFactory.login方法的典型用法代码示例。如果您正苦于以下问题:Python PBClientFactory.login方法的具体用法?Python PBClientFactory.login怎么用?Python PBClientFactory.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.spread.pb.PBClientFactory
的用法示例。
在下文中一共展示了PBClientFactory.login方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def login(self, userID, robotID, password):
""" Callback for Robot connection to login and authenticate.
@param userID: User ID under which the robot is logging in.
@type userID: str
@param robotID: Unique ID of the robot in the namespace of the
user under which the robot is logging in.
@type robotID: str
@param password: Hashed password as hex-encoded string which is
used to authenticate the user.
@type password: str
@return: Representation of the connection to the robot
which is used in the Robot process.
(type: rce.robot.Connection)
@rtype: twisted.internet.defer.Deferred
"""
conn = Connection(self, userID, robotID)
factory = PBClientFactory()
self._reactor.connectTCP(self._masterIP, self._masterPort, factory)
d = factory.login(UsernamePassword(userID, password))
d.addCallback(self._cbAuthenticated, conn)
d.addCallback(self._cbConnected, conn)
d.addCallback(lambda _: conn)
return d
示例2: main
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def main(reactor, cred, masterIP, masterPort, commPort, uid):
f = open('/opt/rce/data/env.log', 'w') # TODO: Hardcoded? Use os.getenv('HOME')?
log.startLogging(f)
rospy.init_node('RCE_Master')
print 'connect to ', masterIP, masterPort
factory = PBClientFactory()
reactor.connectTCP(masterIP, masterPort, factory)
client = EnvironmentClient(reactor, commPort)
def terminate():
reactor.callFromThread(client.terminate)
reactor.callFromThread(reactor.stop)
rospy.on_shutdown(terminate)
def _err(reason):
print(reason)
terminate()
d = factory.login(cred, (client, uid))
d.addCallback(lambda ref: setattr(client, '_avatar', ref))
d.addErrback(_err)
reactor.run(installSignalHandlers=False)
f.close()
示例3: ForwardOutput
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
class ForwardOutput(Output):
implements(IOutput)
def configure(self, section):
self.forwardserver = section.getString('forwarding address', None)
self.forwardport = section.getInt('forwarding port', None)
self.retryinterval = section.getInt('retry interval', 10)
self.forwardedevents = getStat("terane.output.%s.forwardedevents" % self.name, 0)
self.stalerefs = getStat("terane.output.%s.stalerefs" % self.name, 0)
def startService(self):
Output.startService(self)
self._client = None
self._listener = None
self._remote = None
self._backoff = None
self._reconnect()
def _reconnect(self):
try:
if self._client:
self._client.disconnect()
self._client = PBClientFactory()
if self._listener:
self._listener.disconnect()
self._listener = reactor.connectTCP(self.forwardserver, self.forwardport, self._client)
self._remote = self._client.login(Anonymous())
self._remote.addCallback(self._login)
self._remote.addErrback(self._loginFailed)
except Exception, e:
logger.error("[output:%s] failed to connect to remote collector: %s" % (self.name,str(e)))
logger.error("[output:%s] will retry to connect in %i seconds" % (self.name,self.retryinterval))
self._backoff = reactor.callLater(self.retryinterval, self._reconnect)
示例4: main
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def main(
reactor,
cred,
masterIP,
masterPort,
masterPassword,
infraPasswd,
bridgeIF,
internalIP,
bridgeIP,
envPort,
rosproxyPort,
rootfsDir,
confDir,
dataDir,
pkgDir,
ubuntuRel,
rosRel,
data,
):
log.startLogging(sys.stdout)
def _err(reason):
print(reason)
reactor.stop()
factory = PBClientFactory()
reactor.connectTCP(masterIP, masterPort, factory)
client = ContainerClient(
reactor,
masterIP,
masterPort,
masterPassword,
infraPasswd,
bridgeIF,
internalIP,
bridgeIP,
envPort,
rosproxyPort,
rootfsDir,
confDir,
dataDir,
pkgDir,
ubuntuRel,
rosRel,
data,
)
d = factory.login(cred, (client, data))
d.addCallback(lambda ref: setattr(client, "_avatar", ref))
d.addErrback(_err)
reactor.addSystemEventTrigger("before", "shutdown", client.terminate)
reactor.run()
示例5: main
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def main():
"""
Connect to a PB server running on port 8800 on localhost and log in to
it, both anonymously and using a username/password it will recognize.
"""
startLogging(stdout)
factory = PBClientFactory()
reactor.connectTCP("localhost", 8800, factory)
anonymousLogin = factory.login(Anonymous())
anonymousLogin.addCallback(connected)
anonymousLogin.addErrback(error, "Anonymous login failed")
usernameLogin = factory.login(UsernamePassword("user1", "pass1"))
usernameLogin.addCallback(connected)
usernameLogin.addErrback(error, "Username/password login failed")
bothDeferreds = gatherResults([anonymousLogin, usernameLogin])
bothDeferreds.addCallback(finished)
reactor.run()
示例6: main
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def main(reactor, cred, masterIP, masterPort, internalIF, bridgeIF, envPort,
rootfsDir, confDir, dataDir, srcDir, pkgDir, maxNr):
log.startLogging(sys.stdout)
def _err(reason):
print(reason)
reactor.stop()
factory = PBClientFactory()
reactor.connectTCP(masterIP, masterPort, factory)
client = ContainerClient(reactor, masterIP, internalIF, bridgeIF, envPort,
rootfsDir, confDir, dataDir, srcDir, pkgDir)
d = factory.login(cred, (client, maxNr))
d.addCallback(lambda ref: setattr(client, '_avatar', ref))
d.addErrback(_err)
reactor.addSystemEventTrigger('before', 'shutdown', client.terminate)
reactor.run()
示例7: main
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def main(reactor, cred, masterIP, masterPort, consolePort,
extIP, extPort, commPort, pkgPath, customConverters):
log.startLogging(sys.stdout)
def _err(reason):
print(reason)
reactor.stop()
factory = PBClientFactory()
reactor.connectTCP(masterIP, masterPort, factory)
rosPath = []
for path in get_ros_paths() + [p for p, _ in pkgPath]:
if path not in rosPath:
rosPath.append(path)
loader = Loader(rosPath)
converter = Converter(loader)
for customConverter in customConverters:
# Get correct path/name of the converter
module, className = customConverter.rsplit('.', 1)
# Load the converter
mod = __import__(module, fromlist=[className])
converter.addCustomConverter(getattr(mod, className))
client = RobotClient(reactor, masterIP, consolePort, commPort, extIP,
extPort, loader, converter)
d = factory.login(cred, client)
d.addCallback(lambda ref: setattr(client, '_avatar', ref))
d.addErrback(_err)
# portal = Portal(client, (client,))
robot = CloudEngineWebSocketFactory(client,
'ws://localhost:{0}'.format(extPort))
listenWS(robot)
reactor.addSystemEventTrigger('before', 'shutdown', client.terminate)
reactor.run()
示例8: _login
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
def _login(self, credentials, client=None):
log.debug("_login called")
d = PBClientFactory.login(self, credentials, client)
d.addCallback(self._gotPerspective)
d.addErrback(self.gotPerspectiveFailed)
return d
示例9: ConsoleClient
# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import login [as 别名]
class ConsoleClient(HistoricRecvLine):
""" The class creates the terminal and manages connections with Master
and ROSAPI servers on specific containers
"""
def __init__(self, masterIP, consolePort):
""" Initialize the ConsoleClient.
@param masterIP: The IP of the master server
@type masterIP: string
@param consolePort: Port of the master server
@type consolePort: int
"""
self._user = None
self._masterIP = masterIP
self._console_port = consolePort
self._mode = "Username"
self._username = None
self._password = None
self._factory = None
self._connected_rosapi_nodes = {}
self._privilege = None
def showPrompt(self):
""" Show the prompt >>>
"""
self.terminal.nextLine()
self.terminal.write(self.ps[self.pn])
def connectionMade(self):
""" Create a PBClientFactory and connect to master when ConsoleClient
connected to StandardIO. Prompt user for Username
"""
HistoricRecvLine.connectionMade(self)
self._factory = PBClientFactory()
reactor.connectTCP(self._masterIP, self._console_port, self._factory) #@UndefinedVariable
self.terminal.write("Username: ")
def lineReceived(self, line):
""" Manage state/mode after connection. Code uses states to take
credential input and then starts terminal input.
@param line: line typed on terminal
@type line: string
"""
def _cbError(why, msg):
err(why, msg)
reactor.stop() #@UndefinedVariable
def _cbConnectionSuccess(view):
self._user = view
if isinstance(self._user, dict):
self._privilege = 'console'
else:
self._privilege = 'admin'
self.terminal.write('Connection to Master Established.')
self.showPrompt()
if self._mode == 'Username':
self._mode = 'Password'
self._username = line
self.terminal.write('Password: ')
elif self._mode == 'Password':
self._mode = 'Terminal'
self._password = line
cred = UsernamePassword(self._username,
sha256(self._password).hexdigest())
d = self._factory.login(cred)
d.addCallback(lambda p: p.callRemote("getUserView", True))
d.addCallback(_cbConnectionSuccess)
d.addErrback(_cbError, "Username/password login failed")
else:
self.parseInputLine(line)
def parseInputLine(self, line):
""" A function to route various commands entered via Console.
@param line: The text entered on the Console
@type line: string
"""
if line is not None and line is not '':
func = getattr(self, 'cmd_' + line.split()[0].upper(), None)
if func is not None:
func(line.split()[1:])
else:
self.terminal.write('No such command')
self.showPrompt()
@_errorHandle
def callToRosProxy(self, command, parameter):
""" Function to handle call to ROSAPI Proxy Server.
@param command: The command to execute in ROS environment.
@type command: string
@param parameter: A parameter for the command.
@type parameter: string
#.........这里部分代码省略.........