Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
test.test_nntplib.NNTPv1Handler Class Reference
Inheritance diagram for test.test_nntplib.NNTPv1Handler:
Inheritance graph
[legend]
Collaboration diagram for test.test_nntplib.NNTPv1Handler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def start
def process_pending
def expect_body
def push_data
def push_lit
def handle_unknown
def handle_welcome
def handle_QUIT
def handle_DATE
def handle_GROUP
def handle_HELP
def handle_STAT
def handle_NEXT
def handle_LAST
def handle_LIST
def handle_NEWNEWS
def handle_XOVER
def handle_POST
def handle_IHAVE
def handle_ARTICLE
def handle_HEAD
def handle_BODY

Public Attributes

 in_body
 allow_posting
 body_callback
 body
 posted_body

Static Public Attributes

string welcome = "200 NNTP mock server"
string sample_head
string sample_body
string sample_article = "\n\n"

Private Member Functions

def _decode

Private Attributes

 _readline
 _push_data

Detailed Description

A handler for RFC 977

Definition at line 368 of file test_nntplib.py.


Member Function Documentation

def test.test_nntplib.NNTPv1Handler._decode (   self,
  data 
) [private]

Definition at line 381 of file test_nntplib.py.

00381 
00382     def _decode(self, data):
00383         return str(data, "utf-8", "surrogateescape")

Flag that the client is expected to post a request body

Definition at line 422 of file test_nntplib.py.

00422 
00423     def expect_body(self):
00424         """Flag that the client is expected to post a request body"""
00425         self.in_body = True

Here is the caller graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_ARTICLE (   self,
  message_spec = None 
)

Definition at line 631 of file test_nntplib.py.

00631 
00632     def handle_ARTICLE(self, message_spec=None):
00633         if message_spec is None:
00634             self.push_lit("220 3000237 <45223423@example.com>")
00635         elif message_spec == "<45223423@example.com>":
00636             self.push_lit("220 0 <45223423@example.com>")
00637         elif message_spec == "3000234":
00638             self.push_lit("220 3000234 <45223423@example.com>")
00639         else:
00640             self.push_lit("430 No Such Article Found")
00641             return
00642         self.push_lit(self.sample_article)
00643         self.push_lit(".")

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_BODY (   self,
  message_spec = None 
)

Definition at line 657 of file test_nntplib.py.

00657 
00658     def handle_BODY(self, message_spec=None):
00659         if message_spec is None:
00660             self.push_lit("222 3000237 <45223423@example.com>")
00661         elif message_spec == "<45223423@example.com>":
00662             self.push_lit("222 0 <45223423@example.com>")
00663         elif message_spec == "3000234":
00664             self.push_lit("222 3000234 <45223423@example.com>")
00665         else:
00666             self.push_lit("430 No Such Article Found")
00667             return
00668         self.push_lit(self.sample_body)
00669         self.push_lit(".")
00670 

Here is the call graph for this function:

Definition at line 446 of file test_nntplib.py.

00446 
00447     def handle_DATE(self):
00448         self.push_lit("111 20100914001155")

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_GROUP (   self,
  group 
)

Definition at line 449 of file test_nntplib.py.

00449 
00450     def handle_GROUP(self, group):
00451         if group == "fr.comp.lang.python":
00452             self.push_lit("211 486 761 1265 fr.comp.lang.python")
00453         else:
00454             self.push_lit("411 No such group {}".format(group))

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_HEAD (   self,
  message_spec = None 
)

Definition at line 644 of file test_nntplib.py.

00644 
00645     def handle_HEAD(self, message_spec=None):
00646         if message_spec is None:
00647             self.push_lit("221 3000237 <45223423@example.com>")
00648         elif message_spec == "<45223423@example.com>":
00649             self.push_lit("221 0 <45223423@example.com>")
00650         elif message_spec == "3000234":
00651             self.push_lit("221 3000234 <45223423@example.com>")
00652         else:
00653             self.push_lit("430 No Such Article Found")
00654             return
00655         self.push_lit(self.sample_head)
00656         self.push_lit(".")

Here is the call graph for this function:

Definition at line 455 of file test_nntplib.py.

00455 
00456     def handle_HELP(self):
00457         self.push_lit("""\
00458             100 Legal commands
00459               authinfo user Name|pass Password|generic <prog> <args>
00460               date
00461               help
00462             Report problems to <root@example.org>
00463             .""")

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_IHAVE (   self,
  message_id,
  body = None 
)

Definition at line 604 of file test_nntplib.py.

00604 
00605     def handle_IHAVE(self, message_id, *, body=None):
00606         if body is None:
00607             if (self.allow_posting and
00608                 message_id == "<i.am.an.article.you.will.want@example.com>"):
00609                 self.push_lit("335 Send it; end with <CR-LF>.<CR-LF>")
00610                 self.expect_body()
00611             else:
00612                 self.push_lit("435 Article not wanted")
00613         else:
00614             assert self.allow_posting
00615             self.push_lit("235 Article transferred OK")
00616             self.posted_body = body

Here is the call graph for this function:

Definition at line 477 of file test_nntplib.py.

00477 
00478     def handle_LAST(self):
00479         self.push_lit("223 3000234 <45223423@example.com> retrieved")

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_LIST (   self,
  action = None,
  param = None 
)

Definition at line 480 of file test_nntplib.py.

00480 
00481     def handle_LIST(self, action=None, param=None):
00482         if action is None:
00483             self.push_lit("""\
00484                 215 Newsgroups in form "group high low flags".
00485                 comp.lang.python 0000052340 0000002828 y
00486                 comp.lang.python.announce 0000001153 0000000993 m
00487                 free.it.comp.lang.python 0000000002 0000000002 y
00488                 fr.comp.lang.python 0000001254 0000000760 y
00489                 free.it.comp.lang.python.learner 0000000000 0000000001 y
00490                 tw.bbs.comp.lang.python 0000000304 0000000304 y
00491                 .""")
00492         elif action == "ACTIVE":
00493             if param == "*distutils*":
00494                 self.push_lit("""\
00495                     215 Newsgroups in form "group high low flags"
00496                     gmane.comp.python.distutils.devel 0000014104 0000000001 m
00497                     gmane.comp.python.distutils.cvs 0000000000 0000000001 m
00498                     .""")
00499             else:
00500                 self.push_lit("""\
00501                     215 Newsgroups in form "group high low flags"
00502                     .""")
00503         elif action == "OVERVIEW.FMT":
00504             self.push_lit("""\
00505                 215 Order of fields in overview database.
00506                 Subject:
00507                 From:
00508                 Date:
00509                 Message-ID:
00510                 References:
00511                 Bytes:
00512                 Lines:
00513                 Xref:full
00514                 .""")
00515         elif action == "NEWSGROUPS":
00516             assert param is not None
00517             if param == "comp.lang.python":
00518                 self.push_lit("""\
00519                     215 Descriptions in form "group description".
00520                     comp.lang.python\tThe Python computer language.
00521                     .""")
00522             elif param == "comp.lang.python*":
00523                 self.push_lit("""\
00524                     215 Descriptions in form "group description".
00525                     comp.lang.python.announce\tAnnouncements about the Python language. (Moderated)
00526                     comp.lang.python\tThe Python computer language.
00527                     .""")
00528             else:
00529                 self.push_lit("""\
00530                     215 Descriptions in form "group description".
00531                     .""")
00532         else:
00533             self.push_lit('501 Unknown LIST keyword')

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_NEWNEWS (   self,
  group,
  date_str,
  time_str 
)

Definition at line 534 of file test_nntplib.py.

