Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Check if project name appears legal, given template requirements.

Templates can provide number of namespaces they expect (provided
in 'ndots' attributes for number-of-dots in name). This checks that
provided project name is has correct number of namespaces and that
each part is a legal Python identifier.

        def checkdots(template, name):
    """Check if project name appears legal, given template requirements.

    Templates can provide number of namespaces they expect (provided
    in 'ndots' attributes for number-of-dots in name). This checks that
    provided project name is has correct number of namespaces and that
    each part is a legal Python identifier.
    """
    msg = "Not a valid Python dotted name: %s ('%s' is not an identifier)"
    ndots = getattr(template, 'ndots', None)
    if ndots is None:
        return   # No validation possible

    cdots = name.count(".")
    if ndots != cdots:
        raise ValueError(
            "Project name expected %i dots, supplied '%s' has %i dots" % (
                ndots, name, cdots))
    for part in name.split("."):
        # Check if Python identifier,
        # http://code.activestate.com/recipes/413487/
        try:
            class test(object): __slots__ = [part]
        except TypeError:
            raise ValueError(msg % (name, part))
        


src/t/e/templer.core-1.0b4/src/templer/core/tests/test_script.py   templer.core(Download)
import StringIO
 
from templer.core.zopeskel_script import checkdots
from templer.core.zopeskel_script import process_args
from templer.core.zopeskel_script import run
        t = FauxTemplate()
 
        checkdots(t, "anything is legal; not a package")
 
    def test_checkdots_two(self):
        self.assertRaises(ValueError, checkdots, t, "two.dots.but not legal")
 
        checkdots(t, "two.dots.legal")
 
    def test_process_args(self):