Exemplo n.º 1
0
    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
Exemplo n.º 2
0
	def __new__(self, model, *args, **kwargs):
		"""
		Creates and returns a new Physics object.
		"""
		instance = object.__new__(self)
		instance.model = model
		return instance
Exemplo n.º 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
Exemplo n.º 4
0
    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
Exemplo n.º 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)
Exemplo n.º 6
0
 def __new__(cls, *args, **kwargs):
     ##
     # before __init__
     ##
     obj = object.__new__(cls)
     obj.inputs = InputDict(obj)
     obj.outputs = OutputDict(obj)
     return obj
Exemplo n.º 7
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
Exemplo n.º 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
    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
Exemplo n.º 10
0
    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
Exemplo n.º 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()
Exemplo n.º 12
0
    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
Exemplo n.º 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
    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)
Exemplo n.º 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
Exemplo n.º 16
0
Arquivo: Lumpy.py Projeto: 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)
Exemplo n.º 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
Exemplo n.º 18
0
 def copy(self):
     uri = object.__new__(self.__class__)
     uri.__dict__.update(self.__dict__)
     uri.options = self.options.copy()
     return uri
Exemplo n.º 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
Exemplo n.º 20
0
 def __new__(cls):
     if Device._device_inst is None:
         Device._device_inst = object.__new__(Device)
     return Device._device_inst