Create a friendly Python object from an evdev style event.
509485
def _make_event(self, tv_sec, tv_usec, ev_type, code, value):
        """"""
        event_type = self.manager.get_event_type(ev_type)
        eventinfo = {
            "ev_type": event_type,
            "state": value,
            "timestamp": tv_sec + (tv_usec / 1000000),
            "code": self.manager.get_event_string(event_type, code)
        }

        return InputEvent(self, eventinfo)
641500
def FromEvent(cls, service_event):
    
    _, _, name = service_event.key_path.rpartition(
        WindowsService._REGISTRY_KEY_PATH_SEPARATOR)
    service_type = service_event.regvalue.get('Type', '')
    image_path = service_event.regvalue.get('ImagePath', '')
    start_type = service_event.regvalue.get('Start', '')
    service_dll = service_event.regvalue.get('ServiceDll', '')
    object_name = service_event.regvalue.get('ObjectName', '')

    if service_event.pathspec:
      source = (service_event.pathspec.location, service_event.key_path)
    else:
      source = ('Unknown', 'Unknown')
    return cls(
        name=name, service_type=service_type, image_path=image_path,
        start_type=start_type, object_name=object_name,
        source=source, service_dll=service_dll)
905345
def processVREvent(self, event):
        ""
        et = event.eventType
        if et == openvr.VREvent_TrackedDeviceActivated:
            self.setupRenderModelForTrackedDevice( event.trackedDeviceIndex )
            dprintf( "Device %u attached. Setting up render model.\n" % event.trackedDeviceIndex )
        elif et == openvr.VREvent_TrackedDeviceDeactivated:
            dprintf( "Device %u detached.\n" % event.trackedDeviceIndex )
        elif et == openvr.VREvent_TrackedDeviceUpdated:
            dprintf( "Device %u updated.\n" % event.trackedDeviceIndex )
32821
def factory_chat(js_obj, driver=None):
    """"""
    if js_obj["kind"] not in ["chat", "group", "broadcast"]:
        raise AssertionError("Expected chat, group or broadcast object, got {0}".format(js_obj["kind"]))

    if js_obj["isGroup"]:
        return GroupChat(js_obj, driver)

    if js_obj["kind"] == "broadcast":
        return BroadcastChat(js_obj, driver)

    return UserChat(js_obj, driver)
421550
def make_event_data(self, flavor, data):
        
        if not flavor.startswith('_'):
            raise ValueError('Event flavor must start with _underscore')

        d = {'source': {'space': self._event_space, 'id': self._source_id}}
        d.update(data)
        return {flavor: d}
1029198
def as_event_class(obj):
    
    if is_string(obj):
        for c in all_subclasses(AbinitEvent):
            if c.__name__ == obj or c.yaml_tag == obj: return c
        raise ValueError("Cannot find event class associated to %s" % obj)

    # Assume class.
    assert obj in all_subclasses(AbinitEvent)
    return obj
522918
def new_event(self, event_data: str) -> None:
        """"""
        event = self.parse_event_xml(event_data)

        if EVENT_OPERATION in event:
            self.manage_event(event)
1170314
def runtime_import(object_path):
    """"""
    obj_module, obj_element = object_path.rsplit(".", 1)
    loader = __import__(obj_module, globals(), locals(), [str(obj_element)])
    return getattr(loader, obj_element)
297382
def get_object(request, pid):
    """"""
    sciobj = d1_gmn.app.models.ScienceObject.objects.get(pid__did=pid)
    content_type_str = d1_gmn.app.object_format_cache.get_content_type(
        sciobj.format.format
    )
    # Return local or proxied SciObj bytes
    response = django.http.StreamingHttpResponse(
        _get_sciobj_iter(sciobj), content_type_str
    )
    d1_gmn.app.views.headers.add_sciobj_properties_headers_to_response(response, sciobj)
    d1_gmn.app.event_log.log_read_event(pid, request)
    return response
836088
function (evt, callback) {
    var self = this;

    var payload = evt;

    if (self.payload && self.payload !== '') {
      payload = dotty.get(evt, self.payload);
    }

    if (self.evtExtFn.length === 3) {
      if (self.id) {
        self.extractId(evt, function (err, id) {
          if (err) {
            debug(err);
            return callback(err);
          }

          self.loadViewModel(id, function (err, vm) {
            if (err) {
              debug(err);
              return callback(err);
            }

            try {
              self.evtExtFn(_.cloneDeep(payload), vm, function () {
                try {
                  callback.apply(this, _.toArray(arguments));
                } catch (e) {
                  debug(e);
                  process.emit('uncaughtException', e);
                }
              });
            } catch (e) {
              debug(e);
              process.emit('uncaughtException', e);
            }
          });
        });
        return;
      }

      try {
        self.evtExtFn(_.cloneDeep(payload), self.collection, function () {
          try {
            callback.apply(this, _.toArray(arguments));
          } catch (e) {
            debug(e);
            process.emit('uncaughtException', e);
          }
        });
      } catch (e) {
        debug(e);
        process.emit('uncaughtException', e);
      }
      return;
    }

    if (self.evtExtFn.length === 1) {
      try {
        var res = self.evtExtFn(evt);
        try {
          callback(null, res);
        } catch (e) {
          debug(e);
          process.emit('uncaughtException', e);
        }
      } catch (e) {
        debug(e);
        process.emit('uncaughtException', e);
      }
      return;
    }

    if (self.evtExtFn.length === 2) {
      if (!self.collection || !self.id) {
        try {
          self.evtExtFn(evt, function () {
            try {
              callback.apply(this, _.toArray(arguments));
            } catch (e) {
              debug(e);
              process.emit('uncaughtException', e);
            }
          });
        } catch (e) {
          debug(e);
          process.emit('uncaughtException', e);
        }
        return;
      }

      self.extractId(evt, function (err, id) {
        if (err) {
          debug(err);
          return callback(err);
        }

        self.loadViewModel(id, function (err, vm) {
          if (err) {
            debug(err);
            return callback(err);
          }

          try {
            var res = self.evtExtFn(_.cloneDeep(payload), vm);
            try {
              callback(null, res);
            } catch (e) {
              debug(e);
              process.emit('uncaughtException', e);
            }
          } catch (e) {
            debug(e);
            process.emit('uncaughtException', e);
          }
        });
      });
    }
  }
