Esempio n. 1
0
    def ProcessCronNode(self, node):
        """Processes XML <cron> nodes into Cron objects.

    The following information is parsed out:
      description: Describing the purpose of the cron job.
      url: The location of the script.
      schedule: Written in groc; the schedule according to which the job is
        executed.
      timezone: The timezone that the schedule runs in.
      target: Which version of the app this applies to.

    Args:
      node: <cron> XML node in cron.xml.
    """
        tag = xml_parser_utils.GetTag(node)
        if tag != 'cron':
            self.errors.append('Unrecognized node: <%s>' % tag)
            return

        cron = Cron()
        cron.url = xml_parser_utils.GetChildNodeText(node, 'url')
        cron.timezone = xml_parser_utils.GetChildNodeText(node, 'timezone')
        cron.target = xml_parser_utils.GetChildNodeText(node, 'target')
        cron.description = xml_parser_utils.GetChildNodeText(
            node, 'description')
        cron.schedule = xml_parser_utils.GetChildNodeText(node, 'schedule')
        _ProcessRetryParametersNode(node, cron)

        validation_error = self._ValidateCronEntry(cron)
        if validation_error:
            self.errors.append(validation_error)
        else:
            self.crons.append(cron)
Esempio n. 2
0
    def ProcessDispatchNode(self, node):
        """Processes XML <dispatch> nodes into DispatchEntry objects.

    The following information is parsed out:
      url: The URL or URL pattern to route.
      module: The module to route it to.
    If there are no errors, the data is loaded into a DispatchEntry object
    and added to a list. Upon error, a description of the error is added to
    a list and the method terminates.

    Args:
      node: <dispatch> XML node in dos.xml.
    """
        tag = xml_parser_utils.GetTag(node)
        if tag != 'dispatch':
            self.errors.append('Unrecognized node: <%s>' % tag)
            return

        entry = DispatchEntry()
        entry.url = xml_parser_utils.GetChildNodeText(node, 'url')
        entry.module = xml_parser_utils.GetChildNodeText(node, 'module')

        validation = self._ValidateEntry(entry)
        if validation:
            self.errors.append(validation)
            return
        self.dispatch_entries.append(entry)
Esempio n. 3
0
    def ProcessBlacklistNode(self, node):
        """Processes XML <blacklist> nodes into BlacklistEntry objects.

    The following information is parsed out:
      subnet: The IP, in CIDR notation.
      description: (optional)
    If there are no errors, the data is loaded into a BlackListEntry object
    and added to a list. Upon error, a description of the error is added to
    a list and the method terminates.

    Args:
      node: <blacklist> XML node in dos.xml.
    """
        tag = xml_parser_utils.GetTag(node)
        if tag != 'blacklist':
            self.errors.append('Unrecognized node: <%s>' % tag)
            return

        entry = BlacklistEntry()
        entry.subnet = xml_parser_utils.GetChildNodeText(node, 'subnet')
        entry.description = xml_parser_utils.GetChildNodeText(
            node, 'description')

        validation = self._ValidateEntry(entry)
        if validation:
            self.errors.append(validation)
            return
        self.blacklist_entries.append(entry)
Esempio n. 4
0
    def ProcessXml(self, xml_str):
        """Parses XML string and returns object representation of relevant info.

    Args:
      xml_str: The XML string.
    Returns:
      A QueueXml object containing information about task queue
      specifications from the XML.
    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """

        try:
            self.errors = []
            xml_root = ElementTree.fromstring(xml_str)

            if xml_parser_utils.GetTag(xml_root) != 'queue-entries':
                raise AppEngineConfigException(
                    'Root tag must be <queue-entries>')

            self.queue_xml = QueueXml()
            self.queue_xml.queues = []
            self.queue_xml.total_storage_limit = xml_parser_utils.GetChildNodeText(
                xml_root, 'total-storage-limit')
            for child in xml_parser_utils.GetNodes(xml_root, 'queue'):
                self.ProcessQueueNode(child)

            if self.errors:
                raise AppEngineConfigException('\n'.join(self.errors))

            return self.queue_xml

        except ElementTree.ParseError as e:
            raise AppEngineConfigException('Bad input -- not valid XML: %s' %
                                           e)