/usr/lib/python2.6/site-packages/keystoneauth1
Edit: /usr/lib/python2.6/site-packages/keystoneauth1/_utils.pyc (8059B)
Ñò
DVc @ s› d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d „ Z e e ƒ Z d e f d „ ƒ YZ
d „ Z d „ Z d „ Z
d „ Z d S( iÿÿÿÿNc C s, | i t i d ƒ d d ƒ } t i | ƒ S( Nt .i t keystoneauth( t replacet __name__t splitt loggingt getLogger( t name( ( s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyt
get_logger s t
positionalc B sV e Z d Z d Z d Z d e d „ Z e d e d „ ƒ Z e d „ ƒ Z d „ Z RS( sŠ A decorator which enforces only some args may be passed positionally.
This idea and some of the code was taken from the oauth2 client of the
google-api client.
This decorator makes it easy to support Python 3 style key-word only
parameters. For example, in Python 3 it is possible to write::
def fn(pos1, *, kwonly1, kwonly2=None):
...
All named parameters after * must be a keyword::
fn(10, 'kw1', 'kw2') # Raises exception.
fn(10, kwonly1='kw1', kwonly2='kw2') # Ok.
To replicate this behaviour with the positional decorator you simply
specify how many arguments may be passed positionally. To replicate the
example above::
@positional(1)
def fn(pos1, kwonly1=None, kwonly2=None):
...
If no default value is provided to a keyword argument, it becomes a
required keyword argument::
@positional(0)
def fn(required_kw):
...
This must be called with the keyword parameter::
fn() # Raises exception.
fn(10) # Raises exception.
fn(required_kw=10) # Ok.
When defining instance or class methods always remember that in python the
first positional argument passed is always the instance so you will need to
account for `self` and `cls`::
class MyClass(object):
@positional(2)
def my_method(self, pos1, kwonly1=None):
...
@classmethod
@positional(2)
def my_method(cls, pos1, kwonly1=None):
...
If you would prefer not to account for `self` and `cls` you can use the
`method` and `classmethod` helpers which do not consider the initial
positional argument. So the following class is exactly the same as the one
above::
class MyClass(object):
@positional.method(1)
def my_method(self, pos1, kwonly1=None):
...
@positional.classmethod(1)
def my_method(cls, pos1, kwonly1=None):
...
If a value isn't provided to the decorator then it will enforce that
every variable without a default value will be required to be a kwarg::
@positional()
def fn(pos1, kwonly1=None):
...
fn(10) # Ok.
fn(10, 20) # Raises exception.
fn(10, kwonly1=20) # Ok.
This behaviour will work with the `positional.method` and
`positional.classmethod` helper functions as well::
class MyClass(object):
@positional.classmethod()
def my_method(cls, pos1, kwonly1=None):
...
MyClass.my_method(10) # Ok.
MyClass.my_method(10, 20) # Raises exception.
MyClass.my_method(10, kwonly1=20) # Ok.
For compatibility reasons you may wish to not always raise an exception so
a WARN mode is available. Rather than raise an exception a warning message
will be logged::
@positional(1, enforcement=positional.WARN):
def fn(pos1, kwonly=1):
...
Available modes are:
- positional.EXCEPT - the default, raise an exception.
- positional.WARN - log a warning on mistake.
t exceptt warnc C s | | _ | | _ d S( N( t _max_positional_argst _enforcement( t selft max_positional_argst enforcement( ( s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyt __init__‹ s c s4 ˆ d j o ˆ d 7‰ n ‡ ‡ ‡ f d † } | S( Ni c s ˆ ˆ ˆ ƒ | ƒ S( N( ( t func( R R t cls( s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyt f” s ( t None( R R R R ( ( R R R s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyt method s
c s ‡ ‡ ‡ f d † } | S( Nc s t ˆ i ˆ ˆ Ž | ƒ ƒ S( N( t classmethodR ( R ( t kwargst argsR ( s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyR š s ( ( R R R R ( ( R R R s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyR ˜ s c s‡ ˆ i d j o2 t i ˆ ƒ } t | i ƒ t | i ƒ ˆ _ n ˆ i d j o d n d ‰ t i ˆ ƒ ‡ ‡ ‡ f d † ƒ } | S( Ni t t sc s t | ƒ ˆ i j o} d h ˆ i d 6ˆ i d 6t | ƒ d 6ˆ d 6} ˆ i ˆ i j o t | ƒ ‚ q“ ˆ i ˆ i j o t i | ƒ q“ n ˆ | | Ž S( NsN %(name)s takes at most %(max)d positional argument%(plural)s (%(given)d given)R t maxt givent plural( t lenR R R
t EXCEPTt TypeErrort WARNt loggert warning( R R t message( R R R ( s; /tmp/pip-build-lt8jXN/keystoneauth1/keystoneauth1/_utils.pyt inner¥ s
( R R t inspectt
getargspecR R t defaultst functoolst wraps( R R t specR&