示例#1
0
    def ProcessXml(self, xml_str):
        """Parses XML string and returns object representation of relevant info.

    Args:
      xml_str: The XML string.
    Returns:
      A list of Cron objects containing information about cron jobs from the
      XML.
    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """

        try:
            self.crons = []
            self.errors = []
            xml_root = ElementTree.fromstring(xml_str)
            if xml_root.tag != 'cronentries':
                raise AppEngineConfigException(
                    'Root tag must be <cronentries>')

            for child in xml_root.getchildren():
                self.ProcessCronNode(child)

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

            return self.crons
        except ElementTree.ParseError:
            raise AppEngineConfigException('Bad input -- not valid XML')
  def ProcessXml(self, xml_str, has_jsps=False):
    """Parses XML string and returns object representation of relevant info.

    Uses ElementTree parser to return a tree representation of XML.
    Then walks down that tree and extracts important info and adds it to the
    object.

    Args:
      xml_str: The XML string itself.
      has_jsps: True if the application has *.jsp files.

    Returns:
      If there is well-formed but illegal XML, returns a list of
      errors. Otherwise, returns an AppEngineWebXml object containing
      information from XML.

    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """
    try:
      self.web_xml = WebXml()
      self.web_xml.has_jsps = has_jsps
      self.errors = []
      xml_root = ElementTree.fromstring(xml_str)
      for node in xml_root.getchildren():
        self.ProcessSecondLevelNode(node)

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

      return self.web_xml

    except ElementTree.ParseError:
      raise AppEngineConfigException('Bad input -- not valid XML')
示例#3
0
    def ProcessXml(self, xml_str):
        """Parses XML string and returns object representation of relevant info.

    Uses ElementTree parser to return a tree representation of XML.
    Then walks down that tree and extracts important info and adds it
    to the object.

    Args:
      xml_str: The XML string itself

    Returns:
      If there is well-formed but illegal XML, returns a list of
      errors. Otherwise, returns an AppEngineWebXml object containing
      information from XML.

    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """
        try:
            self.app_engine_web_xml = AppEngineWebXml()
            self.errors = []
            xml_root = ElementTree.fromstring(xml_str)

            for child in xml_root.getchildren():
                self.ProcessChildNode(child)
            self.CheckScalingConstraints()
            if self.errors:

                raise AppEngineConfigException('\n'.join(self.errors))
            return self.app_engine_web_xml
        except ElementTree.ParseError:
            raise AppEngineConfigException('Bad input -- not valid XML')
    def ProcessXml(self, xml_str):
        """Parses XML string and returns object representation of relevant info.

    Args:
      xml_str: The XML string.
    Returns:
      A list of Index objects containing information about datastore indexes
      from the XML.
    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """

        try:
            self.indexes = []
            self.errors = []
            xml_root = ElementTree.fromstring(xml_str)
            if xml_parser_utils.GetTag(xml_root) != 'datastore-indexes':
                raise AppEngineConfigException(
                    'Root tag must be <datastore-indexes>')

            for child in xml_root.getchildren():
                self.ProcessIndexNode(child)

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

            return self.indexes
        except ElementTree.ParseError:
            raise AppEngineConfigException('Bad input -- not valid XML')
示例#5
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)
示例#6
0
    def ProcessXml(self, xml_str):
        """Parses XML string and returns object representation of relevant info.

    Args:
      xml_str: The XML string.
    Returns:
      A list of DispatchEntry objects defining how URLs are dispatched to
      modules.
    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """

        try:
            self.dispatch_entries = []
            self.errors = []
            xml_root = ElementTree.fromstring(xml_str)
            if xml_root.tag != 'dispatch-entries':
                raise AppEngineConfigException(
                    'Root tag must be <dispatch-entries>')

            for child in xml_root.getchildren():
                self.ProcessDispatchNode(child)

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

            return self.dispatch_entries
        except ElementTree.ParseError:
            raise AppEngineConfigException('Bad input -- not valid XML')
    def TranslateAdditionalOptions(self, h):
        """Generates Yaml statements from security constraint information."""
        additional_statements = []

        required_role = h.GetProperty('required_role', default='none')
        required_role_translation = {
            'none': 'optional',
            '*': 'required',
            'admin': 'admin'
        }
        additional_statements.append('  login: %s' %
                                     required_role_translation[required_role])

        transport_guarantee = h.GetProperty('transport_guarantee',
                                            default='none')

        if transport_guarantee == 'none':
            if self.app_engine_web_xml.ssl_enabled:
                additional_statements.append('  secure: optional')
            else:
                additional_statements.append('  secure: never')
        else:
            if self.app_engine_web_xml.ssl_enabled:
                additional_statements.append('  secure: always')
            else:
                raise AppEngineConfigException(
                    'SSL must be enabled in appengine-web.xml to use '
                    'transport-guarantee')

        handler_id = self.web_xml.pattern_to_id.get(h.pattern)
        if handler_id and handler_id in self.app_engine_web_xml.api_endpoints:
            additional_statements.append('  api_endpoint: True')
        return additional_statements
    def ProcessXml(self, xml_str):
        """Parses XML string and returns object representation of relevant info.

    Args:
      xml_str: The XML string.
    Returns:
      A list of Backend object containg information about backends from the XML.
    Raises:
      AppEngineConfigException: In case of malformed XML or illegal inputs.
    """
        try:
            self.backends = []
            self.errors = []
            xml_root = ElementTree.fromstring(xml_str)

            for child in xml_root.getchildren():
                self.ProcessBackendNode(child)

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

            return self.backends
        except ElementTree.ParseError:
            raise AppEngineConfigException('Bad input -- not valid XML')