modosaic.services.extension¶
modosaic.services.extension ¶
ExtensionService ¶
Helpers for image extensions and filesystem-safe path fragments.
infer_extension_from_bytes
staticmethod
¶
infer_extension_from_bytes(data)
Infer a known image extension from encoded bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Encoded image bytes. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
|
Source code in modosaic/services/extension.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
normalize_extension
staticmethod
¶
normalize_extension(extension, fallback='.bin')
Normalize a file extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str | None
|
Optional extension with or without a leading dot. |
required |
fallback
|
str
|
Extension returned when |
'.bin'
|
Returns:
| Type | Description |
|---|---|
str
|
Extension with a leading dot. |
Source code in modosaic/services/extension.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
sanitize_fragment
staticmethod
¶
sanitize_fragment(value)
Convert arbitrary text into a safe filename fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Text to sanitize. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A non-empty fragment containing alphanumeric characters, dots, |
str
|
dashes, and underscores only. |
Source code in modosaic/services/extension.py
23 24 25 26 27 28 29 30 31 32 33 34 35 | |