def __init__(self,
                 package_path=None,
                 owner_name=None,
                 owner_domain=None,
                 parent=None,
                 language_model=None):
        """Construct a Module.

    Args:
      package_path: (str) A '/' delimited path to this module.
      owner_name: (str) The name of the owner of the API, as they would like it
        to appear in library code. E.g "Best Buy"
      owner_domain: (str) The domain of the owner of the API, as they would like
        it to appear in library code.
      parent: (CodeObject) The parent of this element.
      language_model: (LanguageModel) The language we are targetting.
        Dynamically defaults to the parent's language model.
    """
        super(Module, self).__init__({},
                                     None,
                                     parent=parent,
                                     language_model=language_model)
        self._package_path = utilities.NoSpaces(package_path)
        self._owner_name = utilities.NoSpaces(owner_name)
        self._owner_domain = utilities.SanitizeDomain(owner_domain)
        self._name = None  # will be memoized on first call to name property
Пример #2
0
    def _NormalizeOwnerInformation(self):
        """Ensure that owner and ownerDomain are set to sane values."""
        owner_domain = self.get('ownerDomain', '')
        if not owner_domain:
            root_url = self.get('rootUrl')
            if root_url:
                owner_domain = urlparse.urlparse(root_url).hostname
                # Normalize google domains.
                if any(
                        owner_domain.endswith(d)
                        for d in _RECOGNIZED_GOOGLE_DOMAINS):
                    owner_domain = 'google.com'
        if owner_domain:
            owner_domain = utilities.SanitizeDomain(owner_domain)
        else:
            owner_domain = _DEFAULT_OWNER_DOMAIN

        self.SetTemplateValue('ownerDomain', owner_domain)
        if not self.get('ownerName'):
            if owner_domain == _DEFAULT_OWNER_DOMAIN:
                owner_name = _DEFAULT_OWNER_NAME
            else:
                owner_name = owner_domain.replace('.', '_')
            self.SetTemplateValue('ownerName', owner_name)
        if not self.get('owner'):
            self.SetTemplateValue('owner', self['ownerName'].lower())
Пример #3
0
 def testSanitizeDomain(self):
     self.assertIsNone(utilities.SanitizeDomain(None))
     self.assertEquals('google.com', utilities.SanitizeDomain('google.com'))
     self.assertEquals('google.com', utilities.SanitizeDomain('GooglE.com'))
     self.assertEquals('google.com',
                       utilities.SanitizeDomain('goo|gle.com'))
     self.assertEquals('google.com',
                       utilities.SanitizeDomain('goo gle.com'))
     self.assertEquals('googl.com', utilities.SanitizeDomain('googlê.com'))
     self.assertEquals('www_test.appspot.com',
                       utilities.SanitizeDomain('www-test.appspot.com'))