當前位置: 首頁>>代碼示例>>Python>>正文


Python nntplib.NNTPPermanentError方法代碼示例

本文整理匯總了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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_nntplib.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_nntplib.py

示例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)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:test_nntplib.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:8,代碼來源:test_nntplib.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_nntplib.py

示例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) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:8,代碼來源:test_nntplib.py

示例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() 
開發者ID:wdxtub,項目名稱:deep-learning-note,代碼行數:59,代碼來源:2_nntp_client.py


注:本文中的nntplib.NNTPPermanentError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。