示例#1
0
   def __getattr__(self, name):
      """support client.cs to access to collection.

         eg.
         cc = client()
         cs = cc.test
         cl = cs.test_cl  # access to collection named 'test_cl'

         and we should pass '__members__' and '__methods__',
         becasue dir(cc) will invoke __getattr__("__members__") and
         __getattr__("__methods__").

         if success, a collection object will be returned.

      Exceptions:
         pysequoiadb.error.SDBBaseError
      """
      if '__members__' == name or '__methods__' == name:
         pass
      else:
         try:
            cl = collection()
            rc = sdb.cs_get_collection(self._cs, name, cl._cl)
            pysequoiadb._raise_if_error("Failed to get collection: %s" %
                                        name, rc)
         except SDBBaseError:
            del cl;
            cl = None
            raise

         return cl
示例#2
0
   def get_collection(self, cl_name):
      """Get the named collection.
         
      Parameters:
         Name         Type     Info:
         cl_name      str      The full name of the collection..
      Return values:
         a collection object of query
      Exceptions:
         pysequoiadb.error.SDBTypeError
         pysequoiadb.error.SDBBaseError
      """
      if not isinstance(cl_name, basestring):
         raise SDBTypeError("collection must be an instance of basestring")

      try:
         cl = collection()
         rc = sdb.cs_get_collection(self._cs, cl_name, cl._cl)
         pysequoiadb._raise_if_error("Failed to get collection: %s" %
                                     cl_name, rc)
      except SDBBaseError:
         del cl
         cl = None
         raise

      return cl