00534 
00535     def handle_NEWNEWS(self, group, date_str, time_str):
00536         # We hard code different return messages depending on passed
00537         # argument and date syntax.
00538         if (group == "comp.lang.python" and date_str == "20100913"
00539             and time_str == "082004"):
00540             # Date was passed in RFC 3977 format (NNTP "v2")
00541             self.push_lit("""\
00542                 230 list of newsarticles (NNTP v2) created after Mon Sep 13 08:20:04 2010 follows
00543                 <a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>
00544                 <f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>
00545                 .""")
00546         elif (group == "comp.lang.python" and date_str == "100913"
00547             and time_str == "082004"):
00548             # Date was passed in RFC 977 format (NNTP "v1")
00549             self.push_lit("""\
00550                 230 list of newsarticles (NNTP v1) created after Mon Sep 13 08:20:04 2010 follows
00551                 <a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>
00552                 <f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>
00553                 .""")
00554         else:
00555             self.push_lit("""\
00556                 230 An empty list of newsarticles follows
00557                 .""")
00558         # (Note for experiments: many servers disable NEWNEWS.
00559         #  As of this writing, sicinfo3.epfl.ch doesn't.)

Here is the call graph for this function:

Definition at line 474 of file test_nntplib.py.

00474 
00475     def handle_NEXT(self):
00476         self.push_lit("223 3000237 <668929@example.org> retrieved")

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_POST (   self,
  body = None 
)

Definition at line 592 of file test_nntplib.py.

00592 
00593     def handle_POST(self, *, body=None):
00594         if body is None:
00595             if self.allow_posting:
00596                 self.push_lit("340 Input article; end with <CR-LF>.<CR-LF>")
00597                 self.expect_body()
00598             else:
00599                 self.push_lit("440 Posting not permitted")
00600         else:
00601             assert self.allow_posting
00602             self.push_lit("240 Article received OK")
00603             self.posted_body = body

Here is the call graph for this function:

Definition at line 443 of file test_nntplib.py.

00443 
00444     def handle_QUIT(self):
00445         self.push_lit("205 Bye!")

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_STAT (   self,
  message_spec = None 
)

Definition at line 464 of file test_nntplib.py.

00464 
00465     def handle_STAT(self, message_spec=None):
00466         if message_spec is None:
00467             self.push_lit("412 No newsgroup selected")
00468         elif message_spec == "3000234":
00469             self.push_lit("223 3000234 <45223423@example.com>")
00470         elif message_spec == "<45223423@example.com>":
00471             self.push_lit("223 0 <45223423@example.com>")
00472         else:
00473             self.push_lit("430 No Such Article Found")

Here is the call graph for this function:

Definition at line 437 of file test_nntplib.py.

00437 
00438     def handle_unknown(self):
00439         self.push_lit("500 What?")

Here is the call graph for this function:

Definition at line 440 of file test_nntplib.py.

00440 
00441     def handle_welcome(self):
00442         self.push_lit(self.welcome)

Here is the call graph for this function:

def test.test_nntplib.NNTPv1Handler.handle_XOVER (   self,
  message_spec 
)

Definition at line 560 of file test_nntplib.py.

00560 
00561     def handle_XOVER(self, message_spec):
00562         if message_spec == "57-59":
00563             self.push_lit(
00564                 "224 Overview information for 57-58 follows\n"
00565                 "57\tRe: ANN: New Plone book with strong Python (and Zope) themes throughout"
00566                     "\tDoug Hellmann <doug.hellmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>"
00567                     "\tSat, 19 Jun 2010 18:04:08 -0400"
00568                     "\t<4FD05F05-F98B-44DC-8111-C6009C925F0C@gmail.com>"
00569                     "\t<hvalf7$ort$1@dough.gmane.org>\t7103\t16"
00570                     "\tXref: news.gmane.org gmane.comp.python.authors:57"
00571                     "\n"
00572                 "58\tLooking for a few good bloggers"
00573                     "\tDoug Hellmann <doug.hellmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>"
00574                     "\tThu, 22 Jul 2010 09:14:14 -0400"
00575                     "\t<A29863FA-F388-40C3-AA25-0FD06B09B5BF@gmail.com>"
00576                     "\t\t6683\t16"
00577                     "\t"
00578                     "\n"
00579                 # An UTF-8 overview line from fr.comp.lang.python
00580                 "59\tRe: Message d'erreur incompréhensible (par moi)"
00581                     "\tEric Brunel <eric.brunel@pragmadev.nospam.com>"
00582                     "\tWed, 15 Sep 2010 18:09:15 +0200"
00583                     "\t<eric.brunel-2B8B56.18091515092010@news.wanadoo.fr>"
00584                     "\t<4c90ec87$0$32425$ba4acef3@reader.news.orange.fr>\t1641\t27"
00585                     "\tXref: saria.nerim.net fr.comp.lang.python:1265"
00586                     "\n"
00587                 ".\n")
00588         else:
00589             self.push_lit("""\
00590                 224 No articles
00591                 .""")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 384 of file test_nntplib.py.

