def get_file(self, md5_digest, file_size, cls):
     row = self._db_query(self.SentFile,
                          self.SentFile.md5_digest == md5_digest,
                          self.SentFile.file_size == file_size,
                          self.SentFile.type == _SentFileType.from_type(
                              cls).value).one_or_none()
     return (row.id, row.hash) if row else None
Exemple #2
0
 def get_file(self, md5_digest: str, file_size: int, cls: Any) -> Optional[Tuple[int, int]]:
     row = self._db_query(self.SentFile,
                          self.SentFile.md5_digest == md5_digest,
                          self.SentFile.file_size == file_size,
                          self.SentFile.type == _SentFileType.from_type(
                              cls).value).one_or_none()
     return (row.id, row.hash) if row else None
 def get_file(self, md5_digest, file_size, cls):
     sentfile_container = self.get_sent_file_container()
     
     query = "SELECT * FROM c WHERE c.md5_digest='{}' AND c.file_size={} AND c.type='{}'".format(
         md5_digest, file_size, _SentFileType.from_type(cls).value
     )
     
     for item in sentfile_container.query_items(query, enable_cross_partition_query=True):
         return item['id'], item['hash']
    def get_file(self, md5_digest, file_size, cls):
        with switch_db(SentFile, self.database) as _SentFile:
            row = _SentFile.objects(
                md5_digest=md5_digest,
                file_size=file_size,
                type=_SentFileType.from_type(cls).value).first()

        if row:
            return cls(row.id, row.hash)
    def cache_file(self, md5_digest, file_size, instance):
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError("Cannot cache %s instance" % type(instance))

        self.db.merge(
            self.SentFile(session_id=self.session_id, md5_digest=md5_digest,
                          type=_SentFileType.from_type(type(instance)).value,
                          id=instance.id, hash=instance.access_hash))
        self.save()
    def cache_file(self, md5_digest, file_size, instance):
        with switch_db(SentFile, self.database) as _SentFile:
            if not isinstance(instance, (InputDocument, InputPhoto)):
                raise TypeError('Cannot cache %s instance' % type(instance))

            _SentFile(md5_digest=md5_digest,
                      file_size=file_size,
                      type=_SentFileType.from_type(type(instance)).value,
                      id=instance.id,
                      hash=instance.access_hash).save()
Exemple #7
0
    def cache_file(self, md5_digest: str, file_size: int,
                   instance: Union[InputDocument, InputPhoto]) -> None:
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError("Cannot cache {} instance".format(type(instance)))

        self.db.merge(
            self.SentFile(session_id=self.session_id, md5_digest=md5_digest, file_size=file_size,
                          type=_SentFileType.from_type(type(instance)).value,
                          id=instance.id, hash=instance.access_hash))
        self.save()
 def cache_file(self, md5_digest, file_size, instance):
     if not isinstance(instance, (InputDocument, InputPhoto)):
         raise TypeError("Cannot cache {} instance".format(type(instance)))
     senf_file = models.SentFile(session_id=self.session_id,
                                 md5_digest=md5_digest,
                                 type=_SentFileType.from_type(
                                     type(instance)).value,
                                 id=instance.id,
                                 hash=instance.access_hash)
     senf_file.save()
     self.save()
 def get_file(self, md5_digest, file_size, cls):
     key = "{}:sent_files:{}".format(self.sess_prefix, md5_digest)
     s = self.redis_connection.get(key)
     if s:
         try:
             s = self._unpack(s)
             return md5_digest, file_size \
                 if s["file_size"] == file_size and s["type"] == _SentFileType.from_type(cls).value \
                 else None
         except Exception as ex:
             __log__.exception(ex.args)
             return None
Exemple #10
0
 def get_file(self, md5_digest: str, file_size: int,
              cls: Any) -> Optional[Tuple[int, int]]:
     t = self.SentFile.__table__
     rows = (self.engine.execute(
         select([t.c.id, t.c.hash]).where(
             and_(t.c.session_id == self.session_id,
                  t.c.md5_digest == md5_digest, t.c.file_size == file_size,
                  t.c.type == _SentFileType.from_type(cls).value))))
     try:
         return next(rows)
     except StopIteration:
         return None
