class CloudFile: filename = FieldProperty(IFile['filename']) _size = 0 _md5 = None _data = b'' def __init__(self, content_type='application/octet-stream', filename=None, size=0, md5=None, data=b''): if not isinstance(content_type, bytes): content_type = content_type.encode('utf8') self.content_type = content_type if filename is not None: self.filename = filename extension_discovery = filename.split('.') if len(extension_discovery) > 1: self._extension = extension_discovery[-1] elif self.filename is not None: self.filename = uuid.uuid4().hex self._size = size self._md5 = md5 self._data = data @property def data(self): return self._data @property def size(self): if hasattr(self, '_size'): return self._size else: return None @property def md5(self): if hasattr(self, '_md5'): return self._md5 else: return None @property def extension(self): if hasattr(self, '_extension'): return self._extension else: return None
from zope.interface import Interface from zope.interface.interfaces import IInterface from zope.interface.interfaces import IMethod import decimal import json import jsonschema import re __docformat__ = "restructuredtext" # pep 8 friendlyness Container # Fix up bootstrap field types Field.title = FieldProperty(IField["title"]) # type: ignore Field.description = FieldProperty(IField["description"]) # type: ignore Field.required = FieldProperty(IField["required"]) # type: ignore Field.readonly = FieldProperty(IField["readonly"]) # type: ignore # Default is already taken care of classImplements(Field, IField) MinMaxLen.min_length = FieldProperty(IMinMaxLen["min_length"]) # type: ignore MinMaxLen.max_length = FieldProperty(IMinMaxLen["max_length"]) # type: ignore classImplements(Text, IText) classImplements(TextLine, ITextLine) classImplements(Password, IPassword) classImplements(Bool, IBool) classImplements(Bool, IFromUnicode) classImplements(Int, IInt)
class BaseCloudFile: """Base cloud file storage class""" filename: str = FieldProperty(IFile['filename']) # type: ignore valid = True def __init__(self, content_type='application/octet-stream', filename=None, size=0, md5=None): if isinstance(content_type, bytes): content_type = content_type.decode('utf8') self.content_type = content_type if filename is not None: self.filename = filename extension_discovery = filename.split('.') if len(extension_discovery) > 1: self._extension = extension_discovery[-1] elif self.filename is None: self.filename = uuid.uuid4().hex self._size = size self._md5 = md5 self._current_upload = 0 def guess_content_type(self): return guess_content_type(self.content_type, self.filename) @property def current_upload(self): return self._current_upload @current_upload.setter def current_upload(self, val): self._current_upload = val def get_actual_size(self): return self._current_upload @property def uri(self): if hasattr(self, '_uri'): return self._uri @uri.setter def uri(self, val): self._uri = val @property def size(self): if hasattr(self, '_size'): return self._size else: return None @size.setter def size(self, val): self._size = val @property def md5(self): if hasattr(self, '_md5'): return self._md5 else: return None @md5.setter def md5(self, val): self._md5 = val @property def extension(self): if getattr(self, '_extension', None): return self._extension else: if '.' in self.filename: return self.filename.split('.')[-1] return None @extension.setter def extension(self, val): self._extension = val
class BaseCloudFile: """Base cloud file storage class""" filename = FieldProperty(IFile['filename']) valid = True def __init__(self, content_type='application/octet-stream', filename=None, size=0, md5=None): if not isinstance(content_type, bytes): content_type = content_type.encode('utf8') self.content_type = content_type if filename is not None: self.filename = filename extension_discovery = filename.split('.') if len(extension_discovery) > 1: self._extension = extension_discovery[-1] elif self.filename is None: self.filename = uuid.uuid4().hex self._size = size self._md5 = md5 self._data = b'' def guess_content_type(self): ct = to_str(self.content_type) if ct == 'application/octet-stream': # try guessing content_type ct, _ = mimetypes.guess_type(self.filename) if ct is None: ct = 'application/octet-stream' return ct def generate_key(self, request, context): return '{}{}/{}::{}'.format(request._container_id, get_content_path(context), context._p_oid, uuid.uuid4().hex) def get_actual_size(self): return self._current_upload def _set_data(self, data): self._data = data def _get_data(self): return self._data data = property(_get_data, _set_data) @property def uri(self): if hasattr(self, '_uri'): return self._uri @property def size(self): if hasattr(self, '_size'): return self._size else: return None @property def md5(self): if hasattr(self, '_md5'): return self._md5 else: return None @property def extension(self): if getattr(self, '_extension', None): return self._extension else: if '.' in self.filename: return self.filename.split('.')[-1] return None async def copy_cloud_file(self, context, new_uri): raise NotImplemented() async def rename_cloud_file(self, new_uri): raise NotImplemented() async def init_upload(self, context): raise NotImplemented() async def append_data(self, data): raise NotImplemented() async def finish_upload(self, context): raise NotImplemented() async def delete_upload(self, uri=None): raise NotImplemented() async def download(self, buf): raise NotImplemented()
from zope.interface import Interface from zope.interface.interfaces import IInterface from zope.interface.interfaces import IMethod import decimal import json import jsonschema import re __docformat__ = 'restructuredtext' # pep 8 friendlyness Container # Fix up bootstrap field types Field.title = FieldProperty(IField['title']) # type: ignore Field.description = FieldProperty(IField['description']) # type: ignore Field.required = FieldProperty(IField['required']) # type: ignore Field.readonly = FieldProperty(IField['readonly']) # type: ignore # Default is already taken care of classImplements(Field, IField) MinMaxLen.min_length = FieldProperty(IMinMaxLen['min_length']) # type: ignore MinMaxLen.max_length = FieldProperty(IMinMaxLen['max_length']) # type: ignore classImplements(Text, IText) classImplements(TextLine, ITextLine) classImplements(Password, IPassword) classImplements(Bool, IBool) classImplements(Bool, IFromUnicode) classImplements(Int, IInt)