|
1 | 1 | from collections.abc import Sequence
|
| 2 | +from datetime import datetime |
| 3 | +from typing import TypedDict |
2 | 4 |
|
3 |
| -from .__get import GetOptions |
4 | 5 | from ._attributes import Attributes
|
5 | 6 | from ._bytes import Bytes
|
6 | 7 | from ._list import ObjectMeta
|
7 | 8 | from .store import ObjectStore
|
8 | 9 |
|
| 10 | +class OffsetRange(TypedDict): |
| 11 | + """Request all bytes starting from a given byte offset.""" |
| 12 | + |
| 13 | + offset: int |
| 14 | + """The byte offset for the offset range request.""" |
| 15 | + |
| 16 | +class SuffixRange(TypedDict): |
| 17 | + """Request up to the last `n` bytes.""" |
| 18 | + |
| 19 | + suffix: int |
| 20 | + """The number of bytes from the suffix to request.""" |
| 21 | + |
| 22 | +class GetOptions(TypedDict, total=False): |
| 23 | + """Options for a get request. |
| 24 | +
|
| 25 | + All options are optional. |
| 26 | + """ |
| 27 | + |
| 28 | + if_match: str | None |
| 29 | + """ |
| 30 | + Request will succeed if the `ObjectMeta::e_tag` matches |
| 31 | + otherwise returning [`PreconditionError`][obstore.exceptions.PreconditionError]. |
| 32 | +
|
| 33 | + See <https://datatracker.ietf.org/doc/html/rfc9110#name-if-match> |
| 34 | +
|
| 35 | + Examples: |
| 36 | +
|
| 37 | + ```text |
| 38 | + If-Match: "xyzzy" |
| 39 | + If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" |
| 40 | + If-Match: * |
| 41 | + ``` |
| 42 | + """ |
| 43 | + |
| 44 | + if_none_match: str | None |
| 45 | + """ |
| 46 | + Request will succeed if the `ObjectMeta::e_tag` does not match |
| 47 | + otherwise returning [`NotModifiedError`][obstore.exceptions.NotModifiedError]. |
| 48 | +
|
| 49 | + See <https://datatracker.ietf.org/doc/html/rfc9110#section-13.1.2> |
| 50 | +
|
| 51 | + Examples: |
| 52 | +
|
| 53 | + ```text |
| 54 | + If-None-Match: "xyzzy" |
| 55 | + If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz" |
| 56 | + If-None-Match: * |
| 57 | + ``` |
| 58 | + """ |
| 59 | + |
| 60 | + if_unmodified_since: datetime | None |
| 61 | + """ |
| 62 | + Request will succeed if the object has been modified since |
| 63 | +
|
| 64 | + <https://datatracker.ietf.org/doc/html/rfc9110#section-13.1.3> |
| 65 | + """ |
| 66 | + |
| 67 | + if_modified_since: datetime | None |
| 68 | + """ |
| 69 | + Request will succeed if the object has not been modified since |
| 70 | + otherwise returning [`PreconditionError`][obstore.exceptions.PreconditionError]. |
| 71 | +
|
| 72 | + Some stores, such as S3, will only return `NotModified` for exact |
| 73 | + timestamp matches, instead of for any timestamp greater than or equal. |
| 74 | +
|
| 75 | + <https://datatracker.ietf.org/doc/html/rfc9110#section-13.1.4> |
| 76 | + """ |
| 77 | + |
| 78 | + range: tuple[int, int] | list[int] | OffsetRange | SuffixRange |
| 79 | + """ |
| 80 | + Request transfer of only the specified range of bytes |
| 81 | + otherwise returning [`NotModifiedError`][obstore.exceptions.NotModifiedError]. |
| 82 | +
|
| 83 | + The semantics of this tuple are: |
| 84 | +
|
| 85 | + - `(int, int)`: Request a specific range of bytes `(start, end)`. |
| 86 | +
|
| 87 | + If the given range is zero-length or starts after the end of the object, an |
| 88 | + error will be returned. Additionally, if the range ends after the end of the |
| 89 | + object, the entire remainder of the object will be returned. Otherwise, the |
| 90 | + exact requested range will be returned. |
| 91 | +
|
| 92 | + The `end` offset is _exclusive_. |
| 93 | +
|
| 94 | + - `{"offset": int}`: Request all bytes starting from a given byte offset. |
| 95 | +
|
| 96 | + This is equivalent to `bytes={int}-` as an HTTP header. |
| 97 | +
|
| 98 | + - `{"suffix": int}`: Request the last `int` bytes. Note that here, `int` is _the |
| 99 | + size of the request_, not the byte offset. This is equivalent to `bytes=-{int}` |
| 100 | + as an HTTP header. |
| 101 | +
|
| 102 | + <https://datatracker.ietf.org/doc/html/rfc9110#name-range> |
| 103 | + """ |
| 104 | + |
| 105 | + version: str | None |
| 106 | + """ |
| 107 | + Request a particular object version |
| 108 | + """ |
| 109 | + |
| 110 | + head: bool |
| 111 | + """ |
| 112 | + Request transfer of no content |
| 113 | +
|
| 114 | + <https://datatracker.ietf.org/doc/html/rfc9110#name-head> |
| 115 | + """ |
| 116 | + |
9 | 117 | class GetResult:
|
10 | 118 | """Result for a get request.
|
11 | 119 |
|
|
0 commit comments