当前位置: 首页>>代码示例>>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;未经允许,请勿转载。