当前位置: 首页>>代码示例>>Python>>正文


Python new.classobj方法代码示例

本文整理汇总了Python中new.classobj方法的典型用法代码示例。如果您正苦于以下问题:Python new.classobj方法的具体用法?Python new.classobj怎么用?Python new.classobj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在new的用法示例。


在下文中一共展示了new.classobj方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cp13736

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def test_cp13736(self):
        import os
        _f_imp_cp13736 = os.path.join(self.test_dir, "impcp13736.py")
        shortName = _f_imp_cp13736.rsplit(os.sep, 1)[1].split(".")[0]

        self.write_to_file(_f_imp_cp13736, """
class Test(object):
    def a(self):
        return 34
""")

        import sys
        if sys.platform=="win32" and "." not in sys.path:
            sys.path.append(".")
        import new
        import imp

        moduleInfo = imp.find_module(shortName)
        module = imp.load_module(shortName, moduleInfo[0], moduleInfo[1], moduleInfo[2])
        t = new.classobj('Test1', (getattr(module, 'Test'),), {})
        i = t()
        self.assertEqual(i.a(), 34)

        moduleInfo[0].close()
        self.delete_files(_f_imp_cp13736) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_imp.py

示例2: makeSQLTests

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def makeSQLTests(base, suffix, globals):
    """
    Make a test case for every db connector which can connect.

    @param base: Base class for test case. Additional base classes
                 will be a DBConnector subclass and unittest.TestCase
    @param suffix: A suffix used to create test case names. Prefixes
                   are defined in the DBConnector subclasses.
    """
    connectors = [GadflyConnector, SQLiteConnector, PyPgSQLConnector,
                  PsycopgConnector, MySQLConnector, FirebirdConnector]
    for connclass in connectors:
        name = connclass.TEST_PREFIX + suffix
        klass = new.classobj(name, (connclass, base, unittest.TestCase), base.__dict__)
        globals[name] = klass

# GadflyADBAPITestCase SQLiteADBAPITestCase PyPgSQLADBAPITestCase
# PsycopgADBAPITestCase MySQLADBAPITestCase FirebirdADBAPITestCase 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_adbapi.py

示例3: makeSQLTests

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def makeSQLTests(base, suffix, globals):
    """Make a test case for every db connector which can connect.

    @param base: Base class for test case. Additional base classes
                 will be a DBConnector subclass and unittest.TestCase
    @param suffix: A suffix used to create test case names. Prefixes
                   are defined in the DBConnector subclasses.
    """
    connectors = [GadflyConnector, SQLiteConnector, PyPgSQLConnector,
                  PsycopgConnector, MySQLConnector, FirebirdConnector]
    for connclass in connectors:
        name = connclass.TEST_PREFIX + suffix
        import new
        klass = new.classobj(name, (connclass, base, unittest.TestCase), {})
        globals[name] = klass

# GadflyADBAPITestCase SQLiteADBAPITestCase PyPgSQLADBAPITestCase
# PsycopgADBAPITestCase MySQLADBAPITestCase FirebirdADBAPITestCase 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:20,代码来源:test_adbapi.py

示例4: __init__

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def __init__(self):
        self.serial = None
        self.response = None
        self.method = 0
        self.hwndMarantzControl = None

        for groupname, list in commandsList:
            group = self.AddGroup(groupname)
            for classname, title, desc, app, serial in list:
                if desc is None:
                    desc = title
                clsAttributes = dict(name=title, description=desc, appcmd=app, serialcmd=serial)
                cls = new.classobj(classname, (MarantzSerialAction,), clsAttributes)
                group.AddAction(cls)

        group = self.AddGroup('Volume')
        group.AddAction(MarantzSerialSetVolumeAbsolute)
        group.AddAction(MarantzSerialSetVolumeRelative) 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:20,代码来源:__init__.py

示例5: hook__setattr__

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def hook__setattr__(obj):
    if not hasattr(obj,'__attrproxy__'):
        C = obj.__class__
        import new
        obj.__class__=new.classobj(C.__name__,(C,)+C.__bases__,
            {'__attrproxy__':[],
            '__setattr__':lambda self,k,v,osa=getattr(obj,'__setattr__',None),hook=hook: hook(self,k,v,osa)}) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:attrmap.py

