new image paste module: imgur
This commit is contained in:
parent
910aa6eea1
commit
2c3922ed2c
5 changed files with 183 additions and 0 deletions
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
|
||||
from weboob.capabilities.paste import ICapPaste
|
||||
import binascii
|
||||
|
||||
|
||||
class BasePasteBackend(ICapPaste):
|
||||
|
|
@ -49,6 +50,26 @@ class BasePasteBackend(ICapPaste):
|
|||
return e
|
||||
|
||||
|
||||
def image_mime(data_base64, supported_formats=('gif', 'jpeg', 'png')):
|
||||
try:
|
||||
beginning = data_base64[:24].decode('base64')
|
||||
except binascii.Error, e:
|
||||
return None
|
||||
|
||||
if 'gif' in supported_formats and 'GIF8' in beginning:
|
||||
return 'image/gif'
|
||||
elif 'jpeg' in supported_formats and 'JFIF' in beginning:
|
||||
return 'image/jpeg'
|
||||
elif 'png' in supported_formats and '\x89PNG' in beginning:
|
||||
return 'image/png'
|
||||
elif 'xcf' in supported_formats and 'gimp xcf' in beginning:
|
||||
return 'image/x-xcf'
|
||||
elif 'pdf' in supported_formats and '%PDF' in beginning:
|
||||
return 'application/pdf'
|
||||
elif 'tiff' in supported_formats and ('II\x00\x2a' in beginning or \
|
||||
'MM\x2a\x00' in beginning):
|
||||
return 'image/tiff'
|
||||
|
||||
def test():
|
||||
class MockPasteBackend(BasePasteBackend):
|
||||
def __init__(self, expirations):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue