当前位置: 首页>>代码示例>>Python>>正文


Python NNTP.xhdr方法代码示例

本文整理汇总了Python中nntplib.NNTP.xhdr方法的典型用法代码示例。如果您正苦于以下问题:Python NNTP.xhdr方法的具体用法?Python NNTP.xhdr怎么用?Python NNTP.xhdr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nntplib.NNTP的用法示例。


在下文中一共展示了NNTP.xhdr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]
def main():
  s = NNTP(settings.nntp_hostname, settings.nntp_port)
  resp, groups = s.list()
  # check all of the groups, just in case
  for group_name, last, first, flag in groups:
      resp, count, first, last, name = s.group(group_name)
      print "\nGroup", group_name, 'has', count, 'articles, range', first, 'to', last
      resp, subs = s.xhdr('subject', first + '-' + last)
      for id, sub in subs[-10:]:
          print id, sub
  s.quit()
开发者ID:jgrassler,项目名称:papercut,代码行数:13,代码来源:check_health.py

示例2: download_group

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]
def download_group(name):

    if not os.path.exists(name):
        os.mkdir(name)

    s = NNTP('news.gmane.org')
    resp, count, first, last, name = s.group(name)
    print 'Group', name, 'has', count, 'articles, range', first, 'to', last
    resp, subs = s.xhdr('subject', first + '-' + last)
    for id, sub in subs: 
        print id
        with open(os.path.join(name, str(id)), 'wb') as fp:
            pprint.pprint(s.article(id), stream=fp)
开发者ID:zopyx,项目名称:plone-social-analytics,代码行数:15,代码来源:test.py

示例3: __init__

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]
class NewsGrep:
    def __init__(self,server,username,password):
        self.server = NNTP(server, 119,username,password)
    def __del__(self):
        pass

    def __str__(self):
        pass

    def list(self):
        resp, groups = self.server.list()
        for group, last, first, flag in groups:
            print group

    def ls(self,group_name):
        resp, count, first, last, name = self.server.group(group_name)
        print 'Group', name, 'has', count, 'articles, range', first, 'to', last

        resp, subs = self.server.xhdr('subject', first + '-' + last)
        for id, sub in subs[-10:]:
            print id, sub
开发者ID:astrangeguy,项目名称:zendump,代码行数:23,代码来源:newsgrep.py

示例4: int

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]
    showcount  = int(showcount)
except:
    servername = 'news.gmane.org'
    groupname  = 'gmane.comp.python.general'          # cmd line args or defaults
    showcount  = 10                          # show last showcount posts

# connect to nntp server
print 'Connecting to', servername, 'for', groupname
from nntplib import NNTP
connection = NNTP(servername)
(reply, count, first, last, name) = connection.group(groupname)
print '%s has %s articles: %s-%s' % (name, count, first, last)

# get request headers only
fetchfrom = str(int(last) - (showcount-1))
(reply, subjects) = connection.xhdr('subject', (fetchfrom + '-' + last))

# show headers, get message hdr+body
for (id, subj) in subjects:                  # [-showcount:] if fetch all hdrs
    print 'Article %s [%s]' % (id, subj)
    if not listonly and raw_input('=> Display?') in ['y', 'Y']:
        reply, num, tid, list = connection.head(id)
        for line in list:
            for prefix in showhdrs:
                if line[:len(prefix)] == prefix:
                    print line[:80]; break
        if raw_input('=> Show body?') in ['y', 'Y']:
            reply, num, tid, list = connection.body(id)
            for line in list:
                print line[:80]
    print
开发者ID:wintergalt,项目名称:canilla,代码行数:33,代码来源:code_idol.py

示例5: Copyright

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]
#!/usr/bin/env python
# Copyright (c) 2004 Joao Prado Maia. See the LICENSE file for more information.
# $Id: check_health.py,v 1.1 2004-01-25 06:10:33 jpm Exp $

import settings
from nntplib import NNTP

s = NNTP(settings.nntp_hostname, settings.nntp_port)
resp, groups = s.list()
# check all of the groups, just in case
for group_name, last, first, flag in groups:
    resp, count, first, last, name = s.group(group_name)
    print "\nGroup", group_name, 'has', count, 'articles, range', first, 'to', last
    resp, subs = s.xhdr('subject', first + '-' + last)
    for id, sub in subs[-10:]:
        print id, sub
s.quit()
开发者ID:TBOpen,项目名称:papercut,代码行数:19,代码来源:check_health.py

