Back to index

plone3  3.1.7
Classes | Functions | Variables
PluggableAuthService.utils Namespace Reference

Classes

class  TestFileFinder

Functions

def fromZ2Interface
def directlyProvides
def classImplements
def postonly
def remove_stale_bytecode
def find_unit_test_files
def module_name_from_path
def get_suite
def allTests
def makestr
def createViewName
def createKeywords

Variables

tuple product_dir = package_home( globals() )
tuple product_prefix = os.path.join( os.path.split(product_dir)[:-1] )
tuple _wwwdir = os.path.join( product_dir, 'www' )

Function Documentation

def PluggableAuthService.utils.allTests (   from_dir = product_dir,
  test_prefix = 'test' 
)
    Walk the product and build a unittest.TestSuite aggregating tests.

Definition at line 160 of file utils.py.

00160 
00161 def allTests( from_dir=product_dir, test_prefix='test' ):
00162     """
00163         Walk the product and build a unittest.TestSuite aggregating tests.
00164     """
00165     os.path.walk( from_dir, remove_stale_bytecode, None )
00166     test_files = find_unit_test_files( from_dir, test_prefix )
00167     test_files.sort()
00168 
00169     suite = unittest.TestSuite()
00170 
00171     for test_file in test_files:
00172 
00173         s = get_suite( test_file )
00174         if s is not None:
00175             suite.addTest( s )
00176 
00177     return suite
00178 

Here is the call graph for this function:

def PluggableAuthService.utils.classImplements (   class_,
  interfaces 
)

Definition at line 41 of file utils.py.

00041 
00042 def classImplements(class_, *interfaces):
00043     # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface
00044     normalized_interfaces = []
00045     for i in interfaces:
00046         try:
00047             i = fromZ2Interface(i)
00048         except ValueError: # already a Zope 3 interface
00049             pass
00050         normalized_interfaces.append(i)
00051     return interface.classImplements(class_, *normalized_interfaces)
00052 
00053 # postonly protection
00054 try:
00055     # Zope 2.8.9, 2.9.7 and 2.10.3 (and up)
    from AccessControl.requestmethod import postonly

Here is the call graph for this function:

    Centralized place for creating the keywords that identify
    a ZCacheable record in a RAMCacheManager.

    Keywords are hashed so we don't accidentally expose sensitive
    information.

Definition at line 195 of file utils.py.

00195 
00196 def createKeywords(**kw):
00197     """
00198         Centralized place for creating the keywords that identify
00199         a ZCacheable record in a RAMCacheManager.
00200 
00201         Keywords are hashed so we don't accidentally expose sensitive
00202         information.
00203     """
00204     keywords = sha.new()
00205 
00206     items = kw.items()
00207     items.sort()
00208     for k, v in items:
00209         keywords.update(makestr(k))
00210         keywords.update(makestr(v))
00211 
00212     return {'keywords': keywords.hexdigest()}
00213 

Here is the call graph for this function:

Here is the caller graph for this function:

def PluggableAuthService.utils.createViewName (   method_name,
  user_handle = None 
)
    Centralized place for creating the "View Name" that identifies
    a ZCacheable record in a RAMCacheManager

Definition at line 185 of file utils.py.

00185 
00186 def createViewName(method_name, user_handle=None):
00187     """
00188         Centralized place for creating the "View Name" that identifies
00189         a ZCacheable record in a RAMCacheManager
00190     """
00191     if not user_handle:
00192         return makestr(method_name)
00193     else:
00194         return '%s-%s' % (makestr(method_name), makestr(user_handle))

Here is the call graph for this function:

Here is the caller graph for this function:

def PluggableAuthService.utils.directlyProvides (   obj,
  interfaces 
)

Definition at line 30 of file utils.py.

00030 
00031 def directlyProvides(obj, *interfaces):
00032     # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface
00033     normalized_interfaces = []
00034     for i in interfaces:
00035         try:
00036             i = fromZ2Interface(i)
00037         except ValueError: # already a Zope 3 interface
00038             pass
00039         normalized_interfaces.append(i)
00040     return interface.directlyProvides(obj, *normalized_interfaces)