Exemple #11
0
    def cache_file(self, md5_digest: str, file_size: int,
                   instance: Union[InputDocument, InputPhoto]) -> None:
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError("Cannot cache {} instance".format(type(instance)))

        t = self.SentFile.__table__
        values = dict(id=instance.id, hash=instance.access_hash)
        with self.engine.begin() as conn:
            conn.execute("INSERT OR REPLACE INTO {} ".format(self.SentFile.__tablename__) +
                         "VALUES (:session_id, :md5_digest, :type, :file_size)",
                         dict(session_id=self.session_id, md5_digest=md5_digest,
                              type=_SentFileType.from_type(type(instance)).value,
                              file_size=file_size, **values))
    def cache_file(self, md5_digest: str, file_size: int,
                   instance: Union[InputDocument, InputPhoto]) -> None:
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError("Cannot cache {} instance".format(type(instance)))

        t = self.SentFile.__table__
        values = dict(id=instance.id, hash=instance.access_hash)
        with self.engine.begin() as conn:
            conn.execute(insert(t)
                         .values(session_id=self.session_id, md5_digest=md5_digest,
                                 type=_SentFileType.from_type(type(instance)).value,
                                 file_size=file_size, **values)
                         .on_duplicate_key_update(**values))
    def cache_file(self, md5_digest: str, file_size: int,
                   instance: Union[InputDocument, InputPhoto]) -> None:
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError("Cannot cache {} instance".format(type(instance)))

        t = self.SentFile.__table__
        values = dict(id=instance.id, hash=instance.access_hash)
        self.engine.execute(
            insert(t).values(
                session_id=self.session_id,
                md5_digest=md5_digest,
                type=_SentFileType.from_type(type(instance)).value,
                file_size=file_size,
                **values).on_conflict_do_update(constraint=t.primary_key,
                                                set_=values))
 def cache_file(self, md5_digest, file_size, instance):
     
     if not isinstance(instance, (InputDocument, InputPhoto)):
         raise TypeError('Cannot cache %s instance' % type(instance))
     
     sentfile_container = self.get_sent_file_container()
         
     item = {
         'md5_digest': md5_digest,
         'file_size': file_size,
         'type': _SentFileType.from_type(type(instance)).value,
         'id': str(instance.id),
         'hash': instance.access_hash
     }
     
     sentfile_container.upsert_item(json.loads(json.dumps(item)))
Exemple #15
0
    def cache_file(self, md5_digest: str, file_size: int,
                   instance: Union[InputDocument, InputPhoto]) -> None:
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError("Cannot cache {} instance".format(type(instance)))

        t = self.SentFile.__table__
        file_type = _SentFileType.from_type(type(instance)).value
        with self.engine.begin() as conn:
            conn.execute(t.delete().where(session_id=self.session_id,
                                          md5_digest=md5_digest,
                                          type=file_type,
                                          file_size=file_size))
            conn.execute(t.insert().values(session_id=self.session_id,
                                           md5_digest=md5_digest,
                                           type=file_type,
                                           file_size=file_size,
                                           id=instance.id,
                                           hash=instance.access_hash))
    def cache_file(self, md5_digest, file_size, instance):
        if not isinstance(instance, (InputDocument, InputPhoto)):
            raise TypeError('Cannot cache {} instance'.format(type(instance)))

        key = "{}:sent_files:{}".format(self.sess_prefix, md5_digest)
        s = {
            "md5_digest": md5_digest,
            "file_size": file_size,
            "type": _SentFileType.from_type(type(instance)).value,
            "id": instance.id,
            "hash": instance.access_hash,
        }

        if self.add_timestamps:
            s.update({
                "ts_ts": time.time(),
                "ts_str": time.strftime(DEFAULT_TS_STR_FORMAT, time.localtime()),
            })

        try:
            self.redis_connection.set(key, self._pack(s))
        except Exception as ex:
            __log__.exception(ex.args)
 def get_file(self, md5_digest, file_size, cls):
     row = models.SentFile.objects.filter(
         md5_digest=md5_digest,
         file_size=file_size,
         type=_SentFileType.from_type(cls).value).first()
     return (row.id, row.hash) if row else None