88
99
1010def import_gssapi_extension (name ):
11+ """Import a GSSAPI extension module
12+
13+ This method imports a GSSAPI extension module based
14+ on the name of the extension (not including the
15+ 'ext_' prefix). If the extension is not available,
16+ the method retuns None.
17+
18+ Args:
19+ name (str): the name of the extension
20+
21+ Returns:
22+ module: Either the extension module or None
23+ """
24+
1125 try :
1226 path = 'gssapi.raw.ext_{0}' .format (name )
1327 __import__ (path )
@@ -29,7 +43,20 @@ def getter(self):
2943 return property (getter , setter )
3044
3145
32- def inquire_property (name ):
46+ def inquire_property (name , doc = None ):
47+ """Creates a property based on an inquire result
48+
49+ This method creates a property that calls the
50+ :python:`_inquire` method, and return the value of the
51+ requested information.
52+
53+ Args:
54+ name (str): the name of the 'inquire' result information
55+
56+ Returns:
57+ property: the created property
58+ """
59+
3360 def inquire_property (self ):
3461 if not self ._started :
3562 msg = ("Cannot read {0} from a security context whose "
@@ -38,23 +65,41 @@ def inquire_property(self):
3865
3966 return getattr (self ._inquire (** {name : True }), name )
4067
41- return property (inquire_property )
68+ return property (inquire_property , doc = doc )
4269
4370
4471# use UTF-8 as the default encoding, like Python 3
4572_ENCODING = 'UTF-8'
4673
4774
4875def _get_encoding ():
76+ """Gets the current encoding used for strings.
77+
78+ This value is used to encode and decode string
79+ values like names.
80+
81+ Returns:
82+ str: the current encoding
83+ """
4984 return _ENCODING
5085
5186
5287def set_encoding (enc ):
88+ """Sets the current encoding used for strings
89+
90+ This value is used to encode and decode string
91+ values like names.
92+
93+ Args:
94+ enc: the encoding to use
95+ """
96+
5397 global _ENCODING
5498 _ENCODING = enc
5599
56100
57101def _encode_dict (d ):
102+ """Encodes any relevant strings in a dict"""
58103 def enc (x ):
59104 if isinstance (x , six .text_type ):
60105 return x .encode (_ENCODING )
@@ -67,6 +112,17 @@ def enc(x):
67112# in case of Python 3, just use exception chaining
68113@deco .decorator
69114def catch_and_return_token (func , self , * args , ** kwargs ):
115+ """Optionally defer exceptions and return a token instead
116+
117+ When `__DEFER_STEP_ERRORS__` is set on the implementing class
118+ or instance, methods wrapped with this wrapper will
119+ catch and save their :python:`GSSError` exceptions and
120+ instead return the result token attached to the exception.
121+
122+ The exception can be later retrived through :python:`_last_err`
123+ (and :python:`_last_tb` when Python 2 is in use).
124+ """
125+
70126 try :
71127 return func (self , * args , ** kwargs )
72128 except GSSError as e :
@@ -85,6 +141,13 @@ def catch_and_return_token(func, self, *args, **kwargs):
85141
86142@deco .decorator
87143def check_last_err (func , self , * args , ** kwargs ):
144+ """Check and raise deferred errors before running the function
145+
146+ This method checks :python:`_last_err` before running the wrapped
147+ function. If present and not None, the exception will be raised
148+ with its original traceback.
149+ """
150+
88151 if self ._last_err is not None :
89152 try :
90153 if six .PY2 :
@@ -115,6 +178,14 @@ def check_last_err(func, self, *args, **kwargs):
115178
116179
117180class CheckLastError (type ):
181+ """Check for a deferred error on all methods
182+
183+ This metaclass applies the :python:`check_last_err` decorator
184+ to all methods not prefixed by '_'.
185+
186+ Additionally, it enabled `__DEFER_STEP_ERRORS__` by default.
187+ """
188+
118189 def __new__ (cls , name , parents , attrs ):
119190 attrs ['__DEFER_STEP_ERRORS__' ] = True
120191
0 commit comments