def normalize_name(self, name):
        """
        Return the new normalized name.

        @raise InvalidNameError: if the name is invalid (malformatted of
            contains invalid characters).
        @rase NameAlreadyInUseError: if the name is already in use.
        """

        if not isinstance(name, str):
            raise errors.InvalidNameError(_("Name must be a string"))
        _name = name.strip()
        if not re.search("\A[a-zA-Z]", _name):
            msg = _("Name {0} does not start with a " "letter").format(name)
            raise errors.InvalidNameError(msg)
        _name = re.sub(' ', '_', _name)
        if not re.search("\A[a-zA-Z0-9_\.-]+\Z", _name):
            msg = _("Name must contains only letters, numbers, underscores, "
                    "hyphens and points, {}").format(name)
            raise errors.InvalidNameError(msg)
        if self.is_in_use(_name):
            raise errors.NameAlreadyInUseError(name)
        return _name
Beispiel #2
0
 def get_project(self, name):
     try:
         path = self._path.child(name)
         return self.project_factory(path, self)
     except filepath.InsecurePath:
         raise errors.InvalidNameError(name)