"Fossies" - the Fresh Open Source Software Archive

Member "viewvc-1.2.1/lib/common.py" (26 Mar 2020, 1907 Bytes) of package /linux/misc/viewvc-1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "common.py" see the Fossies "Dox" file reference documentation.

    1 # -*-python-*-
    2 #
    3 # Copyright (C) 1999-2020 The ViewCVS Group. All Rights Reserved.
    4 #
    5 # By using this file, you agree to the terms and conditions set forth in
    6 # the LICENSE.html file which can be found at the top level of the ViewVC
    7 # distribution or at http://viewvc.org/license-1.html.
    8 #
    9 # For more information, visit http://viewvc.org/
   10 #
   11 # -----------------------------------------------------------------------
   12 #
   13 # common: common definitions for the viewvc library
   14 #
   15 # -----------------------------------------------------------------------
   16 
   17 # Special type indicators for diff header processing and idiff return codes
   18 _RCSDIFF_IS_BINARY = 'binary-diff'
   19 _RCSDIFF_ERROR = 'error'
   20 _RCSDIFF_NO_CHANGES = "no-changes"
   21 
   22 
   23 class _item:
   24   def __init__(self, **kw):
   25     vars(self).update(kw)
   26 
   27 
   28 class TemplateData:
   29   """A custom dictionary-like object that allows one-time definition
   30   of keys, and only value fetches and changes, and key deletions,
   31   thereafter.
   32 
   33   EZT doesn't require the use of this special class -- a normal
   34   dict-type data dictionary works fine.  But use of this class will
   35   assist those who want the data sent to their templates to have a
   36   consistent set of keys."""
   37 
   38   def __init__(self, initial_data={}):
   39     self._items = initial_data
   40     
   41   def __getitem__(self, key):
   42     return self._items.__getitem__(key)
   43 
   44   def __setitem__(self, key, item):
   45     assert self._items.has_key(key)
   46     return self._items.__setitem__(key, item)
   47 
   48   def __delitem__(self, key):
   49     return self._items.__delitem__(key)
   50 
   51   def keys(self):
   52     return self._items.keys()
   53 
   54   def merge(self, template_data):
   55     """Merge the data in TemplataData instance TEMPLATA_DATA into this
   56     instance.  Avoid the temptation to use this conditionally in your
   57     code -- it rather defeats the purpose of this class."""
   58     
   59     assert isinstance(template_data, TemplateData)
   60     self._items.update(template_data._items)