def validateTo(self, user): """ Determine whether the recipient is local to this system or not and dispatch to the appropriate helper method. """ siteStore = self.avatar.store.parent if user.dest.domain in userbase.getDomainNames(siteStore): return self.localValidateTo(user) else: return self.remoteValidateTo(user)
def subdomain(self, hostname): """ Determine of which known domain the given hostname is a subdomain. @return: A two-tuple giving the subdomain part and the domain part or C{None} if the domain is not a subdomain of any known domain. """ hostname = hostname.split(":")[0] for domain in getDomainNames(self.siteStore): if hostname.endswith("." + domain): username = hostname[:-len(domain) - 1] if username != "www": return username, domain return None
def testDomainNames(self): s = Store() acc = s for localpart, domain, internal in [(u'local', u'example.com', True), (u'local', u'example.net', True), (u'remote', u'example.org', False), (u'another', u'example.com', True), (u'brokenguy', None, True)]: userbase.LoginMethod(store=s, localpart=localpart, domain=domain, verified=True, account=s, protocol=u'test', internal=internal) self.assertEquals(userbase.getDomainNames(s), [u"example.com", u"example.net"])
def testDomainNames(self): s = Store() acc = s for localpart, domain, internal in [ ('local', 'example.com', True), ('local', 'example.net', True), ('remote', 'example.org', False), ('another', 'example.com', True), ('brokenguy', None, True)]: userbase.LoginMethod( store=s, localpart=localpart, domain=domain, verified=True, account=s, protocol='test', internal=internal) self.assertEqual(userbase.getDomainNames(s), ["example.com", "example.net"])
def rootURL(self, request): """ Return the URL for the root of this website which is appropriate to use in links generated in response to the given request. @type request: L{twisted.web.http.Request} @param request: The request which is being responded to. @rtype: L{URL} @return: The location at which the root of the resource hierarchy for this website is available. """ host = request.getHeader('host') or self.hostname if ':' in host: host = host.split(':', 1)[0] for domain in [self.hostname] + getDomainNames(self.store): if (host == domain or host.startswith('www.') and host[len('www.'):] == domain): return URL(scheme='', netloc='', pathsegs=['']) if request.isSecure(): return self.encryptedRoot(self.hostname) else: return self.cleartextRoot(self.hostname)
def getAvailableDomains(self): """ Return a list of domain names available on this site. """ return getDomainNames(self.store)
def validateFrom(self, helo, origin): if origin.domain in userbase.getDomainNames(self.store): return defer.fail(smtp.SMTPBadSender(origin)) return defer.succeed(origin)
def getHostnames(store): """ Like L{axiom.userbase.getDomainNames}, but also default to just C{['localhost']} if there are no domains. """ return userbase.getDomainNames(store) or ['localhost']