Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
xpcom.server.policy.DefaultPolicy Class Reference

List of all members.

Public Member Functions

def __init__

Private Member Functions

def _QueryInterface_
def _MakeInterfaceParam_
def _CallMethod_
def _doHandleException
def _CallMethodException_
def _GatewayException_

Private Attributes

 _obj_
 _nominated_interfaces_
 _iid_
 _interface_info_
 _interface_iid_map_

Detailed Description

Definition at line 136 of file policy.py.


Constructor & Destructor Documentation

def xpcom.server.policy.DefaultPolicy.__init__ (   self,
  instance,
  iid 
)

Definition at line 137 of file policy.py.

00137 
00138     def __init__(self, instance, iid):
00139         self._obj_ = instance
00140         self._nominated_interfaces_ = ni = _GetNominatedInterfaces(instance)
00141         self._iid_ = iid
00142         if ni is None:
00143             raise ValueError, "The object '%r' can not be used as a COM object" % (instance,)
00144         # This is really only a check for the user
00145         if __debug__:
00146             if iid != IID_nsISupports and iid not in ni:
00147                 # The object may delegate QI.
00148                 delegate_qi = getattr(instance, "_query_interface_", None)
00149                 # Perform the actual QI and throw away the result - the _real_
00150                 # QI performed by the framework will set things right!
00151                 if delegate_qi is None or not delegate_qi(iid):
00152                     raise ServerException(nsError.NS_ERROR_NO_INTERFACE)
00153         # Stuff for the magic interface conversion.
00154         self._interface_info_ = None
00155         self._interface_iid_map_ = {} # Cache - Indexed by (method_index, param_index)


Member Function Documentation

def xpcom.server.policy.DefaultPolicy._CallMethod_ (   self,
  com_object,
  index,
  info,
  params 
) [private]

Definition at line 247 of file policy.py.

00247 
00248     def _CallMethod_(self, com_object, index, info, params):
00249         #print "_CallMethod_", index, info, params
00250         flags, name, param_descs, ret = info
00251         assert ret[1][0] == xpcom_consts.TD_UINT32, "Expected an nsresult (%s)" % (ret,)
00252         if XPT_MD_IS_GETTER(flags):
00253             # Look for a function of that name
00254             func = getattr(self._obj_, "get_" + name, None)
00255             if func is None:
00256                 assert len(param_descs)==1 and len(params)==0, "Can only handle a single [out] arg for a default getter"
00257                 ret = getattr(self._obj_, name) # Let attribute error go here!
00258             else:
00259                 ret = func(*params)
00260             return 0, ret
00261         elif XPT_MD_IS_SETTER(flags):
00262             # Look for a function of that name
00263             func = getattr(self._obj_, "set_" + name, None)
00264             if func is None:
00265                 assert len(param_descs)==1 and len(params)==1, "Can only handle a single [in] arg for a default setter"
00266                 setattr(self._obj_, name, params[0]) # Let attribute error go here!
00267             else:
00268                 func(*params)
00269             return 0
00270         else:
00271             # A regular method.
00272             func = getattr(self._obj_, name)
00273             return 0, func(*params)

def xpcom.server.policy.DefaultPolicy._CallMethodException_ (   self,
  com_object,
  index,
  info,
  params,
  exc_info 
) [private]

Definition at line 294 of file policy.py.

00294 
00295     def _CallMethodException_(self, com_object, index, info, params, exc_info):
00296         # Later we may want to have some smart "am I debugging" flags?
00297         # Or maybe just delegate to the actual object - it's probably got the best
00298         # idea what to do with them!
00299         flags, name, param_descs, ret = info
00300         exc_typ, exc_val, exc_tb = exc_info
00301         # use the xpt module to get a better repr for the method.
00302         # But if we fail, ignore it!
00303         try:
00304             import xpcom.xpt
00305             m = xpcom.xpt.Method(info, index, None)
00306             func_repr = m.Describe().lstrip()
00307         except:
00308             func_repr = "%s(%r)" % (name, param_descs)
00309         return self._doHandleException(func_repr, exc_info)

Here is the call graph for this function:

def xpcom.server.policy.DefaultPolicy._doHandleException (   self,
  func_name,
  exc_info 
) [private]

Definition at line 274 of file policy.py.

00274 
00275     def _doHandleException(self, func_name, exc_info):
00276         exc_val = exc_info[1]
00277         is_server_exception = isinstance(exc_val, ServerException)
00278         if is_server_exception:
00279             if xpcom.verbose:
00280                 print "** Information:  '%s' raised COM Exception %s" % (func_name, exc_val)
00281                 traceback.print_exception(exc_info[0], exc_val, exc_info[2])
00282                 print "** Returning nsresult from existing exception", exc_val
00283             return exc_val.errno
00284         # Unhandled exception - always print a warning.
00285         print "** Unhandled exception calling '%s'" % (func_name,)
00286         traceback.print_exception(exc_info[0], exc_val, exc_info[2])
00287         print "** Returning nsresult of NS_ERROR_FAILURE"
00288         return nsError.NS_ERROR_FAILURE
00289 

Here is the caller graph for this function:

def xpcom.server.policy.DefaultPolicy._GatewayException_ (   self,
  name,
  exc_info 
) [private]

Definition at line 313 of file policy.py.

00313 
00314     def _GatewayException_(self, name, exc_info):
00315         return self._doHandleException(name, exc_info)

Here is the call graph for this function:

def xpcom.server.policy.DefaultPolicy._MakeInterfaceParam_ (   self,
  interface,
  iid,
  method_index,
  mi,
  param_index 
) [private]

Definition at line 196 of file policy.py.

00196 
00197     def _MakeInterfaceParam_(self, interface, iid, method_index, mi, param_index):
00198         # Wrap a "raw" interface object in a nice object.  The result of this
00199         # function will be passed to one of the gateway methods.
00200         if iid is None:
00201             # look up the interface info - this will be true for all xpcom called interfaces.
00202             if self._interface_info_ is None:
00203                 import xpcom.xpt
00204                 self._interface_info_ = xpcom.xpt.Interface( self._iid_ )
00205             iid = self._interface_iid_map_.get( (method_index, param_index))
00206             if iid is None:
00207                 iid = self._interface_info_.GetIIDForParam(method_index, param_index)
00208                 self._interface_iid_map_[(method_index, param_index)] = iid
00209         # handle nsIVariant
00210         if iid == IID_nsIVariant:
00211             interface = interface.QueryInterface(iid)
00212             dt = interface.dataType
00213             if dt in VARIANT_INT_TYPES:
00214                 return interface.getAsInt32()
00215             if dt in VARIANT_LONG_TYPES:
00216                 return interface.getAsInt64()
00217             if dt in VARIANT_FLOAT_TYPES:
00218                 return interface.getAsFloat()
00219             if dt in VARIANT_STRING_TYPES:
00220                 return interface.getAsStringWithSize()
00221             if dt in VARIANT_UNICODE_TYPES:
00222                 return interface.getAsWStringWithSize()
00223             if dt == xpcom_consts.VTYPE_BOOL:
00224                 return interface.getAsBool()
00225             if dt == xpcom_consts.VTYPE_INTERFACE:
00226                 return interface.getAsISupports()
00227             if dt == xpcom_consts.VTYPE_INTERFACE_IS:
00228                 return interface.getAsInterface()
00229             if dt == xpcom_consts.VTYPE_EMPTY or dt == xpcom_consts.VTYPE_VOID:
00230                 return None
00231             if dt == xpcom_consts.VTYPE_ARRAY:
00232                 return interface.getAsArray()
00233             if dt == xpcom_consts.VTYPE_EMPTY_ARRAY:
00234                 return []
00235             if dt == xpcom_consts.VTYPE_ID:
00236                 return interface.getAsID()
00237             # all else fails...
00238             print "Warning: nsIVariant type %d not supported - returning a string" % (dt,)
00239             try:
00240                 return interface.getAsString()
00241             except COMException:
00242                 print "Error: failed to get Variant as a string - returning variant object"
00243                 traceback.print_exc()
00244                 return interface
00245             
00246         return client.Component(interface, iid)
    
def xpcom.server.policy.DefaultPolicy._QueryInterface_ (   self,
  com_object,
  iid 
) [private]

Definition at line 156 of file policy.py.

00156 
00157     def _QueryInterface_(self, com_object, iid):
00158         # Framework allows us to return a single boolean integer,
00159         # or a COM object.
00160         if iid in self._nominated_interfaces_:
00161             # We return the underlying object re-wrapped
00162             # in a new gateway - which is desirable, as one gateway should only support
00163             # one interface (this wont affect the users of this policy - we can have as many
00164             # gateways as we like pointing to the same Python objects - the users never
00165             # see what object the call came in from.
00166             # NOTE: We could have simply returned the instance and let the framework
00167             # do the auto-wrap for us - but this way we prevent a round-trip back into Python
00168             # code just for the autowrap.
00169             return xpcom.server.WrapObject(self._obj_, iid, bWrapClient = 0)
00170 
00171         # Always support nsIClassInfo 
00172         if iid == _xpcom.IID_nsIClassInfo:
00173             return GetClassInfoForObject(self._obj_)
00174 
00175         # See if the instance has a QI
00176         # use lower-case "_query_interface_" as win32com does, and it doesnt really matter.
00177         delegate = getattr(self._obj_, "_query_interface_", None)
00178         if delegate is not None:
00179             # The COM object itself doesnt get passed to the child
00180             # (again, as win32com doesnt).  It is rarely needed
00181             # (in win32com, we dont even pass it to the policy, although we have identified
00182             # one place where we should - for marshalling - so I figured I may as well pass it
00183             # to the policy layer here, but no all the way down to the object.
00184             return delegate(iid)
00185         # Finally see if we are being queried for one of the "nsISupports primitives"
00186         if not _supports_primitives_map_:
00187             iim = _xpcom.XPTI_GetInterfaceInfoManager()
00188             for (iid_name, attr, cvt) in _supports_primitives_data_:
00189                 special_iid = iim.GetInfoForName(iid_name).GetIID()
00190                 _supports_primitives_map_[special_iid] = (attr, cvt)
00191         attr, cvt = _supports_primitives_map_.get(iid, (None,None))
00192         if attr is not None and hasattr(self._obj_, attr):
00193             return xpcom.server.WrapObject(SupportsPrimitive(iid, self._obj_, attr, cvt), iid, bWrapClient = 0)
00194         # Out of clever things to try!
00195         return None # We dont support this IID.

Here is the call graph for this function:


Member Data Documentation

Definition at line 140 of file policy.py.

Definition at line 154 of file policy.py.

Definition at line 153 of file policy.py.

Definition at line 139 of file policy.py.

Definition at line 138 of file policy.py.


The documentation for this class was generated from the following file: