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)
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)
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)
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)
def ProcessQueueNode(self, node): """Processes XML <queue> nodes into Queue objects. The following information is parsed out: name mode: can be either push or pull retry-parameters: task-retry-limit ---- push queues only ---- task-age-limit min-backoff-seconds max-back-off-seconds max-doubling bucket-size max-concurrent-requests rate: how often tasks are processed on this queue. target: version of application on which tasks on this queue will be invoked. ---- pull queues only ---- acl: access control list - lists user and writer email addresses. Args: node: Current <queue> XML node being processed. """ name = xml_parser_utils.GetChildNodeText(node, 'name') if not name: self.errors.append('Must specify a name for each <queue> entry') return # push is the default mode. mode = xml_parser_utils.GetChildNodeText(node, 'mode', 'push') if mode not in ('push', 'pull'): self.errors.append(BAD_MODE_ERROR_MESSAGE % (mode, name)) return if mode == 'pull': queue = PullQueue() queue.name = name self._ProcessPullQueueNode(node, queue) else: queue = PushQueue() queue.name = name self._ProcessPushQueueNode(node, queue) self.queue_xml.queues.append(queue)
def _ProcessPushQueueNode(self, node, queue): if xml_parser_utils.GetChild(node, 'acl') is not None: self.errors.append('The element <acl> is not defined for push ' "queues; bad <queue> entry with name '%s'" % queue.name) for tag in PUSH_QUEUE_TAGS: field_name = tag.replace('-', '_') setattr(queue, field_name, xml_parser_utils.GetChildNodeText(node, tag)) self._ProcessRetryParametersNode(node, queue)
def _ProcessRetryParametersNode(node, cron): """Converts <retry-parameters> in node to cron.retry_parameters.""" retry_parameters_node = xml_parser_utils.GetChild(node, 'retry-parameters') if retry_parameters_node is None: cron.retry_parameters = None return retry_parameters = _RetryParameters() cron.retry_parameters = retry_parameters for tag in _RETRY_PARAMETER_TAGS: if xml_parser_utils.GetChild(retry_parameters_node, tag) is not None: setattr( retry_parameters, tag.replace('-', '_'), xml_parser_utils.GetChildNodeText(retry_parameters_node, tag))
def _ProcessRetryParametersNode(self, node, queue): """Pulls information out of <retry-parameters> node.""" retry_parameters_node = xml_parser_utils.GetChild( node, 'retry-parameters') if retry_parameters_node is None: queue.retry_parameters = None return retry_parameters = RetryParameters() queue.retry_parameters = retry_parameters retry_parameters.task_retry_limit = xml_parser_utils.GetChildNodeText( retry_parameters_node, 'task-retry-limit') for tag in PUSH_QUEUE_RETRY_PARAMS: # All elements but 'task-retry-limit' are specific to push queues. if xml_parser_utils.GetChild(retry_parameters_node, tag) is not None: if isinstance(queue, PullQueue): self.errors.append(RETRY_PARAM_ERROR_MESSAGE % (tag, queue.name)) else: setattr( retry_parameters, tag.replace('-', '_'), xml_parser_utils.GetChildNodeText( retry_parameters_node, tag))