示例6: save_classobj

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def save_classobj(self, obj):
    """ Save an interactively defined classic class object by value """
    if obj.__module__ == '__main__':
        args = (obj.__name__, obj.__bases__, obj.__dict__)
        self.save_reduce(new.classobj, args, obj=obj)
    else:
        pickle.Pickler.save_global(self, obj, name) 
开发者ID:ActiveState,项目名称:code,代码行数:9,代码来源:recipe-572213.py

示例7: get_options_dict

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def get_options_dict(configFile):
  f = open(configFile)
  d = yaml.load(f)
  f.close()
  objs = {}
  for k,v in d.items():
    oClz = classobj('%sOptions'%k.capitalize(),(ConfigOptions,), {})
    obj = oClz(**d[k])
    objs[oClz.__name__]=obj
  return ConfigOptions(**objs)
# 
开发者ID:ActiveState,项目名称:code,代码行数:13,代码来源:recipe-577130.py

示例8: __init__

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def __init__(self):
        self.host = "localhost"
        self.port = 2663
        self.isSessionRunning = False
        self.timeline = ""
        self.waitStr = None
        self.waitFlag = threading.Event()
        self.PlayState = -1
        self.lastMessage = {}
        self.lastSubtitleNum = 0
        self.lastSubtitlesEnabled = False
        self.lastAudioTrackNum = 0

        group = self.AddGroup('Requests')
        for className, scancode, descr in ttRequests:
            clsAttributes = dict(name=descr, value=scancode)
            cls = new.classobj(className, (stdAction,), clsAttributes)
            group.AddAction(cls)

        group = self.AddGroup('Commands')
        for className, scancode, descr, ParamDescr in ttCommands:
            clsAttributes = dict(name=descr, value=scancode)
            if ParamDescr == "":
                 if className[0:3] == "IP_":
                    cls = new.classobj(className, (stdAction,), clsAttributes)
                 else:
                    cls = new.classobj(className, (wmAction,), clsAttributes)
            else:
                cls = new.classobj(className, (stdActionWithStringParameter,), clsAttributes)
                cls.parameterDescription = ParamDescr
            group.AddAction(cls) 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:33,代码来源:__init__.py

示例9: WithEvents

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def WithEvents(disp, user_event_class):
  """Similar to DispatchWithEvents - except that the returned
  object is *not* also usable as the original Dispatch object - that is
  the returned object is not dispatchable.

  The difference is best summarised by example.

  >>> class IEEvents:
  ...    def OnVisible(self, visible):
  ...       print "Visible changed:", visible
  ...
  >>> ie = Dispatch("InternetExplorer.Application")
  >>> ie_events = WithEvents(ie, IEEvents)
  >>> ie.Visible = 1
  Visible changed: 1

  Compare with the code sample for DispatchWithEvents, where you get a
  single object that is both the interface and the event handler.  Note that
  the event handler instance will *not* be able to use 'self.' to refer to
  IE's methods and properties.

  This is mainly useful where using DispatchWithEvents causes
  circular reference problems that the simple proxy doesn't deal with
  """
  disp = Dispatch(disp)
  if not disp.__class__.__dict__.get("CLSID"): # Eeek - no makepy support - try and build it.
    try:
      ti = disp._oleobj_.GetTypeInfo()
      disp_clsid = ti.GetTypeAttr()[0]
      tlb, index = ti.GetContainingTypeLib()
      tla = tlb.GetLibAttr()
      gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0)
      # Get the class from the module.
      disp_class = gencache.GetClassForProgID(str(disp_clsid))
    except pythoncom.com_error:
      raise TypeError("This COM object can not automate the makepy process - please run makepy manually for this object")
  else:
    disp_class = disp.__class__
  # Get the clsid
  clsid = disp_class.CLSID
  # Create a new class that derives from 2 classes - the event sink
  # class and the user class.
  import new
  events_class = getevents(clsid)
  if events_class is None:
    raise ValueError("This COM object does not support events.")
  result_class = new.classobj("COMEventClass", (events_class, user_event_class), {})
  instance = result_class(disp) # This only calls the first base class __init__.
  if hasattr(user_event_class, "__init__"):
    user_event_class.__init__(instance)
  return instance 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:53,代码来源:__init__.py

示例10: watchObject

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def watchObject(self, object, identifier, callback):
        """Watch the given object.

        Whenever I think the object might have changed, I'll send an
        ObjectLink of it to the callback.

        The identifier argument is used to generate identifiers for
        objects which are members of this one.
        """
        if type(object) is not types.InstanceType:
            raise TypeError, "Sorry, can only place a watch on Instances."

        # uninstallers = []

        dct = {}
        reflect.addMethodNamesToDict(object.__class__, dct, '')
        for k in object.__dict__.keys():
            dct[k] = 1

        members = dct.keys()

        clazzNS = {}
        clazz = new.classobj('Watching%s%X' %
                             (object.__class__.__name__, id(object)),
                             (_MonkeysSetattrMixin, object.__class__,),
                             clazzNS)

        clazzNS['_watchEmitChanged'] = new.instancemethod(
            lambda slf, i=identifier, b=self, cb=callback:
            cb(b.browseObject(slf, i)),
            None, clazz)

        # orig_class = object.__class__
        object.__class__ = clazz

        for name in members:
            m = getattr(object, name)
            # Only hook bound methods.
            if ((type(m) is types.MethodType)
                and (m.im_self is not None)):
                # What's the use of putting watch monkeys on methods
                # in addition to __setattr__?  Well, um, uh, if the
                # methods modify their attributes (i.e. add a key to
                # a dictionary) instead of [re]setting them, then
                # we wouldn't know about it unless we did this.
                # (Is that convincing?)

                monkey = _WatchMonkey(object)
                monkey.install(name)
                # uninstallers.append(monkey.uninstall)

        # XXX: This probably prevents these objects from ever having a
        # zero refcount.  Leak, Leak!
        ## self.watchUninstallers[object] = uninstallers 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:56,代码来源:explorer.py

示例11: _copyReusedRecipes

# 需要导入模块: import new [as 别名]
# 或者: from new import classobj [as 别名]
def _copyReusedRecipes(self):
        # XXX HACK - get rid of this when we move the
        # recipe classes to the repository.
        # makes copies of some of the superclass recipes that are
        # created in this module.  (specifically, the ones with buildreqs)
        recipeClassDict = {}
        for recipeClass in self.module.__dict__.values():
            if (type(recipeClass) != type or
                    not issubclass(recipeClass, recipe.Recipe)):
                continue
            numParents = len(inspect.getmro(recipeClass))
            recipeClassDict[recipeClass.__name__] = (numParents, recipeClass)
        # create copies of recipes by the number of parents they have
        # a class always has more parents than its parent does,
        # if you copy the superClasses first, the copies will.
        recipeClasses = [ x[1]  for x in sorted(recipeClassDict.values(),
                                                key=lambda x: x[0]) ]
        for recipeClass in recipeClasses:
            className = recipeClass.__name__
            # when we create a new class object, it needs its superclasses.
            # get the original superclass list and substitute in any
            # copies
            mro = list(inspect.getmro(recipeClass)[1:])
            newMro = []
            for superClass in mro:
                superName = superClass.__name__
                newMro.append(self.module.__dict__.get(superName, superClass))

            newDict = {}
            for name, attr in recipeClass.__dict__.iteritems():
                if type(attr) in [ types.ModuleType, types.MethodType,
                                   types.UnboundMethodType,
                                   types.FunctionType,
                                   staticmethod,
                                   # don't copy in flags, as they
                                   # need to have their data copied out
                                   use.LocalFlagCollection]:
                    newDict[name] = attr
                else:
                    newDict[name] = copy.deepcopy(attr)

            self.module.__dict__[className] = \
                            new.classobj(className, tuple(newMro), newDict) 
开发者ID:sassoftware,项目名称:conary,代码行数:45,代码来源:loadrecipe.py


注:本文中的new.classobj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。