Get an instance by binary uuid.

    :param model: a string, model name in rio.models.
    :param bin_uuid: a 16-bytes binary string.
    :return: None or a SQLAlchemy instance.
3121
def get_instance_by_bin_uuid(model, bin_uuid):
    
    try:
        model = get_model(model)
    except ImportError:
        return None

    return model.query.filter_by(**{'bin_uuid': bin_uuid}).first()
240463
def id(cls):
        
        if cls.__uuid_primary_key__:
            return immutable(Column(UUIDType(binary=False), default=uuid_.uuid4, primary_key=True, nullable=False))
        else:
            return immutable(Column(Integer, primary_key=True, nullable=False))
862630
def model(self, model, create=True):
        ''''''
        manager = self.manager(model)
        sm = self._models.get(manager)
        if sm is None and create:
            sm = SessionModel(manager)
            self._models[manager] = sm
        return sm
640909
def get_model(self, model, model_id):
        
        return self._store.find_record(self._get_model_class(model), int(model_id))
1186922
def get_column_model(name, model=None):
    
    if '.' in name:
        m, name = name.split('.')
        model = get_model(m)

    if model:
        return model.c.get(name), model
    else:
        return None, None
622900
def get_uuid(obj):
    """"""
    # TODO: deprecate null uuid ret val
    from uuid import UUID
    try:
        uuid = obj.attrs['uuid']
    except KeyError:
        return UUID(int=0)
    # convert to unicode for python 3
    try:
        uuid = uuid.decode('ascii')
    except (LookupError, AttributeError):
        pass
    return UUID(uuid)
649191
def get_model(model):
    
    try:
        if isinstance(model, str):
            app_label, model_name = model.split('.', 1)
            m = loading.get_model(app_label, model_name)
            if not m:  # pragma: no cover
                raise LookupError()  # Django < 1.7 just returns None
            return m
        elif issubclass(model, models.Model):
            return model
    except (LookupError, ValueError):
        pass
    raise ValueError(model)
131412
def ulid_to_binary(ulid):
    
    if isinstance(ulid, uuid.UUID):
        return ulid.bytes
    if isinstance(ulid, (text_type, bytes)) and len(ulid) == 26:
        return decode_ulid_base32(ulid)
    if isinstance(ulid, (bytes, bytearray)) and len(ulid) == 16:
        return ulid
    raise InvalidULID('can not convert ulid %r to binary' % ulid)
1065155
public static function bootUuidBinaryModelTrait()
    {
        static::creating(function ($model) {
            // Only generate UUID if it wasn't set by already.
            $key = $model->getKeyName();
            if (!isset($model->attributes[$key])) {
                // This is necessary because on \Illuminate\Database\Eloquent\Model::performInsert
                // will not check for $this->getIncrementing() but directly for $this->incrementing
                $model->incrementing = false;
                $uuidVersion = (!empty($model->uuidVersion) ? $model->uuidVersion : 4);   // defaults to 4
                $uuid = Uuid::generate($uuidVersion);
                $model->attributes[$key] = (property_exists($model, 'uuidOptimization') && $model::$uuidOptimization ? $model::toOptimized($uuid->string) : $uuid->bytes);
            }
        }, 0);
    }
918883
def get_model(sender, model_name, model_inst, model_info, model_config):
    
    MC = get_mc()
    if MC:
        model = MC.get((MC.c.model_name==model_name) & (MC.c.uuid!=''))
        if model:
            cached_inst = __cache__.get(model_name)
            if not cached_inst or (cached_inst and cached_inst[1]!=model.uuid):
                model_inst = model.get_instance()
                M = orm.create_model(model_name, fields=eval(model_inst.fields or '[]'),
                                     indexes=eval(model_inst.indexes or '[]'),
                                     basemodel=model_inst.basemodel,
                                     __replace__=True)
                __cache__[model_name] = (M, model.uuid)

                #process extension model
                if model_inst.has_extension:
                    ext_model_name = model_name + '_extension'
                    fields = eval(model_inst.extension_fields or '[]')
                    fields.insert(0, {'name':'_parent', 'type':'OneToOne', 'reference_class':model_name, 'collection_name':'ext'})
                    ME = orm.create_model(ext_model_name, fields=fields,
                                          indexes=eval(model_inst.extension_indexes or '[]'),
                                          basemodel=model_inst.extension_model,
                                          __replace__=True)

            else:
                M = cached_inst[0]

            return M
424434
def binary(self, length=(1 * 1024 * 1024)):
        
        blob = [self.generator.random.randrange(256) for _ in range(length)]
        return bytes(blob) if sys.version_info[0] >= 3 else bytearray(blob)
479420
def get_uuid_like_indexes_on_table(model):
    
    with default_connection.cursor() as c:
        indexes = select_uuid_like_indexes_on_table(model, c)
    return indexes
380754
def get_bin(self):
        
        if self._lookup_session is None:
            mgr = get_provider_manager('RESOURCE', runtime=self._runtime, proxy=self._proxy)
            self._lookup_session = mgr.get_bin_lookup_session(proxy=getattr(self, "_proxy", None))
        return self._lookup_session.get_bin(Id(self._my_map['id']))
681825
def binary(self):
        
        if isinstance(self.value, int):
            return b_chr(_TAG_ATOM_CACHE_REF) + b_chr(self.value)
        elif isinstance(self.value, TypeUnicode):
            value_encoded = self.value.encode('utf-8')
            length = len(value_encoded)
            if length <= 255:
                return (
                    b_chr(_TAG_SMALL_ATOM_UTF8_EXT) +
                    b_chr(length) + value_encoded
                )
            elif length <= 65535:
                return (
                    b_chr(_TAG_ATOM_UTF8_EXT) +
                    struct.pack(b'>H', length) + value_encoded
                )
            else:
                raise OutputException('uint16 overflow')
        elif isinstance(self.value, bytes):
            length = len(self.value)
            if length <= 255:
                return b_chr(_TAG_SMALL_ATOM_EXT) + b_chr(length) + self.value
            elif length <= 65535:
                return (
                    b_chr(_TAG_ATOM_EXT) +
                    struct.pack(b'>H', length) + self.value
                )
            else:
                raise OutputException('uint16 overflow')
        else:
            raise OutputException('unknown atom type')
504477
def uuid4():
    """"""
    # Otherwise, get randomness from urandom or the 'random' module.
    try:
        import os
        return UUID(bytes=os.urandom(16), version=4)
    except Exception:
        import random
        bytes = [chr(random.randrange(256)) for i in range(16)]
        return UUID(bytes=bytes, version=4)
1364004
def get(self, id):
        
        with rconnect() as conn:
            if id is None:
                raise ValueError

            if isinstance(id, uuid.UUID):
                id = str(id)

            if type(id) != str and type(id) != unicode:
                raise ValueError

            try:
                query = self._base().get(id)
                log.debug(query)
                rv = query.run(conn)
            except ReqlOpFailedError as e:
                log.warn(e)
                raise
            except Exception as e:
                log.warn(e)
                raise
            if rv is not None:
                return self._model(rv)

            return None
1240631
def getbyuuid(self, uuid):
        
        if uuid not in self._schbyuuid:
            raise KeyError('uuid {0} not registered'.format(uuid))

        return self._schbyuuid[uuid]