class PagespeedEntry(validation.Validated):
    """Describes the format of a pagespeed configuration from a yaml file.

  URL blacklist entries are patterns (with '?' and '*' as wildcards).  Any URLs
  that match a pattern on the blacklist will not be optimized by PageSpeed.

  Rewriter names are strings (like 'CombineCss' or 'RemoveComments') describing
  individual PageSpeed rewriters.  A full list of valid rewriter names can be
  found in the PageSpeed documentation.

  The domains-to-rewrite list is a whitelist of domain name patterns with '*' as
  a wildcard, optionally starting with 'http://' or 'https://'.  If no protocol
  is given, 'http://' is assumed.  A resource will only be rewritten if it is on
  the same domain as the HTML that references it, or if its domain is on the
  domains-to-rewrite list.
  """
    ATTRIBUTES = {
        URL_BLACKLIST:
        validation.Optional(
            validation.Repeated(validation.Regex(_URL_BLACKLIST_REGEX))),
        ENABLED_REWRITERS:
        validation.Optional(
            validation.Repeated(validation.Regex(_REWRITER_NAME_REGEX))),
        DISABLED_REWRITERS:
        validation.Optional(
            validation.Repeated(validation.Regex(_REWRITER_NAME_REGEX))),
        DOMAINS_TO_REWRITE:
        validation.Optional(
            validation.Repeated(validation.Regex(_DOMAINS_TO_REWRITE_REGEX))),
    }
Beispiel #2
0
 def _UpdateSkipFiles(self, parsed):
     """Resets skip_files field to Flex default if applicable."""
     if self.RequiresImage() and not self.HasExplicitSkipFiles():
         # pylint:disable=protected-access
         parsed.skip_files = validation._RegexStrValue(
             validation.Regex(DEFAULT_SKIP_FILES_FLEX),
             DEFAULT_SKIP_FILES_FLEX, 'skip_files')
Beispiel #3
0
def ValidateVersion(version):
    """Check that version is in the correct format. If not, raise an error.

  Args:
    version: The version id to validate (must not be None).

  Raises:
    InvalidVersionIdError: If the version id is invalid.
  """
    validator = validation.Regex(appinfo.MODULE_VERSION_ID_RE_STRING)
    try:
        validator.Validate(version, 'version')
    except validation.ValidationError:
        raise exceptions.InvalidVersionIdError(version)
 def _UpdateSkipFiles(self, file_path, parsed):
     """Resets skip_files field to Flex default if applicable."""
     if self.RequiresImage():
         if parsed.skip_files == appinfo.DEFAULT_SKIP_FILES:
             # Make sure that this was actually a default, not from the file.
             try:
                 with open(file_path, 'r') as readfile:
                     contents = readfile.read()
             except IOError:  # If the class was initiated with a non-existent file
                 contents = ''
             if 'skip_files' not in contents:
                 # pylint:disable=protected-access
                 parsed.skip_files = validation._RegexStrValue(
                     validation.Regex(DEFAULT_SKIP_FILES_FLEX),
                     DEFAULT_SKIP_FILES_FLEX, 'skip_files')
Beispiel #5
0
class DispatchEntry(validation.Validated):
    """A Dispatch entry describes a mapping from a URL pattern to a module."""
    ATTRIBUTES = {
        URL: DispatchEntryURLValidator(),
        MODULE: validation.Regex(appinfo.MODULE_ID_RE_STRING),
    }