Skip to content

Commit

Permalink
Document Name class
Browse files Browse the repository at this point in the history
This commit adds documentation for the Name class.

Part of #7
  • Loading branch information
DirectXMan12 committed Dec 18, 2014
1 parent 51e57f7 commit 336ffb1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions gssapi/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,38 @@


class Name(rname.Name):
"""GSSAPI Name
This class represents a GSSAPI name which may be used with
used with and/or returned by other GSSAPI methods.
It inherits from the low-level GSSAPI :class:`~gssapi.raw.names.Name`
class, and thus may used with both low-level and high-level API methods.
This class may be pickled and unpickled, as well as copied.
The :func:`str` and :func:`bytes` methods may be used to retrieve the
text of the name.
"""

__slots__ = ()

def __new__(cls, base=None, name_type=None, token=None):
"""Create or import a GSSAPI name
The constructor either creates or imports a GSSAPI name.
If a :python:`~gssapi.raw.names.Name` object from the low-level API
is passed as the `base` argument, it will be converted into a
high-level object.
If the `token` argument is used, the name will be imported using
the token.
Otherwise, a new name will be created, using the `base` argument as
the string and the `name_type` argument to denote the name type.
"""

if token is not None:
base_name = rname.import_name(token, NameType.export)
elif isinstance(base, rname.Name):
Expand Down Expand Up @@ -39,6 +68,7 @@ def __bytes__(self):

@property
def name_type(self):
"""Get the name type of this name"""
return rname.display_name(self, name_type=True).name_type

def __eq__(self, other):
Expand All @@ -58,9 +88,30 @@ def __repr__(self):
name_type=disp_res.name_type)

def export(self):
"""Export the name
This method exports the name into a byte string which can then be
imported by using the `token` argument of the constructor.
Returns:
bytes: the exported name in token form
"""

return rname.export_name(self)

def canonicalize(self, mech_type):
"""Canonicalize a name with respect to a mechanism
This method returns a new Name that is canonicalized according to
the given mechanism.
Args:
mech_type (OID): the mechanism type to use
Returns:
Name: the canonicalized name
"""

return type(self)(rname.canonicalize_name(self, mech_type))

def __copy__(self):
Expand Down

0 comments on commit 336ffb1

Please sign in to comment.