feat(phase1): add image storage utilities
- Create backend/services/image_storage.py with 4 core functions:
- sanitize_filename(): remove unsafe chars, limit to 255 chars, convert to lowercase
- get_unique_filename(): handle collisions with UUID suffix (format: {name}_{uuid8}_{variant}.jpg)
- ensure_image_directories(): create /images/ root and category subdirs on startup
- save_image(): save bytes to /images/{category}/{filename}, returns relative path
- Create comprehensive test suite (22 tests) covering all functionality
- Integrate ensure_image_directories() into FastAPI startup event
- Directory structure: /images/{category}/{filename}
- Collision handling: auto-suffix with UUID if filename exists
- All tests passing, pathlib.Path for safe operations
This commit is contained in:
55
venv/lib/python3.12/site-packages/pygments/lexers/asc.py
Normal file
55
venv/lib/python3.12/site-packages/pygments/lexers/asc.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
pygments.lexers.asc
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Lexer for various ASCII armored files.
|
||||
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
import re
|
||||
|
||||
from pygments.lexer import RegexLexer, bygroups
|
||||
from pygments.token import Comment, Generic, Name, Operator, String, Whitespace
|
||||
|
||||
__all__ = ['AscLexer']
|
||||
|
||||
|
||||
class AscLexer(RegexLexer):
|
||||
"""
|
||||
Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped
|
||||
base64 data.
|
||||
"""
|
||||
name = 'ASCII armored'
|
||||
aliases = ['asc', 'pem']
|
||||
filenames = [
|
||||
'*.asc', # PGP; *.gpg, *.pgp, and *.sig too, but those can be binary
|
||||
'*.pem', # X.509; *.cer, *.crt, *.csr, and key etc too, but those can be binary
|
||||
'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk',
|
||||
'id_rsa', # SSH private keys
|
||||
]
|
||||
mimetypes = ['application/pgp-keys', 'application/pgp-encrypted',
|
||||
'application/pgp-signature', 'application/pem-certificate-chain']
|
||||
url = 'https://www.openpgp.org'
|
||||
version_added = '2.10'
|
||||
|
||||
flags = re.MULTILINE
|
||||
|
||||
tokens = {
|
||||
'root': [
|
||||
(r'\s+', Whitespace),
|
||||
(r'^-----BEGIN [^\n]+-----$', Generic.Heading, 'data'),
|
||||
(r'\S+', Comment),
|
||||
],
|
||||
'data': [
|
||||
(r'\s+', Whitespace),
|
||||
(r'^([^:]+)(:)([ \t]+)(.*)',
|
||||
bygroups(Name.Attribute, Operator, Whitespace, String)),
|
||||
(r'^-----END [^\n]+-----$', Generic.Heading, 'root'),
|
||||
(r'\S+', String),
|
||||
],
|
||||
}
|
||||
|
||||
def analyse_text(text):
|
||||
if re.search(r'^-----BEGIN [^\n]+-----\r?\n', text):
|
||||
return True
|
||||
Reference in New Issue
Block a user