386055
def _push_event(self, evt):
        """"""
        self._append(evt)
        import datetime
        now = datetime.datetime.now()
        try:
            date = self._get_date(evt)
        except:
            date = now
        try:
            reception_date = evt.reception_date.todatetime()
        except:
            reception_date = now
        try:
            evt_type = evt.event.upper()
        except:
            evt_type = "<UNKNOWN>"
        try:
            dev_name = evt.device.dev_name().upper()
        except:
            dev_name = "<UNKNOWN>"
        try:
            attr_name = evt.attr_name.split("/")[-1].upper()
        except:
            attr_name = "<UNKNOWN>"
        try:
            value = self._get_value(evt)
        except Exception as e:
            value = "Unexpected exception in getting event value: %s" % str(e)
        d = {"date": date, "reception_date": reception_date,
             "type": evt_type, "dev_name": dev_name, "name": attr_name,
             "value": value}
        print(self._msg.format(**d), file=self._fd)
413118
def FromDict(cls, obj):
        

        timestamp = obj.get('timestamp')
        if timestamp is not None:
            import dateutil.parser
            timestamp = dateutil.parser.parse(timestamp)

        return IOTileEvent(obj.get('device_timestamp'), obj.get('stream'), obj.get('extra_data'),
                           obj.get('data'), reading_id=obj.get('streamer_local_id'), reading_time=timestamp)
96487
def _gen_vevent(self, event, vevent):
        """"""
        vevent.add('dtstart').value = event['dtstart'][0]
        vevent.add('dtstamp').value = datetime.fromtimestamp(self._mtime)
        vevent.add('summary').value = event['msg']
        vevent.add('uid').value = event['uid']

        if 'class' in event:
            vevent.add('class').value = event['class']

        if 'categories' in event and len(event['categories']) > 0:
            vevent.add('categories').value = event['categories']

        if 'location' in event:
            vevent.add('location').value = event['location']

        if 'description' in event:
            vevent.add('description').value = event['description']

        if isinstance(event['dtstart'][0], datetime):
            if self._alarm != timedelta():
                valarm = vevent.add('valarm')
                valarm.add('trigger').value = self._alarm
                valarm.add('action').value = 'DISPLAY'
                valarm.add('description').value = event['msg']

            if 'duration' in event:
                vevent.add('duration').value = event['duration']
            else:
                vevent.add('dtend').value = event['dtstart'][0]

        elif len(event['dtstart']) == 1:
            vevent.add('dtend').value = event['dtstart'][0] + timedelta(days=1)

        if len(event['dtstart']) > 1:
            Remind._gen_dtend_rrule(event['dtstart'], vevent)
264104
def from_dict(event_dict):
    
    return SnippetEvent(
        callback_id=event_dict['callbackId'],
        name=event_dict['name'],
        creation_time=event_dict['time'],
        data=event_dict['data'])
266283
def _to_event_data(obj):
    '''
    
    '''

    if obj is None:
        return None
    if isinstance(obj, bool):
        return obj
    if isinstance(obj, int):
        return obj
    if isinstance(obj, float):
        return obj
    if isinstance(obj, str):
        return obj
    if isinstance(obj, bytes):
        return obj
    if isinstance(obj, dict):
        return obj

    if isinstance(obj, NodeDriver):  # Special case for NodeDriver (cyclic references)
        return obj.name

    if isinstance(obj, list):
        return [_to_event_data(item) for item in obj]

    event_data = {}
    for attribute_name in dir(obj):
        if attribute_name.startswith('_'):
            continue

        attribute_value = getattr(obj, attribute_name)

        if callable(attribute_value):  # Strip out methods
            continue

        event_data[attribute_name] = _to_event_data(attribute_value)

    return event_data
175622
def __emulate_buttons(self, changed_buttons, timeval=None):
        """"""
        events = []
        for button in changed_buttons:
            code, value, ev_type = self.__map_button(button)
            event = self.create_event_object(
                ev_type,
                code,
                value,
                timeval=timeval)
            events.append(event)
        return events
688682
def mixin (cls):
    
    cls._events = {}
    cls.bind = Pyevent.bind.__func__
    cls.unbind = Pyevent.unbind.__func__
    cls.trigger = Pyevent.trigger.__func__
    return cls