Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/google/GoogleSOAPFacade.py
blob: 0aab3cf40c2b006d8ba216f9dc1410680da0f642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Facade that hides the differences between the SOAPpy and SOAP.py
libraries, so that google.py doesn't have to deal with them.

@author:     Brian Landers <brian@bluecoat93.org>
@license:    Python
@version:    0.5.4
"""

import warnings
from distutils.version import LooseVersion

__author__    = "Brian Landers <brian@bluecoat93.org>"
__version__ = "0.6"
__license__ = "Python"

#
# Wrapper around the python 'warnings' facility
#
def warn( message, level=RuntimeWarning ):
    warnings.warn( message, level, stacklevel=3 )
    
# We can't use older version of SOAPpy, due to bugs that break the Google API
minSOAPpyVersion = "0.11.3"

#
# Try loading SOAPpy first.  If that fails, fall back to the old SOAP.py
#
SOAPpy = None
try:
    import SOAPpy
    from SOAPpy import SOAPProxy, Types
    
    if LooseVersion( minSOAPpyVersion ) > \
       LooseVersion( SOAPpy.version.__version__ ):
       
        warn( "Versions of SOAPpy before %s have known bugs that prevent " +
              "PyGoogle from functioning." % minSOAPpyVersion )
        raise ImportError
        
except ImportError:
    warn( "SOAPpy not imported. Trying legacy SOAP.py.",
          DeprecationWarning )
    try:
        import SOAP
    except ImportError:
        raise RuntimeError( "Unable to find SOAPpy or SOAP. Can't continue.\n" )

#
# Constants that differ between the modules
#
if SOAPpy:
    false      = Types.booleanType(0)
    true       = Types.booleanType(1)
    structType = Types.structType
    faultType  = Types.faultType
else:
    false      = SOAP.booleanType(0)
    true       = SOAP.booleanType(1)
    structType = SOAP.structType
    faultType  = SOAP.faultType

#
# Get a SOAP Proxy object in the correct way for the module we're using
#
def getProxy( url, namespace, http_proxy ):    
    if SOAPpy:
        return SOAPProxy( url,
                          namespace  = namespace,
                          http_proxy = http_proxy )
    
    else:
        return SOAP.SOAPProxy( url,
                               namespace  = namespace,
                               http_proxy = http_proxy )

#
# Convert an object to a dictionary in the proper way for the module
# we're using for SOAP
#
def toDict( obj ):
    if SOAPpy:
        return obj._asdict()
    else:
        return obj._asdict