Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.support.werkzeug.datastructures.HeaderSet Class Reference

List of all members.

Public Member Functions

def __init__
def add
def remove
def update
def discard
def find
def index
def clear
def as_set
def to_header
def __getitem__
def __delitem__
def __setitem__
def __contains__
def __len__
def __iter__
def __nonzero__
def __str__
def __repr__

Public Attributes

 on_update

Private Attributes

 _headers
 _set

Detailed Description

Similar to the :class:`ETags` class this implements a set-like structure.
Unlike :class:`ETags` this is case insensitive and used for vary, allow, and
content-language headers.

If not constructed using the :func:`parse_set_header` function the
instantiation works like this:

>>> hs = HeaderSet(['foo', 'bar', 'baz'])
>>> hs
HeaderSet(['foo', 'bar', 'baz'])

Definition at line 1501 of file datastructures.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.datastructures.HeaderSet.__init__ (   self,
  headers = None,
  on_update = None 
)

Definition at line 1514 of file datastructures.py.

01514 
01515     def __init__(self, headers=None, on_update=None):
01516         self._headers = list(headers or ())
01517         self._set = set([x.lower() for x in self._headers])
01518         self.on_update = on_update


Member Function Documentation

Definition at line 1632 of file datastructures.py.

01632 
01633     def __contains__(self, header):
01634         return header.lower() in self._set

Definition at line 1618 of file datastructures.py.

01618 
01619     def __delitem__(self, idx):
01620         rv = self._headers.pop(idx)
01621         self._set.remove(rv.lower())
01622         if self.on_update is not None:
01623             self.on_update(self)

Definition at line 1615 of file datastructures.py.

01615 
01616     def __getitem__(self, idx):
01617         return self._headers[idx]

Definition at line 1638 of file datastructures.py.

01638 
01639     def __iter__(self):
01640         return iter(self._headers)

Definition at line 1635 of file datastructures.py.

01635 
01636     def __len__(self):
01637         return len(self._set)

Definition at line 1641 of file datastructures.py.

01641 
01642     def __nonzero__(self):
01643         return bool(self._set)

Definition at line 1647 of file datastructures.py.

01647 
01648     def __repr__(self):
01649         return '%s(%r)' % (
01650             self.__class__.__name__,
01651             self._headers
01652         )
01653 

Definition at line 1624 of file datastructures.py.

01624 
01625     def __setitem__(self, idx, value):
01626         old = self._headers[idx]
01627         self._set.remove(old.lower())
01628         self._headers[idx] = value
01629         self._set.add(value.lower())
01630         if self.on_update is not None:
01631             self.on_update(self)

Here is the caller graph for this function:

Definition at line 1644 of file datastructures.py.

01644 
01645     def __str__(self):
01646         return self.to_header()

Here is the call graph for this function:

Add a new header to the set.

Definition at line 1519 of file datastructures.py.

01519 
01520     def add(self, header):
01521         """Add a new header to the set."""
01522         self.update((header,))

Here is the call graph for this function:

def MoinMoin.support.werkzeug.datastructures.HeaderSet.as_set (   self,
  preserve_casing = False 
)
Return the set as real python set type.  When calling this, all
the items are converted to lowercase and the ordering is lost.

:param preserve_casing: if set to `True` the items in the set returned
                will have the original case like in the
                :class:`HeaderSet`, otherwise they will
                be lowercase.

Definition at line 1598 of file datastructures.py.

01598 
01599     def as_set(self, preserve_casing=False):
01600         """Return the set as real python set type.  When calling this, all
01601         the items are converted to lowercase and the ordering is lost.
01602 
01603         :param preserve_casing: if set to `True` the items in the set returned
01604                                 will have the original case like in the
01605                                 :class:`HeaderSet`, otherwise they will
01606                                 be lowercase.
01607         """
01608         if preserve_casing:
01609             return set(self._headers)
01610         return set(self._set)

Clear the set.

Definition at line 1591 of file datastructures.py.

01591 
01592     def clear(self):
01593         """Clear the set."""
01594         self._set.clear()
01595         del self._headers[:]
01596         if self.on_update is not None:
01597             self.on_update(self)

Like :meth:`remove` but ignores errors.

:param header: the header to be discarded.

Definition at line 1559 of file datastructures.py.

01559 
01560     def discard(self, header):
01561         """Like :meth:`remove` but ignores errors.
01562 
01563         :param header: the header to be discarded.
01564         """
01565         try:
01566             return self.remove(header)
01567         except KeyError:
01568             pass

Here is the call graph for this function:

Return the index of the header in the set or return -1 if not found.

:param header: the header to be looked up.

Definition at line 1569 of file datastructures.py.

01569 
01570     def find(self, header):
01571         """Return the index of the header in the set or return -1 if not found.
01572 
01573         :param header: the header to be looked up.
01574         """
01575         header = header.lower()
01576         for idx, item in enumerate(self._headers):
01577             if item.lower() == header:
01578                 return idx
01579         return -1

Here is the caller graph for this function:

Return the index of the header in the set or raise an
:exc:`IndexError`.

:param header: the header to be looked up.

Definition at line 1580 of file datastructures.py.

01580 
01581     def index(self, header):
01582         """Return the index of the header in the set or raise an
01583         :exc:`IndexError`.
01584 
01585         :param header: the header to be looked up.
01586         """
01587         rv = self.find(header)
01588         if rv < 0:
01589             raise IndexError(header)
01590         return rv

Here is the call graph for this function:

Remove a layer from the set.  This raises an :exc:`KeyError` if the
header is not in the set.

.. versionchanged:: 0.5
    In older versions a :exc:`IndexError` was raised instead of a
    :exc:`KeyError` if the object was missing.

:param header: the header to be removed.

Definition at line 1523 of file datastructures.py.

01523 
01524     def remove(self, header):
01525         """Remove a layer from the set.  This raises an :exc:`KeyError` if the
01526         header is not in the set.
01527 
01528         .. versionchanged:: 0.5
01529             In older versions a :exc:`IndexError` was raised instead of a
01530             :exc:`KeyError` if the object was missing.
01531 
01532         :param header: the header to be removed.
01533         """
01534         key = header.lower()
01535         if key not in self._set:
01536             raise KeyError(header)
01537         self._set.remove(key)
01538         for idx, key in enumerate(self._headers):
01539             if key.lower() == header:
01540                 del self._headers[idx]
01541                 break
01542         if self.on_update is not None:
01543             self.on_update(self)

Here is the caller graph for this function:

Convert the header set into an HTTP header string.

Definition at line 1611 of file datastructures.py.

01611 
01612     def to_header(self):
01613         """Convert the header set into an HTTP header string."""
01614         return ', '.join(map(quote_header_value, self._headers))

Here is the caller graph for this function:

Add all the headers from the iterable to the set.

:param iterable: updates the set with the items from the iterable.

Definition at line 1544 of file datastructures.py.

01544 
01545     def update(self, iterable):
01546         """Add all the headers from the iterable to the set.
01547 
01548         :param iterable: updates the set with the items from the iterable.
01549         """
01550         inserted_any = False
01551         for header in iterable:
01552             key = header.lower()
01553             if key not in self._set:
01554                 self._headers.append(header)
01555                 self._set.add(key)
01556                 inserted_any = True
01557         if inserted_any and self.on_update is not None:
01558             self.on_update(self)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1515 of file datastructures.py.

Definition at line 1516 of file datastructures.py.

Definition at line 1517 of file datastructures.py.


The documentation for this class was generated from the following file: