Top

pytter.utils.fileinfo module

import os
import urllib
import mimetypes


class FileInfo:
    handler        = None
    size: int      = None
    mime_type: str = None
    file_name: str = None
    full_path: str = None
    from_url: bool = False

    def __init__(self, file_handler, full_media_path: str):
        self.handler = file_handler

        if full_media_path.startswith('http'):
            self.from_url = True
            self.full_path = urllib.parse.urlparse(full_media_path).path
        else:
            self.full_path = full_media_path
        self.file_name = os.path.basename(self.full_path)

        file_handler.seek(0, 2)
        self.size = file_handler.tell()
        try:
            file_handler.seek(0)
        except:
            pass

        self.mime_type = mimetypes.guess_type(self.file_name)[0]

    def close(self):
        self.handler.close()


class FileChunk:
    size: int = 0
    data = []
    index: int = 0

    def __init__(self, size: int, index: int, data):
        self.size = size
        self.index = index
        self.data = data


class Megabyte:
    _n: float = 0

    def __init__(self, n: float):
        self._n = n

    def __str__(self):
        return str(self._n)

    @property
    def n_bytes(self) -> int:
        return self._n * 1024 * 1024

Classes

class FileChunk

class FileChunk:
    size: int = 0
    data = []
    index: int = 0

    def __init__(self, size: int, index: int, data):
        self.size = size
        self.index = index
        self.data = data

Ancestors (in MRO)

Class variables

var data

Static methods

def __init__(

self, size, index, data)

Initialize self. See help(type(self)) for accurate signature.

def __init__(self, size: int, index: int, data):
    self.size = size
    self.index = index
    self.data = data

Instance variables

var data

var index

var size

class FileInfo

class FileInfo:
    handler        = None
    size: int      = None
    mime_type: str = None
    file_name: str = None
    full_path: str = None
    from_url: bool = False

    def __init__(self, file_handler, full_media_path: str):
        self.handler = file_handler

        if full_media_path.startswith('http'):
            self.from_url = True
            self.full_path = urllib.parse.urlparse(full_media_path).path
        else:
            self.full_path = full_media_path
        self.file_name = os.path.basename(self.full_path)

        file_handler.seek(0, 2)
        self.size = file_handler.tell()
        try:
            file_handler.seek(0)
        except:
            pass

        self.mime_type = mimetypes.guess_type(self.file_name)[0]

    def close(self):
        self.handler.close()

Ancestors (in MRO)

Class variables

var from_url

var full_path

var handler

Static methods

def __init__(

self, file_handler, full_media_path)

Initialize self. See help(type(self)) for accurate signature.

def __init__(self, file_handler, full_media_path: str):
    self.handler = file_handler
    if full_media_path.startswith('http'):
        self.from_url = True
        self.full_path = urllib.parse.urlparse(full_media_path).path
    else:
        self.full_path = full_media_path
    self.file_name = os.path.basename(self.full_path)
    file_handler.seek(0, 2)
    self.size = file_handler.tell()
    try:
        file_handler.seek(0)
    except:
        pass
    self.mime_type = mimetypes.guess_type(self.file_name)[0]

def close(

self)

def close(self):
    self.handler.close()

Instance variables

var file_name

var handler

var mime_type

var size

class Megabyte

class Megabyte:
    _n: float = 0

    def __init__(self, n: float):
        self._n = n

    def __str__(self):
        return str(self._n)

    @property
    def n_bytes(self) -> int:
        return self._n * 1024 * 1024

Ancestors (in MRO)

Static methods

def __init__(

self, n)

Initialize self. See help(type(self)) for accurate signature.

def __init__(self, n: float):
    self._n = n

Instance variables

var n_bytes