本文整理汇总了Python中twisted.words.protocols.irc.IRCClient.away方法的典型用法代码示例。如果您正苦于以下问题:Python IRCClient.away方法的具体用法?Python IRCClient.away怎么用?Python IRCClient.away使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.protocols.irc.IRCClient
的用法示例。
在下文中一共展示了IRCClient.away方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ClientTests
# 需要导入模块: from twisted.words.protocols.irc import IRCClient [as 别名]
# 或者: from twisted.words.protocols.irc.IRCClient import away [as 别名]
class ClientTests(TestCase):
"""
Tests for the protocol-level behavior of IRCClient methods intended to
be called by application code.
"""
def setUp(self):
"""
Create and connect a new L{IRCClient} to a new L{StringTransport}.
"""
self.transport = StringTransport()
self.protocol = IRCClient()
self.protocol.performLogin = False
self.protocol.makeConnection(self.transport)
# Sanity check - we don't want anything to have happened at this
# point, since we're not in a test yet.
self.assertEquals(self.transport.value(), "")
def test_away(self):
"""
L{IRCCLient.away} sends an AWAY command with the specified message.
"""
message = "Sorry, I'm not here."
self.protocol.away(message)
expected = [
'AWAY :%s' % (message,),
'',
]
self.assertEquals(self.transport.value().split('\r\n'), expected)
def test_back(self):
"""
L{IRCClient.back} sends an AWAY command with an empty message.
"""
self.protocol.back()
expected = [
'AWAY :',
'',
]
self.assertEquals(self.transport.value().split('\r\n'), expected)
def test_whois(self):
"""
L{IRCClient.whois} sends a WHOIS message.
"""
self.protocol.whois('alice')
self.assertEquals(
self.transport.value().split('\r\n'),
['WHOIS alice', ''])
def test_whoisWithServer(self):
"""
L{IRCClient.whois} sends a WHOIS message with a server name if a
value is passed for the C{server} parameter.
"""
self.protocol.whois('alice', 'example.org')
self.assertEquals(
self.transport.value().split('\r\n'),
['WHOIS example.org alice', ''])
def test_register(self):
"""
L{IRCClient.register} sends NICK and USER commands with the
username, name, hostname, server name, and real name specified.
"""
username = 'testuser'
hostname = 'testhost'
servername = 'testserver'
self.protocol.realname = 'testname'
self.protocol.password = None
self.protocol.register(username, hostname, servername)
expected = [
'NICK %s' % (username,),
'USER %s %s %s :%s' % (
username, hostname, servername, self.protocol.realname),
'']
self.assertEquals(self.transport.value().split('\r\n'), expected)
def test_registerWithPassword(self):
"""
If the C{password} attribute of L{IRCClient} is not C{None}, the
C{register} method also sends a PASS command with it as the
argument.
"""
username = 'testuser'
hostname = 'testhost'
servername = 'testserver'
self.protocol.realname = 'testname'
self.protocol.password = 'testpass'
self.protocol.register(username, hostname, servername)
expected = [
'PASS %s' % (self.protocol.password,),
'NICK %s' % (username,),
'USER %s %s %s :%s' % (
#.........这里部分代码省略.........
示例2: ClientTests
# 需要导入模块: from twisted.words.protocols.irc import IRCClient [as 别名]
# 或者: from twisted.words.protocols.irc.IRCClient import away [as 别名]
class ClientTests(TestCase):
"""
Tests for the protocol-level behavior of IRCClient methods intended to
be called by application code.
"""
def setUp(self):
self.transport = StringIO()
self.protocol = IRCClient()
self.protocol.performLogin = False
self.protocol.makeConnection(self.transport)
# Sanity check - we don't want anything to have happened at this
# point, since we're not in a test yet.
self.failIf(self.transport.getvalue())
def test_away(self):
"""
L{IRCCLient.away} sends an AWAY command with the specified message.
"""
message = "Sorry, I'm not here."
self.protocol.away(message)
expected = [
'AWAY :%s' % (message,),
'',
]
self.assertEqual(self.transport.getvalue().split('\r\n'), expected)
def test_back(self):
"""
L{IRCClient.back} sends an AWAY command with an empty message.
"""
self.protocol.back()
expected = [
'AWAY :',
'',
]
self.assertEqual(self.transport.getvalue().split('\r\n'), expected)
def test_whois(self):
"""
L{IRCClient.whois} sends a WHOIS message.
"""
self.protocol.whois('alice')
self.assertEqual(
self.transport.getvalue().split('\r\n'),
['WHOIS alice', ''])
def test_whoisWithServer(self):
"""
L{IRCClient.whois} sends a WHOIS message with a server name if a
value is passed for the C{server} parameter.
"""
self.protocol.whois('alice', 'example.org')
self.assertEqual(
self.transport.getvalue().split('\r\n'),
['WHOIS example.org alice', ''])
def test_register(self):
"""
L{IRCClient.register} sends NICK and USER commands with the
username, name, hostname, server name, and real name specified.
"""
username = 'testuser'
hostname = 'testhost'
servername = 'testserver'
self.protocol.realname = 'testname'
self.protocol.password = None
self.protocol.register(username, hostname, servername)
expected = [
'NICK %s' % (username,),
'USER %s %s %s :%s' % (
username, hostname, servername, self.protocol.realname),
'']
self.assertEqual(self.transport.getvalue().split('\r\n'), expected)
def test_registerWithPassword(self):
"""
If the C{password} attribute of L{IRCClient} is not C{None}, the
C{register} method also sends a PASS command with it as the
argument.
"""
username = 'testuser'
hostname = 'testhost'
servername = 'testserver'
self.protocol.realname = 'testname'
self.protocol.password = 'testpass'
self.protocol.register(username, hostname, servername)
expected = [
'PASS %s' % (self.protocol.password,),
'NICK %s' % (username,),
'USER %s %s %s :%s' % (
username, hostname, servername, self.protocol.realname),
'']
self.assertEqual(self.transport.getvalue().split('\r\n'), expected)
示例3: ClientTests
# 需要导入模块: from twisted.words.protocols.irc import IRCClient [as 别名]
# 或者: from twisted.words.protocols.irc.IRCClient import away [as 别名]
class ClientTests(TestCase):
"""
Tests for the protocol-level behavior of IRCClient methods intended to
be called by application code.
"""
def setUp(self):
"""
Create and connect a new L{IRCClient} to a new L{StringTransport}.
"""
self.transport = StringTransport()
self.protocol = IRCClient()
self.protocol.performLogin = False
self.protocol.makeConnection(self.transport)
# Sanity check - we don't want anything to have happened at this
# point, since we're not in a test yet.
self.assertEquals(self.transport.value(), "")
def getLastLine(self, transport):
"""
Return the last IRC message in the transport buffer.
"""
return transport.value().split('\r\n')[-2]
def test_away(self):
"""
L{IRCCLient.away} sends an AWAY command with the specified message.
"""
message = "Sorry, I'm not here."
self.protocol.away(message)
expected = [
'AWAY :%s' % (message,),
'',
]
self.assertEquals(self.transport.value().split('\r\n'), expected)
def test_back(self):
"""
L{IRCClient.back} sends an AWAY command with an empty message.
"""
self.protocol.back()
expected = [
'AWAY :',
'',
]
self.assertEquals(self.transport.value().split('\r\n'), expected)
def test_whois(self):
"""
L{IRCClient.whois} sends a WHOIS message.
"""
self.protocol.whois('alice')
self.assertEquals(
self.transport.value().split('\r\n'),
['WHOIS alice', ''])
def test_whoisWithServer(self):
"""
L{IRCClient.whois} sends a WHOIS message with a server name if a
value is passed for the C{server} parameter.
"""
self.protocol.whois('alice', 'example.org')
self.assertEquals(
self.transport.value().split('\r\n'),
['WHOIS example.org alice', ''])
def test_register(self):
"""
L{IRCClient.register} sends NICK and USER commands with the
username, name, hostname, server name, and real name specified.
"""
username = 'testuser'
hostname = 'testhost'
servername = 'testserver'
self.protocol.realname = 'testname'
self.protocol.password = None
self.protocol.register(username, hostname, servername)
expected = [
'NICK %s' % (username,),
'USER %s %s %s :%s' % (
username, hostname, servername, self.protocol.realname),
'']
self.assertEquals(self.transport.value().split('\r\n'), expected)
def test_registerWithPassword(self):
"""
If the C{password} attribute of L{IRCClient} is not C{None}, the
C{register} method also sends a PASS command with it as the
argument.
"""
username = 'testuser'
hostname = 'testhost'
servername = 'testserver'
#.........这里部分代码省略.........