o2o-site-AEO/solution/backend/services/external/social.py
Mina Choi 11d30bb3d1 [chore] solution,admin,ontology: 코드 주석을 한 줄로 — 히스토리 주석 삭제
여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다.

- ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제
- 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다
- eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다

파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이).
site·frontend·admin tsc, site vitest 105 passed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 16:05:19 +09:00

51 lines
1.1 KiB
Python

"""플랫폼 교체 경계."""
import re
import unicodedata
class SocialError(RuntimeError):
def __init__(self, code="SOCIAL_FAILED", *, reauth=False):
super().__init__(code)
self.reauth = reauth
class SocialOutcomeUnknown(SocialError):
pass
URL = re.compile(r"https?://[^\s]+", re.I)
def weighted_length(text: str, provider: int = 1) -> int:
text = unicodedata.normalize("NFC", text)
if provider == 2:
return len(text)
# 보수적으로 이모지 조합의 각 코드포인트도 센다.
def weight(c):
n = ord(c)
return (
1
if n <= 0x10FF
or 0x2000 <= n <= 0x200D
or 0x2010 <= n <= 0x201F
or 0x2032 <= n <= 0x2037
else 2
)
length = 0
pos = 0
for match in URL.finditer(text):
length += sum(weight(c) for c in text[pos : match.start()]) + 23
pos = match.end()
return length + sum(weight(c) for c in text[pos:])
def adapter(provider: int):
if provider == 2:
from services.external import threads
return threads
raise SocialError("UNSUPPORTED_PROVIDER")