__init__.py :  » Windows » pyExcelerator » pywin32-214 » com » win32comext » adsi » 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 » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » com » win32comext » adsi » __init__.py
import win32com
import win32com.client

if type(__path__)==type(''):
  # For freeze to work!
  import sys
  try:
    import adsi
    sys.modules['win32com.adsi.adsi'] = adsi
  except ImportError:
    pass
else:
  # See if we have a special directory for the binaries (for developers)
  win32com.__PackageSupportBuildPath__(__path__)


# Some helpers
# We want to _look_ like the ADSI module, but provide some additional
# helpers.

# Of specific note - most of the interfaces supported by ADSI
# derive from IDispatch - thus, you get the custome methods from the
# interface, as well as via IDispatch.
import pythoncom
from adsi import *

LCID = 0

IDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
IADsContainerType = pythoncom.TypeIIDs[adsi.IID_IADsContainer]

def _get_good_ret(ob,
          # Named arguments used internally
          resultCLSID = None):
  assert resultCLSID is None, "Now have type info for ADSI objects - fix me!"
  # See if the object supports IDispatch
  if hasattr(ob, "Invoke"):
    import win32com.client.dynamic
    name = "Dispatch wrapper around %r" %  ob
    return win32com.client.dynamic.Dispatch(ob, name, ADSIDispatch)
  return ob


class ADSIEnumerator:
  def __init__(self, ob):
    # Query the object for the container interface.
    self._cont_ = ob.QueryInterface(IID_IADsContainer)
    self._oleobj_ = ADsBuildEnumerator(self._cont_) # a PyIADsEnumVARIANT
    self.index = -1
  def __getitem__(self, index):
    return self.__GetIndex(index)
  def __call__(self, index):
    return self.__GetIndex(index)
  def __GetIndex(self, index):
    if type(index)!=type(0): raise TypeError("Only integer indexes are supported for enumerators")
    if index != self.index + 1:
      # Index requested out of sequence.
      raise ValueError("You must index this object sequentially")
    self.index = index
    result = ADsEnumerateNext(self._oleobj_, 1)
    if len(result):
      return _get_good_ret(result[0])
    # Failed - reset for next time around.
    self.index = -1
    self._oleobj_ = ADsBuildEnumerator(self._cont_) # a PyIADsEnumVARIANT
    raise IndexError("list index out of range")

class ADSIDispatch(win32com.client.CDispatch):
  def _wrap_dispatch_(self, ob, userName = None, returnCLSID = None, UnicodeToString=None):
    assert UnicodeToString is None, "this is deprectated and will be removed"
    if not userName:
      userName = "ADSI-object"
    olerepr = win32com.client.dynamic.MakeOleRepr(ob, None, None)
    return ADSIDispatch(ob, olerepr, userName)

  def _NewEnum(self):
    try:
      return ADSIEnumerator(self)
    except pythoncom.com_error:
      # doesnt support it - let our base try!
      return win32com.client.CDispatch._NewEnum(self)

  def __getattr__(self, attr):
    try:
      return getattr(self._oleobj_, attr)
    except AttributeError:
      return win32com.client.CDispatch.__getattr__(self, attr)

  def QueryInterface(self, iid):
    ret = self._oleobj_.QueryInterface(iid)
    return _get_good_ret(ret)

# We override the global methods to do the right thing.
_ADsGetObject = ADsGetObject # The one in the .pyd
def ADsGetObject(path, iid = pythoncom.IID_IDispatch):
  ret = _ADsGetObject(path, iid)
  return _get_good_ret(ret)

_ADsOpenObject = ADsOpenObject
def ADsOpenObject(path, username, password, reserved = 0, iid = pythoncom.IID_IDispatch):
  ret = _ADsOpenObject(path, username, password, reserved, iid)
  return _get_good_ret(ret)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.