Merge pull request #130 from craigcitro/docs

Add functools.wraps() to util.positional().
This commit is contained in:
Nathaniel Manista
2015-02-12 12:03:12 -08:00
3 changed files with 57 additions and 54 deletions

View File

@@ -50,39 +50,38 @@ gflags.DEFINE_multi_int('auth_host_port', [8080, 8090],
def run(flow, storage, http=None): def run(flow, storage, http=None):
"""Core code for a command-line application. """Core code for a command-line application.
The run() function is called from your application and runs through all The ``run()`` function is called from your application and runs
the steps to obtain credentials. It takes a Flow argument and attempts to through all the steps to obtain credentials. It takes a ``Flow``
open an authorization server page in the user's default web browser. The argument and attempts to open an authorization server page in the
server asks the user to grant your application access to the user's data. user's default web browser. The server asks the user to grant your
If the user grants access, the run() function returns new credentials. The application access to the user's data. If the user grants access,
new credentials are also stored in the Storage argument, which updates the the ``run()`` function returns new credentials. The new credentials
file associated with the Storage object. are also stored in the ``storage`` argument, which updates the file
associated with the ``Storage`` object.
It presumes it is run from a command-line application and supports the It presumes it is run from a command-line application and supports the
following flags: following flags:
--auth_host_name: Host name to use when running a local web server ``--auth_host_name`` (string, default: ``localhost``)
to handle redirects during OAuth authorization. Host name to use when running a local web server to handle
(default: 'localhost') redirects during OAuth authorization.
--auth_host_port: Port to use when running a local web server to handle ``--auth_host_port`` (integer, default: ``[8080, 8090]``)
redirects during OAuth authorization.; Port to use when running a local web server to handle redirects
repeat this option to specify a list of values during OAuth authorization. Repeat this option to specify a list
(default: '[8080, 8090]') of values.
(an integer)
--[no]auth_local_webserver: Run a local web server to handle redirects ``--[no]auth_local_webserver`` (boolean, default: ``True``)
during OAuth authorization. Run a local web server to handle redirects during OAuth authorization.
(default: 'true')
Since it uses flags make sure to initialize the gflags module before Since it uses flags make sure to initialize the ``gflags`` module before
calling run(). calling ``run()``.
Args: Args:
flow: Flow, an OAuth 2.0 Flow to step through. flow: Flow, an OAuth 2.0 Flow to step through.
storage: Storage, a Storage to store the credential in. storage: Storage, a ``Storage`` to store the credential in.
http: An instance of httplib2.Http.request http: An instance of ``httplib2.Http.request`` or something that acts
or something that acts like it. like it.
Returns: Returns:
Credentials, the obtained credential. Credentials, the obtained credential.

View File

@@ -111,34 +111,36 @@ class ClientRedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def run_flow(flow, storage, flags, http=None): def run_flow(flow, storage, flags, http=None):
"""Core code for a command-line application. """Core code for a command-line application.
The run() function is called from your application and runs through all the The ``run()`` function is called from your application and runs
steps to obtain credentials. It takes a Flow argument and attempts to open an through all the steps to obtain credentials. It takes a ``Flow``
authorization server page in the user's default web browser. The server asks argument and attempts to open an authorization server page in the
the user to grant your application access to the user's data. If the user user's default web browser. The server asks the user to grant your
grants access, the run() function returns new credentials. The new credentials application access to the user's data. If the user grants access,
are also stored in the Storage argument, which updates the file associated the ``run()`` function returns new credentials. The new credentials
with the Storage object. are also stored in the ``storage`` argument, which updates the file
associated with the ``Storage`` object.
It presumes it is run from a command-line application and supports the It presumes it is run from a command-line application and supports the
following flags: following flags:
--auth_host_name: Host name to use when running a local web server ``--auth_host_name`` (string, default: ``localhost``)
to handle redirects during OAuth authorization. Host name to use when running a local web server to handle
(default: 'localhost') redirects during OAuth authorization.
--auth_host_port: Port to use when running a local web server to handle ``--auth_host_port`` (integer, default: ``[8080, 8090]``)
redirects during OAuth authorization.; Port to use when running a local web server to handle redirects
repeat this option to specify a list of values during OAuth authorization. Repeat this option to specify a list
(default: '[8080, 8090]') of values.
(an integer)
--[no]auth_local_webserver: Run a local web server to handle redirects ``--[no]auth_local_webserver`` (boolean, default: ``True``)
during OAuth authorization. Run a local web server to handle redirects during OAuth authorization.
(default: 'true')
The tools module defines an ArgumentParser the already contains the flag
definitions that run() requires. You can pass that ArgumentParser to your
ArgumentParser constructor:
The tools module defines an ``ArgumentParser`` the already contains the flag
definitions that ``run()`` requires. You can pass that ``ArgumentParser`` to your
``ArgumentParser`` constructor::
parser = argparse.ArgumentParser(description=__doc__, parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -147,12 +149,12 @@ def run_flow(flow, storage, flags, http=None):
Args: Args:
flow: Flow, an OAuth 2.0 Flow to step through. flow: Flow, an OAuth 2.0 Flow to step through.
storage: Storage, a Storage to store the credential in. storage: Storage, a ``Storage`` to store the credential in.
flags: argparse.Namespace, The command-line flags. This is the object flags: ``argparse.Namespace``, The command-line flags. This is the
returned from calling parse_args() on object returned from calling ``parse_args()`` on
argparse.ArgumentParser as described above. ``argparse.ArgumentParser`` as described above.
http: An instance of httplib2.Http.request http: An instance of ``httplib2.Http.request`` or something that
or something that acts like it. acts like it.
Returns: Returns:
Credentials, the obtained credential. Credentials, the obtained credential.

View File

@@ -29,6 +29,7 @@ __all__ = [
'POSITIONAL_IGNORE', 'POSITIONAL_IGNORE',
] ]
import functools
import inspect import inspect
import logging import logging
import sys import sys
@@ -119,6 +120,7 @@ def positional(max_positional_args):
""" """
def positional_decorator(wrapped): def positional_decorator(wrapped):
@functools.wraps(wrapped)
def positional_wrapper(*args, **kwargs): def positional_wrapper(*args, **kwargs):
if len(args) > max_positional_args: if len(args) > max_positional_args:
plural_s = '' plural_s = ''