Back to index

plone3  3.1.7
Classes | Functions | Variables
GenericSetup.differ Namespace Reference

Classes

class  ConfigDiff

Functions

def unidiff

Variables

tuple BLANKS_REGEX = re.compile( r'^\s*$' )

Function Documentation

def GenericSetup.differ.unidiff (   a,
  b,
  filename_a = 'original',
  timestamp_a = None,
  filename_b = 'modified',
  timestamp_b = None,
  ignore_blanks = False 
)

Definition at line 35 of file differ.py.

00035 
00036            ):
00037     r"""Compare two sequences of lines; generate the resulting delta.
00038 
00039     Each sequence must contain individual single-line strings
00040     ending with newlines. Such sequences can be obtained from the
00041     `readlines()` method of file-like objects.  The delta
00042     generated also consists of newline-terminated strings, ready
00043     to be printed as-is via the writeline() method of a file-like
00044     object.
00045 
00046     Note that the last line of a file may *not* have a newline;
00047     this is reported in the same way that GNU diff reports this.
00048     *This method only supports UNIX line ending conventions.*
00049 
00050         filename_a and filename_b are used to generate the header,
00051         allowing other tools to determine what 'files' were used
00052         to generate this output.
00053 
00054         timestamp_a and timestamp_b, when supplied, are expected
00055         to be last-modified timestamps to be inserted in the
00056         header, as floating point values since the epoch.
00057 
00058     Example:
00059 
00060     >>> print ''.join(UniDiffer().compare(
00061     ...     'one\ntwo\nthree\n'.splitlines(1),
00062     ...     'ore\ntree\nemu\n'.splitlines(1))),
00063     +++ original
00064     --- modified
00065     @@ -1,3 +1,3 @@
00066     -one
00067     +ore
00068     -two
00069     -three
00070     +tree
00071     +emu
00072     """
00073     if isinstance( a, basestring ):
00074         a = a.splitlines()
00075 
00076     if isinstance( b, basestring ):
00077         b = b.splitlines()
00078 
00079     if ignore_blanks:
00080         a = [ x for x in a if not BLANKS_REGEX.match( x ) ]
00081         b = [ x for x in b if not BLANKS_REGEX.match( x ) ]
00082 
00083     return unified_diff( a
00084                        , b
00085                        , filename_a
00086                        , filename_b
00087                        , timestamp_a
00088                        , timestamp_b
00089                        , lineterm=""
00090                        )

Here is the caller graph for this function:


Variable Documentation

tuple GenericSetup.differ.BLANKS_REGEX = re.compile( r'^\s*$' )

Definition at line 26 of file differ.py.