示例6: Client

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]
class Client(Context):
    def __init__(self, log,
    hostname, port=None, username=None, password=None, *,
    debuglevel=None, **timeout):
        self.log = log
        self.hostname = hostname
        self.port = port
        self.username = username
        self.password = password
        self.debuglevel = debuglevel
        self.timeout = timeout
        Context.__init__(self)
        self.connect()
    
    def connect(self):
        address = net.format_addr((self.hostname, self.port))
        self.log.write("Connecting to {}\n".format(address))
        if self.port is None:
            port = ()
        else:
            port = (self.port,)
        self.connect_time = time.monotonic()
        self.nntp = NNTP(self.hostname, *port, **self.timeout)
        with ExitStack() as cleanup:
            cleanup.push(self)
            if self.debuglevel is not None:
                self.nntp.set_debuglevel(self.debuglevel)
            self.log.write("{}\n".format(self.nntp.getwelcome()))
            
            if self.username is not None:
                self.log.write("Logging in as {}\n".format(self.username))
                with self.handle_abort():
                    self.nntp.login(self.username, self.password)
                self.log.write("Logged in\n")
            cleanup.pop_all()
    
    def body(self, id, *pos, **kw):
        id = "<{}>".format(id)
        retry = 0
        while True:
            try:
                with self.handle_abort():
                    self.nntp.body(id, *pos, **kw)
                break
            except failure_responses as err:
                [code, *msg] = err.response.split(maxsplit=1)
                if code == "400":
                    [msg] = msg or (None,)
                    if not msg:
                        msg = "Server shut down connection"
                elif code[1] == "0" and not retry:
                    msg = err.response
                else:
                    raise
            self.log.write(msg + "\n")
            self.log_time()
            if retry >= 60:
                raise TimeoutError()
            self.close()
            time.sleep(retry)
            if not retry:
                start = time.monotonic()
            self.connect()
            if retry:
                retry *= 2
            else:
                retry = time.monotonic() - start
                if retry <= 0:
                    retry = 0.5
    
    def group(self, *pos, **kw):
        with self.handle_abort():
            return self.nntp.group(*pos, **kw)
    def over(self, *pos, **kw):
        with self.handle_abort():
            return self.nntp.over(*pos, **kw)
    def hdr(self, *pos, **kw):
        with self.handle_abort():
            return self.nntp.xhdr(*pos, **kw)
    
    @contextmanager
    def handle_abort(self):
        try:
            yield
        except failure_responses:
            raise  # NNTP connection still intact
        except:
            # Protocol is disrupted so abort the connection straight away
            self.close()
            raise
    
    def close(self):
        if not self.nntp:
            return
        
        # Ignore failure of inappropriate QUIT command
        with suppress(NNTPError), self.nntp:
            pass
        self.nntp = None
    
#.........这里部分代码省略.........
开发者ID:vadmium,项目名称:usenet-downloader,代码行数:103,代码来源:nntp.py

示例7: DownloadSpots

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import xhdr [as 别名]

#.........这里部分代码省略.........
        print 'Opening database...',
        self.make_table()
        self.cur.execute('SELECT count(id) FROM spots')
        oude_lengte = self.cur.fetchone()[0]
        print 'Done'
        print oude_lengte, 'spots in database'

        print 'Connecting...',
        last = int(self.news.group('free.pt')[3])
        print 'Done'
        if oude_lengte:
            self.cur.execute('SELECT max(id) FROM spots')
            current = self.cur.fetchone()[0]
        else:
            current = last - (NR_OF_SPOTS * 100)
        delta = 2000
        total = last - current

        print 'Current:', current
        print 'Last:', last
        print total, 'spots op te halen'
        yield total

        if current >= last:
            print 'Geen nieuwe spots!'
            yield 'end'
            return

        print 'Getting new spots...',
        self.cur.execute('DROP INDEX IF EXISTS spots_full_id_index')
        self.conn.commit()
        for i in xrange(0, total, delta):
            for (id, subject), (id, fromline), (id, full_id) in \
                    zip(*(self.news.xhdr(header, '%s-%s'
                    % (current + 1 + i, current + delta + i))[-1] for
                    header in ('subject', 'from', 'Message-ID'))):
                subject = re.sub('^[\t]', '', subject).split('\t')[0]
                if subject[:7] == 'DISPOSE':
                    continue
                subject = subject.decode('latin-1')
                fromline = fromline.decode('latin-1')
                subject = re.sub('\s\|\s\w+$', '', subject)
                poster = re.sub('(\t[^\t]+\t)?([^\s]+)\s<.+$', r'\2', fromline)
                try:
                    info = re.findall(r'<[^>]+>', fromline)[0].split('@')
                    modulus = info[0]
                    info = info[1].split('.')[:4]
                    date = info[3]
                except IndexError:
                    continue

                if info[0][1] == '7':
                    modulus = modulus.split('.')[0][1:]
                else:
                    modulus = 0

                subcats = '|'.join(info[0][2:][x:x + 3] for x in
                                   xrange(0, len(info[0][2:]), 3))

                erotiek = 0
                if info[0][0] == '1':
                    for genre in re.findall('d[0-9]{2}', subcats):
                        if ((23 <= int(genre[1:]) <= 26) or
                            (72 <= int(genre[1:]) <= 89)):
                            erotiek = 1
                            break
开发者ID:BartLH,项目名称:PySpotQt,代码行数:70,代码来源:download_spots.py


注:本文中的nntplib.NNTP.xhdr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。