_datetime_parse.py — anthropic-sdk-python Source File
Architecture documentation for _datetime_parse.py, a python file in the anthropic-sdk-python codebase. 4 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR c8b41cc2_db36_3062_f709_8c907f559cd4["_datetime_parse.py"] cde21691_6a41_9f44_bc0e_fb0aa875b99b["_types"] c8b41cc2_db36_3062_f709_8c907f559cd4 --> cde21691_6a41_9f44_bc0e_fb0aa875b99b cc059f4f_d2bd_7056_9086_eaeec58cbdc0["re"] c8b41cc2_db36_3062_f709_8c907f559cd4 --> cc059f4f_d2bd_7056_9086_eaeec58cbdc0 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] c8b41cc2_db36_3062_f709_8c907f559cd4 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 7e1d14c5_475e_409c_7c4e_1274f9d40aa9["datetime"] c8b41cc2_db36_3062_f709_8c907f559cd4 --> 7e1d14c5_475e_409c_7c4e_1274f9d40aa9 6dadb144_3070_6111_357f_214554108905["__init__.py"] 6dadb144_3070_6111_357f_214554108905 --> c8b41cc2_db36_3062_f709_8c907f559cd4 c96ee5ad_7068_af50_518d_eabdd7af5c4e["_compat.py"] c96ee5ad_7068_af50_518d_eabdd7af5c4e --> c8b41cc2_db36_3062_f709_8c907f559cd4 style c8b41cc2_db36_3062_f709_8c907f559cd4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""
This file contains code from https://github.com/pydantic/pydantic/blob/main/pydantic/v1/datetime_parse.py
without the Pydantic v1 specific errors.
"""
from __future__ import annotations
import re
from typing import Dict, Union, Optional
from datetime import date, datetime, timezone, timedelta
from .._types import StrBytesIntFloat
date_expr = r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
time_expr = (
r"(?P<hour>\d{1,2}):(?P<minute>\d{1,2})"
r"(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?"
r"(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$"
)
date_re = re.compile(f"{date_expr}$")
datetime_re = re.compile(f"{date_expr}[T ]{time_expr}")
EPOCH = datetime(1970, 1, 1)
# if greater than this, the number is in ms, if less than or equal it's in seconds
# (in seconds this is 11th October 2603, in ms it's 20th August 1970)
MS_WATERSHED = int(2e10)
# slightly more than datetime.max in ns - (datetime.max - EPOCH).total_seconds() * 1e9
MAX_NUMBER = int(3e20)
def _get_numeric(value: StrBytesIntFloat, native_expected_type: str) -> Union[None, int, float]:
if isinstance(value, (int, float)):
return value
try:
return float(value)
except ValueError:
return None
except TypeError:
raise TypeError(f"invalid type; expected {native_expected_type}, string, bytes, int or float") from None
def _from_unix_seconds(seconds: Union[int, float]) -> datetime:
if seconds > MAX_NUMBER:
return datetime.max
elif seconds < -MAX_NUMBER:
return datetime.min
while abs(seconds) > MS_WATERSHED:
seconds /= 1000
dt = EPOCH + timedelta(seconds=seconds)
return dt.replace(tzinfo=timezone.utc)
def _parse_timezone(value: Optional[str]) -> Union[None, int, timezone]:
if value == "Z":
return timezone.utc
elif value is not None:
offset_mins = int(value[-2:]) if len(value) > 3 else 0
// ... (77 more lines)
Domain
Subdomains
Dependencies
- _types
- datetime
- re
- typing
Source
Frequently Asked Questions
What does _datetime_parse.py do?
_datetime_parse.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What functions are defined in _datetime_parse.py?
_datetime_parse.py defines 5 function(s): _from_unix_seconds, _get_numeric, _parse_timezone, parse_date, parse_datetime.
What does _datetime_parse.py depend on?
_datetime_parse.py imports 4 module(s): _types, datetime, re, typing.
What files import _datetime_parse.py?
_datetime_parse.py is imported by 2 file(s): __init__.py, _compat.py.
Where is _datetime_parse.py in the architecture?
_datetime_parse.py is located at src/anthropic/_utils/_datetime_parse.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: src/anthropic/_utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free