def testAuthTokenNotEmpty(self): auth_token = AuthToken() auth_token.account_name = 'account' auth_token.token = 'token' auth_token.session_id = 'sessionid' self.assertFalse(util.empty(auth_token.account_name)) self.assertFalse(util.empty(auth_token.token)) self.assertFalse(util.empty(auth_token.session_id))
def soap_url(hostname): """ @return: absolute zimbra soap endpoint url @raise SoapException: if hostname is empty """ if util.empty(hostname): raise SoapException('Empty hostname') return 'http://%s%s' % (hostname, zconstant.SOAP_URL)
def admin_soap_url(hostname): """ @return: absolute zimbra administrative soap endpoint url @raise SoapException: if hostname is empty """ if util.empty(hostname): raise SoapException('Empty hostname') return 'https://%s%s' % (hostname, zconstant.SOAP_ADMIN_URL)
def build_opener(self): """ Builds url opener, initializing proxy. @return: OpenerDirector """ http_handler = urllib2.HTTPHandler() # debuglevel=self.transport.debug if util.empty(self.transport.proxy_url): return urllib2.build_opener(http_handler) proxy_handler = urllib2.ProxyHandler({self.transport.proxy_url[:4]: self.transport.proxy_url}) return urllib2.build_opener(http_handler, proxy_handler)
def proxy_url(hostname, username=None, password=None, port=0, scheme='http'): """ @return: absolute proxy url @raise SoapException: if scheme or hostname is empty """ if util.empty(hostname): raise SoapException('Empty hostname') if util.empty(scheme): raise SoapException('Empty scheme') hostport = hostname if port > 0 and (scheme != 'http' or port != 80): hostport = '%s:%s' % (hostname, port) userpass = '' if not util.empty(username): userpass = '******' % (username, password) url = '%s://%s%s' % (scheme, userpass, hostport) return url
def authenticate(self, transport, account_name, password): """ Authenticates account, if no password given tries to pre-authenticate. @param transport: transport to use for method calls @param account_name: account name @param password: account password @return: AuthToken if authentication succeeded @raise AuthException: if authentication fails """ if not isinstance(transport, ZimbraClientTransport): raise ZimbraClientException('Invalid transport') if util.empty(account_name): raise AuthException('Empty account name')
def build_opener(self): """ Builds url opener, initializing proxy. @return: OpenerDirector """ http_handler = urllib2.HTTPHandler() # debuglevel=self.transport.debug if util.empty(self.transport.proxy_url): return urllib2.build_opener(http_handler) proxy_handler = urllib2.ProxyHandler( {self.transport.proxy_url[:4]: self.transport.proxy_url}) return urllib2.build_opener(http_handler, proxy_handler)
def invoke(self, ns, request_name, params={}, simplify=False): """ Invokes zimbra method using established authentication session. @param req: zimbra request @parm params: request params @param simplify: True to return python object, False to return xml struct @return: zimbra response @raise AuthException: if authentication fails @raise SoapException: wrapped server exception """ if self.auth_token == None: raise AuthException('Unable to invoke zimbra method') if util.empty(request_name): raise ZimbraClientException('Invalid request') return self.transport.invoke(ns, request_name, params, self.auth_token, simplify)
def testEmptyString(self): result = util.empty("") self.assertTrue(result) result = util.empty("some string") self.assertFalse(result)
def testEmptyNone(self): result = util.empty(None) self.assertTrue(result)