Skip to content

Commit

Permalink
ticket:42 get info
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgarm committed Jul 15, 2010
1 parent 4dda46c commit 047993e
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 133 deletions.
20 changes: 20 additions & 0 deletions client/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ def call():

return f(p, zclient)
return call


def init_proxied_client(f):
def call():
logging.basicConfig(stream=sys.stdout,level=logging.DEBUG)

p = load_properties()

proxy_url = soap.proxy_url(p[pconstant.PROXY_HOSTNAME],
p[pconstant.PROXY_USERNAME],
p[pconstant.PROXY_PASSWORD],
p[pconstant.PROXY_PORT],
p[pconstant.PROXY_SCHEME])

zclient = ZimbraClient(soap.soap_url(p[pconstant.HOSTNAME]),
proxy_url=proxy_url)
zclient.authenticate(p[pconstant.ACCOUNT_NAME], p[pconstant.PASSWORD])

return f(p, zclient)
return call
25 changes: 6 additions & 19 deletions client/sample/get_info.py → client/zclient/get_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,21 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyzimbra. If not, see <http://www.gnu.org/licenses/>.
################################################################################
Account info samples.
################################################################################.
@author: ilgar
"""
from client.util import load_properties
from pyzimbra import soap, sconstant
from pyzimbra.z.client import ZimbraClient
from test import pconstant
import logging
import sys

from client.util import init_client
from pyzimbra import sconstant

def get_info():
p = load_properties()

zclient = ZimbraClient(soap.soap_url(p[pconstant.HOSTNAME]))
zclient.authenticate(p[pconstant.ACCOUNT_NAME], p[pconstant.PASSWORD])
@init_client
def run(p, zclient):

params = {sconstant.A_SECTIONS: sconstant.V_MBOX}
info = zclient.get_info(params)

print info
print info.name


if __name__ == '__main__':
logging.basicConfig(stream=sys.stdout,level=logging.DEBUG)

get_info()
run()
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,21 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyzimbra. If not, see <http://www.gnu.org/licenses/>.
################################################################################
Account info samples.
################################################################################.
@author: ilgar
"""
from client.util import load_properties
from pyzimbra import soap, sconstant
from pyzimbra.z.client import ZimbraClient
from test import pconstant
import logging
import sys

from client.util import init_proxied_client
from pyzimbra import sconstant

def get_proxied_info():
p = load_properties()

proxy_url = soap.proxy_url(p[pconstant.PROXY_HOSTNAME],
p[pconstant.PROXY_USERNAME],
p[pconstant.PROXY_PASSWORD],
p[pconstant.PROXY_PORT],
p[pconstant.PROXY_SCHEME])
zclient = ZimbraClient(soap.soap_url(p[pconstant.HOSTNAME]),
proxy_url=proxy_url)
zclient.authenticate(p[pconstant.ACCOUNT_NAME], p[pconstant.PASSWORD])
@init_proxied_client
def run(p, zclient):

params = {sconstant.A_SECTIONS: sconstant.V_MBOX}
info = zclient.get_info(params)

print info
print info.name


if __name__ == '__main__':
logging.basicConfig(stream=sys.stdout,level=logging.DEBUG)

get_proxied_info()
run()
3 changes: 2 additions & 1 deletion pyzimbra/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ def __init__(self):

# ------------------------------------------------------------------ unbound
@abc.abstractmethod
def invoke(self, ns, request_name, params, auth_token):
def invoke(self, ns, request_name, params, auth_token, simplify):
"""
Invokes zimbra request.
@param ns: namespace of the request method
@param request_name: name of the request method
@param params: parameters to pass to method call
@param auth_token: authentication token to use for session
@param simplify: True to return python object, False to return xml struct
@return: zimbra response
"""
if auth_token == None:
Expand Down
15 changes: 12 additions & 3 deletions pyzimbra/soap_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ def __init__(self):


# ------------------------------------------------------------------ unbound
def invoke(self, ns, request_name, params, auth_token):
def invoke(self, ns, request_name, params, auth_token, simplify=False):
"""
Invokes zimbra soap request.
"""
ZimbraClientTransport.invoke(self, ns, request_name, params, auth_token)
ZimbraClientTransport.invoke(self,
ns,
request_name,
params,
auth_token,
simplify)

headers = SOAPpy.Types.headerType()

Expand All @@ -65,7 +70,11 @@ def invoke(self, ns, request_name, params, auth_token):
context._ns = (zconstant.SOAP_DEFAULT_PREFIX, zconstant.NS_ZIMBRA_URL)
headers.context = context

proxy = SOAPpy.SOAPProxy(self.soap_url, ns, header=headers, noroot=1)
proxy = SOAPpy.SOAPProxy(self.soap_url,
ns,
header=headers,
noroot=1,
simplify_objects=simplify)
proxy.config.debug = self.log.isEnabledFor(logging.DEBUG)
proxy.config.strictNamespaces = 0
proxy.config.buildWithNamespacePrefix = 0
Expand Down
1 change: 0 additions & 1 deletion pyzimbra/z/zobject/__init__.py

This file was deleted.

71 changes: 0 additions & 71 deletions pyzimbra/z/zobject/account.py

This file was deleted.

5 changes: 0 additions & 5 deletions pyzimbra/z/zobject/datasource.py

This file was deleted.

5 changes: 0 additions & 5 deletions pyzimbra/z/zobject/folder.py

This file was deleted.

9 changes: 7 additions & 2 deletions pyzimbra/zclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ def __init__(self, soap_url, domains={}, proxy_url=None):


# ------------------------------------------------------------------ unbound
def invoke(self, ns, request_name, params={}):
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
Expand All @@ -79,7 +80,11 @@ def invoke(self, ns, request_name, params={}):
if util.empty(request_name):
raise ZimbraClientException('Invalid request')

return self.transport.invoke(ns, request_name, params, self.auth_token)
return self.transport.invoke(ns,
request_name,
params,
self.auth_token,
simplify)


@abc.abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion test/mock/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self):


# ------------------------------------------------------------------ unbound
def invoke(self, ns, request_name, params, auth_token):
def invoke(self, ns, request_name, params, auth_token, simplify=False):

if auth_token.token == None:
auth_token.token = self.token
Expand Down

0 comments on commit 047993e

Please sign in to comment.