本文整理汇总了Python中nntplib.NNTPPermanentError方法的典型用法代码示例。如果您正苦于以下问题:Python nntplib.NNTPPermanentError方法的具体用法?Python nntplib.NNTPPermanentError怎么用?Python nntplib.NNTPPermanentError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nntplib
的用法示例。
在下文中一共展示了nntplib.NNTPPermanentError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_starttls
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def test_starttls(self):
file = self.server.file
sock = self.server.sock
try:
self.server.starttls()
except nntplib.NNTPPermanentError:
self.skipTest("STARTTLS not supported by server.")
else:
# Check that the socket and internal pseudo-file really were
# changed.
self.assertNotEqual(file, self.server.file)
self.assertNotEqual(sock, self.server.sock)
# Check that the new socket really is an SSL one
self.assertIsInstance(self.server.sock, ssl.SSLSocket)
# Check that trying starttls when it's already active fails.
self.assertRaises(ValueError, self.server.starttls)
示例2: test_unknown_command
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def test_unknown_command(self):
with self.assertRaises(nntplib.NNTPPermanentError) as cm:
self.server._shortcmd("XYZZY")
resp = cm.exception.response
self.assertTrue(resp.startswith("500 "), resp)
示例3: test_module_all_attribute
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def test_module_all_attribute(self):
self.assertTrue(hasattr(nntplib, '__all__'))
target_api = ['NNTP', 'NNTPError', 'NNTPReplyError',
'NNTPTemporaryError', 'NNTPPermanentError',
'NNTPProtocolError', 'NNTPDataError', 'decode_header']
if ssl is not None:
target_api.append('NNTP_SSL')
self.assertEqual(set(nntplib.__all__), set(target_api))
示例4: test_service_permanently_unavailable
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def test_service_permanently_unavailable(self):
#Test service permanently unavailable
class Handler(NNTPv1Handler):
welcome = '502 Service permanently unavilable'
self.check_constructor_error_conditions(
Handler, nntplib.NNTPPermanentError, Handler.welcome)
示例5: test_login_aborted
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def test_login_aborted(self):
#Test a bad authinfo response
login = 't@e.com'
password = 'python'
class Handler(NNTPv1Handler):
def handle_AUTHINFO(self, *args):
self.push_lit(authinfo_response)
authinfo_response = '503 Mechanism not recognized'
self.check_constructor_error_conditions(
Handler, nntplib.NNTPPermanentError, authinfo_response,
login, password)
示例6: test_service_permanently_unavailable
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def test_service_permanently_unavailable(self):
#Test service permanently unavailable
class Handler(NNTPv1Handler):
welcome = '502 Service permanently unavailable'
self.check_constructor_error_conditions(
Handler, nntplib.NNTPPermanentError, Handler.welcome)
示例7: main
# 需要导入模块: import nntplib [as 别名]
# 或者: from nntplib import NNTPPermanentError [as 别名]
def main():
try:
n = nntplib.NNTP(HOST)
#, user=USER, password=PASS) --if authentication required
except socket.gaierror as e:
print("ERROR: cannot reach host '%s'" % HOST)
print(' ("%s")' % eval(str(e))[1]) #what's the need of eval? Why not just str(e)? This itself creates another error
return
except nntplib.NNTPPermanentError as e:
print("ERROR: access denied on '%s'" % HOST)
print(' ("%s")' % str(e))
return
print("*** Connected to host '%s'" % HOST)
try:
rsp, ct, fst, lst, grp = n.group(GRNM)
except nntplib.NNTPTemporaryError as ee:
print("Error: cannot load group '%s'" % GRNM)
print(' ("%s")' % str(ee)) #book had e instead of ee, perhaps printing error in book
print(" Server may require authentication")
print(" Uncomment/edit login line above")
n.quit()
return
except nntplib.NNTPTemporaryError as ee: #this is exactly the above exception! But book has it! Maybe the order matters here
print("ERROR: group '%s' unavailable" % GRNM)
print(' ("%s")' % str(ee)) #book used e instead of ee
n.quit()
return
print("*** Found newsgroup '%s'" % GRNM)
#to get the first available article. Using simply fst doesn't work.
rng = "%s-%s" % (fst, fst)
rsp, frm = n.xhdr('from', rng)
count = 0
while not frm:
count += 1
n = nntplib.NNTP(HOST)
rsp, ct, fst, lst, grp = n.group(GRNM)
rng = "%s-%s" % (fst+count, fst+count)
rsp, frm = n.xhdr('from', rng)
#now that a 'from' header has been found, get other things
rsp, sub = n.xhdr('subject', rng)
rsp, dat = n.xhdr('date', rng)
print('''*** Found first article (#%s):
From: %s
Subject: %s
Date: %s
''' % (fst+count, frm[0][1], sub[0][1], dat[0][1]))
rsp, data = n.body(fst+count)
''' book has rsp, anum, mid, data --but that doesn't work as of this writing
instead, anum and mid are present in data, which is a tuple(at index 0 and 1 respectively)
'''
displayFirst20(data[2])
n.quit()