Here is the call graph for this function:

def PluggableAuthService.utils.find_unit_test_files (   from_dir = product_dir,
  test_prefix = 'test' 
)
    Walk the product, return a list of all unittest files.

Definition at line 122 of file utils.py.

00122 
00123 def find_unit_test_files( from_dir=product_dir, test_prefix='test' ):
00124     """
00125         Walk the product, return a list of all unittest files.
00126     """
00127     finder = TestFileFinder()
00128     os.path.walk( from_dir, finder.visit, test_prefix )
00129     return finder.files

Here is the caller graph for this function:

Definition at line 24 of file utils.py.

00024 
00025     def fromZ2Interface(i):
00026         # Raise ValueError to work around a cornerish case where
00027         # zope.interface is available but Five is not.
00028         raise ValueError, i

Here is the caller graph for this function:

    Retrieve a TestSuite from 'file'.

Definition at line 143 of file utils.py.

00143 
00144 def get_suite( file ):
00145     """
00146         Retrieve a TestSuite from 'file'.
00147     """
00148     module_name = module_name_from_path( file )
00149     loader = unittest.defaultTestLoader
00150     try:
00151         suite = loader.loadTestsFromName( '%s.test_suite' % module_name )
00152     except AttributeError:
00153 
00154         try:
00155             suite = loader.loadTestsFromName(  module_name )
00156         except ImportError, err:
00157             print "Error importing %s\n%s" % (module_name, err)
00158             raise
00159     return suite

Here is the call graph for this function:

Here is the caller graph for this function:

Converts 's' to a non-Unicode string

Definition at line 179 of file utils.py.

00179 
00180 def makestr(s):
00181     """Converts 's' to a non-Unicode string"""
00182     if isinstance(s, unicode):
00183         s = s.encode('utf-8')
00184     return str(s)

Here is the caller graph for this function:

    Return the dotted module name matching the filesystem path.

Definition at line 130 of file utils.py.

00130 
00131 def module_name_from_path( path ):
00132     """
00133         Return the dotted module name matching the filesystem path.
00134     """
00135     assert path.endswith( '.py' )
00136     path = path[:-3]
00137     path = path[ len(product_prefix) + 1: ] # strip extraneous crap
00138     dirs = []
00139     while path:
00140         path, end = os.path.split( path )
00141         dirs.insert( 0, end )
00142     return ".".join( dirs )

Here is the caller graph for this function:

Definition at line 61 of file utils.py.

00061 
00062         def postonly(callable): return callable
00063 

def PluggableAuthService.utils.remove_stale_bytecode (   arg,
  dirname,
  names 
)
    Troll product, removing compiled turds whose source is now gone.

Definition at line 72 of file utils.py.

00072 
00073 def remove_stale_bytecode( arg, dirname, names ):
00074     """
00075         Troll product, removing compiled turds whose source is now gone.
00076     """
00077     names = map( os.path.normcase, names )
00078 
00079     for name in names:
00080 
00081         if name.endswith( ".pyc" ) or name.endswith( ".pyo" ):
00082 
00083             srcname = name[:-1]
00084 
00085             if srcname not in names:
00086 
00087                 fullname = os.path.join( dirname, name )
00088 
00089                 if __debug__:
00090                     print "Removing stale bytecode file", fullname
00091 
00092                 os.unlink( fullname )


Variable Documentation

tuple PluggableAuthService.utils._wwwdir = os.path.join( product_dir, 'www' )

Definition at line 67 of file utils.py.

tuple PluggableAuthService.utils.product_dir = package_home( globals() )

Definition at line 64 of file utils.py.

tuple PluggableAuthService.utils.product_prefix = os.path.join( os.path.split(product_dir)[:-1] )

Definition at line 65 of file utils.py.