コード例 #1
0
ファイル: config.py プロジェクト: mmorage/DRAGONS
    def __new__(cls, *args, **kw):
        """!Allocate a new Config object.

        In order to ensure that all Config object are always in a proper
        state when handed to users or to derived Config classes, some
        attributes are handled at allocation time rather than at initialization

        This ensures that even if a derived Config class implements __init__,
        the author does not need to be concerned about when or even if he
        should call the base Config.__init__
        """
        name = kw.pop("__name", None)
        at = kw.pop("__at", getCallStack())
        # remove __label and ignore it
        kw.pop("__label", "default")

        instance = object.__new__(cls)
        instance._frozen = False
        instance._name = name
        instance._storage = {}
        instance._history = {}
        instance._imports = set()
        # load up defaults
        instance.reset(at=at)
        # set custom default-overides
        instance.setDefaults()
        # set constructor overides
        instance.update(__at=at, **kw)
        return instance
コード例 #2
0
ファイル: physics.py プロジェクト: pf4d/cslvr
	def __new__(self, model, *args, **kwargs):
		"""
		Creates and returns a new Physics object.
		"""
		instance = object.__new__(self)
		instance.model = model
		return instance
コード例 #3
0
 def __new__(cls, *args, **kwargs):
     """Since we never call an AstroFakerInstrument's __init__(), we set
     up the the internal attributes here"""
     instance = object.__new__(cls)
     instance._seeing = 0.8
     instance._descriptor_dict = {}
     return instance
コード例 #4
0
ファイル: config.py プロジェクト: olyoberdorf/DRAGONS
    def __new__(cls, *args, **kw):
        """!Allocate a new Config object.

        In order to ensure that all Config object are always in a proper
        state when handed to users or to derived Config classes, some
        attributes are handled at allocation time rather than at initialization

        This ensures that even if a derived Config class implements __init__,
        the author does not need to be concerned about when or even if he
        should call the base Config.__init__
        """
        name = kw.pop("__name", None)
        at = kw.pop("__at", getCallStack())
        # remove __label and ignore it
        kw.pop("__label", "default")

        instance = object.__new__(cls)
        instance._frozen = False
        instance._name = name
        instance._storage = {}
        instance._history = {}
        instance._imports = set()
        # load up defaults
        instance.reset(at=at)
        # set custom default-overides
        instance.setDefaults()
        # set constructor overides
        instance.update(__at=at, **kw)
        return instance
コード例 #5
0
 def __new__(cls, *args, **kwargs):
     if cls is ClientUIBackend:
         if sys.platform == 'win32':
             backends = (
                 TkUIBackend,
                 WxUIBackend,
                 ZenityUIBackend,
                 Win32UIBackend,
             )
         else:
             backends = (
                 WxUIBackend,
                 ZenityUIBackend,
                 TkUIBackend,
                 Win32UIBackend,
             )
         for subclass in backends:
             try:
                 backend = subclass.__new__(subclass, *args, **kwargs)
             except BackendNotAvailable:
                 continue
             # print("Using %s" % backend)
             return backend
         raise Exception(u'No suitable UI backend found.')
     else:
         return object.__new__(cls)
コード例 #6
0
 def __new__(cls, *args, **kwargs):
     ##
     # before __init__
     ##
     obj = object.__new__(cls)
     obj.inputs = InputDict(obj)
     obj.outputs = OutputDict(obj)
     return obj
コード例 #7
0
ファイル: base.py プロジェクト: hyperopt/hyperopt
 def view(self, exp_key=None, refresh=True):
     rval = object.__new__(self.__class__)
     rval._exp_key = exp_key
     rval._ids = self._ids
     rval._dynamic_trials = self._dynamic_trials
     rval.attachments = self.attachments
     if refresh:
         rval.refresh()
     return rval
コード例 #8
0
 def view(self, exp_key=None, refresh=True):
     rval = object.__new__(self.__class__)
     rval._exp_key = exp_key
     rval._ids = self._ids
     rval._dynamic_trials = self._dynamic_trials
     rval.attachments = self.attachments
     if refresh:
         rval.refresh()
     return rval
コード例 #9
0
    def __new__(cls, print_seconds=None):
        if profile.__INSTANCE is None:
            profile.__INSTANCE = object.__new__(cls)
            profile.__INSTANCE.data = []

        if print_seconds:
            profile.__INSTANCE.print_seconds = print_seconds
            print("Profiling enabled: output every {} seconds".format(
                print_seconds))

        return profile.__INSTANCE
