GoogleSOAPFacade.py :  » Search » PyGoogle » pygoogle-0.6 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Search » PyGoogle 
PyGoogle » pygoogle 0.6 » GoogleSOAPFacade.py
"""
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.