Unpickle a model by retrieving it from the database.
350075
def _model_unpickle(cls, data):
    """"""
    auto_field_value = data['pk']
    try:
        obj = cls.objects.get(pk=auto_field_value)
    except Exception as e:
        if isinstance(e, OperationalError):
            # Attempt reconnect, we've probably hit;
            # OperationalError(2006, 'MySQL server has gone away')
            logger.debug("Caught OperationalError, closing database connection.", exc_info=e)
            from django.db import connection
            connection.close()
            obj = cls.objects.get(pk=auto_field_value)
        else:
            raise
    return obj
909508
def get_model(app, model):
    """"""
    if 'get_model' not in _LAZY_LOADS:
        _lazy_load_get_model()

    _get_model = _LAZY_LOADS['get_model']
    return _get_model(app, model)
611661
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'models' in _dict:
            args['models'] = [
                Model._from_dict(x) for x in (_dict.get('models'))
            ]
        return cls(**args)
919341
def populate_model(model_or_inst, excludes=None, only=None):
    
    inst = model_or_inst if _is_inst(model_or_inst) else model_or_inst()

    parser = make_request_parser(model_or_inst, excludes, only, for_populate=True)
    req_args = parser.parse_args()

    for key, value in req_args.items():
        setattr(inst, key, value)

    return inst
1223526
def from_database(cls, database):
        """"""
        if isinstance(database, PostgresqlDatabase):
            return PostgresqlMigrator(database)
        if isinstance(database, SqliteDatabase):
            return SqliteMigrator(database)
        if isinstance(database, MySQLDatabase):
            return MySQLMigrator(database)
        return super(SchemaMigrator, cls).from_database(database)
550677
def get(self):
        

        if not HAS_SQL:  # pragma: nocover
            return requests.session()

        try:
            conn, c = self.connect()
        except:
            log.traceback(logging.DEBUG)
            return requests.session()

        session = None
        try:
            c.execute('BEGIN IMMEDIATE')
            c.execute('SELECT value FROM {0} LIMIT 1'.format(self.table_name))
            row = c.fetchone()
            if row is not None:
                session = pickle.loads(row[0])
        except:  # pragma: nocover
            log.traceback(logging.DEBUG)

        try:
            conn.close()
        except:  # pragma: nocover
            log.traceback(logging.DEBUG)

        return session if session is not None else requests.session()
1306633
def get_or_exception(cls, id):
        '''  '''
        obj = cls.get(id)

        if obj is None:
            raise ModelNotFoundError('This object does not exist in database')

        return obj
46603
def from_pickle(cls, filename):
        """"""
        with open(filename, 'rb') as f:
            cam = pickle.load(f)

        projection = cam.projection.copy()
        return cls(projection=projection, position=cam.position.xyz, rotation=cam.rotation.__class__(*cam.rotation[:]))
1277835
function pick(obj){
  var keys = [].slice.call(arguments, 1);
  var ret = {};

  for (var i = 0, key; key = keys[i]; i++) {
    if (key in obj) ret[key] = obj[key];
  }

  return ret;
}
1350355
def create(cls, serializable_instance):
    """"""
    if not Serializable.is_serializable(serializable_instance):
      raise ValueError('Can only create pickles for Serializable objects, given {} of type {}'
                       .format(serializable_instance, type(serializable_instance).__name__))
    return cls(unpickle_func=_unpickle_serializable,
               args=(type(serializable_instance), serializable_instance._asdict()))
772074
def unpickle(self, parent):
        """"""
        self.parent = parent
        self._unpickle_collection(self.members)
        self._unpickle_collection(self.executables)
        self._unpickle_collection(self.types)
1030254
def refresh_model(self, model, *, overwrite=False):
    
    new_model = self.find_model_by_id(model.__class__, model.primary_key)
    if overwrite:
      model.update(new_model.to_dict(use_default_excludes=False))
      return model
    else:
      return new_model
328386
def unpickle(self, parent):
        """"""
        self.parent = parent
        self._unpickle_collection(self.members)
        self._unpickle_collection(self.executables)
        self.unpickle_docs()
602182
def dbRestore(self, db_value, context=None):
        
        if db_value is not None:
            return yaml.load(projex.text.nativestring(db_value))
        else:
            return db_value
506134
def _handle_load_unknown(self, data, original):
        """"""
        for key, val in original.items():
            if key not in self.fields:
                data[key] = val
        return data
1184827
def unpickle(cls, s):
        
        className, _json = s.split(':', 1)
        return locate(className)(*json.loads(_json))
215577
def capture_update(self, *, update_fields=()):
        """"""
        return self.capture_update_from_model(self.table_name, self.record_id,
                                              update_fields=update_fields)