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:
43
venv/lib/python3.12/site-packages/pygments/modeline.py
Normal file
43
venv/lib/python3.12/site-packages/pygments/modeline.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
pygments.modeline
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
A simple modeline parser (based on pymodeline).
|
||||
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
__all__ = ['get_filetype_from_buffer']
|
||||
|
||||
|
||||
modeline_re = re.compile(r'''
|
||||
(?: vi | vim | ex ) (?: [<=>]? \d* )? :
|
||||
.* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ )
|
||||
''', re.VERBOSE)
|
||||
|
||||
|
||||
def get_filetype_from_line(l): # noqa: E741
|
||||
m = modeline_re.search(l)
|
||||
if m:
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def get_filetype_from_buffer(buf, max_lines=5):
|
||||
"""
|
||||
Scan the buffer for modelines and return filetype if one is found.
|
||||
"""
|
||||
lines = buf.splitlines()
|
||||
for line in lines[-1:-max_lines-1:-1]:
|
||||
ret = get_filetype_from_line(line)
|
||||
if ret:
|
||||
return ret
|
||||
for i in range(max_lines, -1, -1):
|
||||
if i < len(lines):
|
||||
ret = get_filetype_from_line(lines[i])
|
||||
if ret:
|
||||
return ret
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user