コード例 #10
0
ファイル: singleton.py プロジェクト: vallsv/taurus
    def __new__(cls, *p, **k):
        # srubio: added type checking
        if cls != type(cls._the_instance):
            cls._the_instance = object.__new__(cls)

            # srubio: added init_single check
            if 'init_single' in cls.__dict__:
                cls._the_instance.init_single(*p, **k)
            else:
                cls._the_instance.init(*p, **k)
        return cls._the_instance
コード例 #11
0
 def __new__(cls, *args):
     key = hash(tuple(args))
     try:
         cls._multiton_lock.acquire()
         try:
             return cls._multiton_cache[key]
         except KeyError:
             newobj = object.__new__(cls)
             cls._multiton_cache[key] = newobj
             newobj.multiton_setup(*args)
             return newobj
     finally:
         cls._multiton_lock.release()
コード例 #12
0
ファイル: base.py プロジェクト: Sandroers/sandro
    def denormalize(cls, d, denormalizer=None, entityset=None):
        d = copy.copy(d)
        if denormalizer:
            d = {
                k: denormalizer(v,
                                denormalizer=denormalizer,
                                entityset=entityset)
                for k, v in d.items()
            }

        if entityset and 'entityset' in d:
            d['entityset'] = entityset
        es = object.__new__(cls)
        es.__dict__ = d
        return es
コード例 #13
0
    def from_rf_systems(cls, Ring, *args, section_index=1):

        self = object.__new__(cls)
        self.section_index = int(section_index - 1)
        self._ring_pars(Ring)

        rfShape = [len(args), len(self.cycle_time)]

        self.voltage = rfProgs.voltage_program.zeros(rfShape)
        self.phi_rf_d = rfProgs.phase_program.zeros(rfShape)
        self.harmonic = np.zeros(rfShape)

        for i, a in enumerate(args):
            self.voltage[i], self.phi_rf_d[i], self.harmonic[i] \
                            = a.sample(self.cycle_time, self.use_turns)

        return self
コード例 #14
0
    def __new__(cls, *args, **kwargs):
        """Create a new instance."""
        call_has_out, call_out_optional, _ = _dispatch_call_args(cls)
        cls._call_has_out = call_has_out
        cls._call_out_optional = call_out_optional
        if not call_has_out:
            # Out-of-place _call
            cls._call_in_place = _default_call_in_place
            cls._call_out_of_place = cls._call
        elif call_out_optional:
            # Dual-use _call
            cls._call_in_place = cls._call_out_of_place = cls._call
        else:
            # In-place-only _call
            cls._call_in_place = cls._call
            cls._call_out_of_place = _default_call_out_of_place

        return object.__new__(cls)
コード例 #15
0
 def __new__(cls, obj, *args, **kwargs):
     """
     creates an proxy instance referencing `obj`. (obj, *args, **kwargs) are
     passed to this class' __init__, so deriving classes can define an
     __init__ method of their own.
     note: _class_proxy_cache is unique per deriving class (each deriving
     class must hold its own cache)
     """
     try:
         cache = cls.__dict__["_class_proxy_cache"]
     except KeyError:
         cls._class_proxy_cache = cache = {}
     try:
         theclass = cache[obj.__class__]
     except KeyError:
         cache[obj.__class__] = theclass = cls._create_class_proxy(obj.__class__)
     ins = object.__new__(theclass)
     theclass.__init__(ins, obj, *args, **kwargs)
     return ins
コード例 #16
0
ファイル: Lumpy.py プロジェクト: b0rek/Lumpy
 def __new__(cls, *args, **kwds):
     """override __new__ so we can count the number of Things"""
     Thing.things_created += 1
     return object.__new__(cls)
コード例 #17
0
 def __new__(cls, *args, **kwargs):
     # Force the VERSION class member to be copied to an instance member.
     obj = object.__new__(cls)
     obj.VERSION = cls.VERSION
     return obj
コード例 #18
0
ファイル: uri.py プロジェクト: welitonfreitas/storm-py3
 def copy(self):
     uri = object.__new__(self.__class__)
     uri.__dict__.update(self.__dict__)
     uri.options = self.options.copy()
     return uri
コード例 #19
0
 def __new__(cls, *args, **kwargs):
     # Force the VERSION class member to be copied to an instance member.
     obj = object.__new__(cls)
     obj.VERSION = cls.VERSION
     return obj
コード例 #20
0
 def __new__(cls):
     if Device._device_inst is None:
         Device._device_inst = object.__new__(Device)
     return Device._device_inst