00384 
00385     def process_pending(self):
00386         if self.in_body:
00387             while True:
00388                 line = self._readline()
00389                 if not line:
00390                     return
00391                 self.body.append(line)
00392                 if line == b".\r\n":
00393                     break
00394             try:
00395                 meth, tokens = self.body_callback
00396                 meth(*tokens, body=self.body)
00397             finally:
00398                 self.body_callback = None
00399                 self.body = None
00400                 self.in_body = False
00401         while True:
00402             line = self._decode(self._readline())
00403             if not line:
00404                 return
00405             if not line.endswith("\r\n"):
00406                 raise ValueError("line doesn't end with \\r\\n: {!r}".format(line))
00407             line = line[:-2]
00408             cmd, *tokens = line.split()
00409             #meth = getattr(self.handler, "handle_" + cmd.upper(), None)
00410             meth = getattr(self, "handle_" + cmd.upper(), None)
00411             if meth is None:
00412                 self.handle_unknown()
00413             else:
00414                 try:
00415                     meth(*tokens)
00416                 except Exception as e:
00417                     raise ValueError("command failed: {!r}".format(line)) from e
00418                 else:
00419                     if self.in_body:
00420                         self.body_callback = meth, tokens
00421                         self.body = []

def test.test_nntplib.NNTPv1Handler.push_data (   self,
  data 
)
Push some binary data

Definition at line 426 of file test_nntplib.py.

00426 
00427     def push_data(self, data):
00428         """Push some binary data"""
00429         self._push_data(data)

Here is the caller graph for this function:

def test.test_nntplib.NNTPv1Handler.push_lit (   self,
  lit 
)
Push a string literal

Definition at line 430 of file test_nntplib.py.

00430 
00431     def push_lit(self, lit):
00432         """Push a string literal"""
00433         lit = textwrap.dedent(lit)
00434         lit = "\r\n".join(lit.splitlines()) + "\r\n"
00435         lit = lit.encode('utf-8')
00436         self.push_data(lit)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_nntplib.NNTPv1Handler.start (   self,
  readline,
  push_data 
)

Definition at line 373 of file test_nntplib.py.

00373 
00374     def start(self, readline, push_data):
00375         self.in_body = False
00376         self.allow_posting = True
00377         self._readline = readline
00378         self._push_data = push_data
00379         # Our welcome
00380         self.handle_welcome()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 377 of file test_nntplib.py.

Definition at line 376 of file test_nntplib.py.

Definition at line 375 of file test_nntplib.py.

Definition at line 398 of file test_nntplib.py.

Definition at line 397 of file test_nntplib.py.

Definition at line 374 of file test_nntplib.py.

Definition at line 602 of file test_nntplib.py.

Definition at line 629 of file test_nntplib.py.

Initial value:
"""\
    This is just a test article.
    ..Here is a dot-starting line.

    -- Signed by Andr\xe9."""

Definition at line 623 of file test_nntplib.py.

Initial value:
"""\
    From: "Demo User" <nobody@example.net>
    Subject: I am just a test article
    Content-Type: text/plain; charset=UTF-8; format=flowed
    Message-ID: <i.am.an.article.you.will.want@example.com>"""

Definition at line 617 of file test_nntplib.py.

string test.test_nntplib.NNTPv1Handler.welcome = "200 NNTP mock server" [static]

Definition at line 371 of file test_nntplib.py.


The documentation for this class was generated from the following file: