Commit 24ee359d authored by Abhilash Raj's avatar Abhilash Raj
Browse files

Remove all implicit imports in doctests.

Implicit is better than explicit. These implicit imports often leads to
questions being answered on mailinglists about where these imports come
from. It is easier to have them explitly defined instead.

Also, move some commented helper functions out to be visible so that again
users aren't confused about where the magic functions are coming from.
parent 38ec84ba
......@@ -20,6 +20,7 @@ At first, no email addresses are banned globally.
To get a list-specific ban manager, adapt the mailing list object.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
>>> test_bans = IBanManager(mlist)
......
......@@ -11,10 +11,13 @@ Mailman can bounce messages back to the original sender. This is essentially
equivalent to rejecting the message with notification. Mailing lists can
bounce a message with an optional error message.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('ant@example.com')
Any message can be bounced.
>>> from mailman.testing.helpers import (specialized_message_from_string
... as message_from_string)
>>> msg = message_from_string("""\
... To: ant@example.com
... From: aperson@example.com
......
......@@ -32,7 +32,9 @@ not yet known, they will be registered, and new users will be linked to them.
... 'dperson@example.com',
... ]
>>> from mailman.app.lifecycle import create_list
>>> ant = create_list('ant@example.com', owners)
>>> from mailman.testing.documentation import dump_list
>>> dump_list(address.email for address in ant.owners.addresses)
aperson@example.com
bperson@example.com
......
......@@ -13,6 +13,7 @@ When Mailman needs to send a message to a user, it creates a
``UserNotification`` instance, and then calls the ``.send()`` method on this
object. This method requires a mailing list instance.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
The ``UserNotification`` constructor takes the recipient address, the sender
......
......@@ -10,6 +10,7 @@ changes for moderator approval. This utilizes the :ref:`lower level interface
Moderation is always mailing list-centric.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('ant@example.com')
>>> mlist.preferred_language = 'en'
>>> mlist.display_name = 'A Test List'
......@@ -30,6 +31,8 @@ Holding messages
Anne posts a message to the mailing list, but she is not a member of the list,
so the message is held for moderator approval.
>>> from mailman.testing.helpers import (specialized_message_from_string
... as message_from_string)
>>> msg = message_from_string("""\
... From: anne@example.org
... To: ant@example.com
......@@ -163,7 +166,7 @@ however the message metadata indicates that the message has been approved.
To: ant@example.com
Subject: Something important
...
>>> from mailman.testing.documentation import dump_msgdata
>>> dump_msgdata(messages[0].msgdata)
_parsemsg : False
approved : True
......
......@@ -8,6 +8,7 @@ NNTP, and outgoing queues. Pipelines are named and consist of a sequence of
handlers, each of which is applied in turn. Unlike rules and chains, there is
no way to stop a pipeline from processing the message once it's started.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
>>> print(mlist.posting_pipeline)
default-posting-pipeline
......@@ -25,6 +26,8 @@ Processing a message
Messages hit the pipeline after they've been accepted for posting.
>>> from mailman.testing.helpers import (specialized_message_from_string
... as message_from_string)
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: test@example.com
......@@ -62,6 +65,7 @@ come later during delivery).
The message metadata has information about recipients and other stuff.
However there are currently no recipients for this message.
>>> from mailman.testing.documentation import dump_msgdata
>>> dump_msgdata(msgdata)
original_sender : aperson@example.com
original_subject: My first post
......
......@@ -5,7 +5,10 @@ Archivers
Mailman supports pluggable archivers, and it comes with several default
archivers.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
>>> from mailman.testing.helpers import (specialized_message_from_string
... as message_from_string)
>>> msg = message_from_string("""\
... From: aperson@example.org
... To: test@example.com
......@@ -29,6 +32,7 @@ interoperate.
>>> archivers = {}
>>> from operator import attrgetter
>>> from mailman.config import config
>>> for archiver in sorted(config.archivers, key=attrgetter('name')):
... print(archiver.name)
... print(' ', archiver.list_url(mlist))
......
......@@ -6,6 +6,7 @@ Posts by members and nonmembers are subject to moderation checks during
incoming processing. Different situations can cause such posts to be held for
moderator approval.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
Members and nonmembers have a *moderation action* which can shortcut the
......@@ -70,6 +71,8 @@ Anne's post to the mailing list runs through the incoming runner's default
built-in chain. No rules hit and so the message is accepted.
::
>>> from mailman.testing.helpers import (specialized_message_from_string
... as message_from_string)
>>> msg = message_from_string("""\
... From: anne@example.com
... To: test@example.com
......
......@@ -5,6 +5,7 @@ Adding members
The ``mailman addmembers`` command allows a site administrator to add members
to a mailing list.
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_addmembers.addmembers')
Usage
......@@ -48,6 +49,7 @@ parsed by ``email.utils.parseaddr()``.
>>> from tempfile import NamedTemporaryFile
>>> filename = cleanups.enter_context(NamedTemporaryFile()).name
>>> from mailman.app.lifecycle import create_list
>>> bee = create_list('bee@example.com')
>>> with open(filename, 'w', encoding='utf-8') as fp:
... print("""\
......@@ -58,6 +60,7 @@ parsed by ``email.utils.parseaddr()``.
>>> command('mailman addmembers ' + filename + ' bee.example.com')
>>> from mailman.testing.documentation import dump_list
>>> from operator import attrgetter
>>> dump_list(bee.members.addresses, key=attrgetter('email'))
aperson@example.com
......
......@@ -8,6 +8,7 @@ server. Generally these files are automatically kept up-to-date when mailing
lists are created or removed, but you might occasionally need to manually
regenerate the file. The ``mailman aliases`` command does this.
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_aliases.aliases')
For example, connecting Mailman to Postfix is generally done through the LMTP
......@@ -18,6 +19,7 @@ maps.
Selecting Postfix as the source of incoming messages enables transport map
generation.
>>> from mailman.config import config
>>> config.push('postfix', """
... [mta]
... incoming: mailman.mta.postfix.LMTP
......@@ -33,6 +35,7 @@ Let's create a mailing list and then display the transport map for it. We'll
write the appropriate files to a temporary directory.
::
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('ant@example.com')
>>> import os, shutil, tempfile
......
......@@ -10,6 +10,7 @@ Mailman's configuration is divided in multiple sections which contain multiple
key-value pairs. The ``mailman conf`` command allows you to display a
specific key-value pair, or several key-value pairs.
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_conf.conf')
To get a list of all key-value pairs of any section, you need to call the
......
......@@ -20,6 +20,7 @@ file for the master that disables all the runners.
Starting
========
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_control.start')
Starting the daemons prints a useful message and starts the master watcher
......
......@@ -4,6 +4,7 @@ Command line list creation
A system administrator can create mailing lists by the command line.
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_lists.create')
You can prevent creation of a mailing list in an unknown domain.
......@@ -46,6 +47,7 @@ Setting the owner
By default, no list owners are specified.
>>> from mailman.testing.documentation import dump_list
>>> dump_list(mlist.owners.addresses)
*Empty*
......
......@@ -5,6 +5,7 @@ Deleting members
The ``mailman delmembers`` command allows a site administrator to delete members
from a mailing list.
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_delmembers.delmembers')
Usage
......@@ -64,6 +65,7 @@ options on the command line.
First we need a list with some members.
::
>>> from mailman.app.lifecycle import create_list
>>> bee = create_list('bee@example.com')
>>> from mailman.testing.helpers import subscribe
>>> subscribe(bee, 'Anne')
......@@ -108,6 +110,7 @@ Now we can delete some members.
>>> command('mailman delmembers -f ' + filename + ' -l bee.example.com')
>>> from operator import attrgetter
>>> from mailman.testing.documentation import dump_list
>>> dump_list(bee.members.addresses, key=attrgetter('email'))
Bart Person <bperson@example.com>
Doug Person <dperson@example.com>
......@@ -127,6 +130,7 @@ taken from standard input.
... """
>>> command('mailman delmembers -f - -l bee.example.com', input=stdin)
>>> from mailman.testing.documentation import dump_list
>>> dump_list(bee.members.addresses, key=attrgetter('email'))
Bart Person <bperson@example.com>
Fred Person <fperson@example.com>
......
......@@ -22,6 +22,7 @@ Complete information about command options may be obtained by running
``mailman digests --help``.
::
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_digests.digests')
>>> command('mailman digests --help')
......
......@@ -5,6 +5,7 @@ The 'echo' command
The mail command 'echo' simply replies with the original command and arguments
to the sender.
>>> from mailman.config import config
>>> command = config.commands['echo']
>>> print(command.name)
echo
......@@ -16,6 +17,7 @@ to the sender.
The original message is ignored, but the results receive the echoed command.
::
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
>>> from mailman.runners.command import Results
......
......@@ -5,6 +5,7 @@ The 'end' command
The mail command processor recognized an 'end' command which tells it to stop
processing email messages.
>>> from mailman.config import config
>>> command = config.commands['end']
>>> print(command.name)
end
......@@ -19,6 +20,7 @@ The 'end' command takes no arguments.
The command itself is fairly simple; it just stops command processing, and the
message isn't even looked at.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
>>> from mailman.email.message import Message
>>> print(command.process(mlist, Message(), {}, (), None))
......
......@@ -9,6 +9,7 @@ be posted to lists that are configured to gateway messages from a usenet group.
There are no options other than ``--help``.
::
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_gatenews.gatenews')
>>> command('mailman gatenews --help')
......
......@@ -5,6 +5,7 @@ Email command help
You can get some help about the various email commands that are available by
sending the word `help` to a mailing list's -request address.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('test@example.com')
>>> from mailman.commands.eml_help import Help
>>> help = Help()
......
......@@ -5,6 +5,7 @@ Importing list data
If you have the ``config.pck`` file for a version 2.1 mailing list, you can
import that into an existing mailing list in Mailman 3.0.
>>> from mailman.testing.documentation import cli
>>> command = cli('mailman.commands.cli_import.import21')
You must specify the mailing list you are importing into, and it must exist.
......@@ -38,7 +39,10 @@ When the mailing list exists, you must specify a real pickle file to import
from.
::
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list('import@example.com')
>>> from mailman.config import config
>>> transaction = config.db
>>> transaction.commit()
>>> command('mailman import21 import@example.com ' + __file__)
Usage: ... [OPTIONS] LISTSPEC PICKLE_FILE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment