corehttp package¶
- class corehttp.MatchConditions(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
An enum to describe match conditions.
- IfMissing = 5¶
If the target object does not exist. Usually it maps to etag!=’*’
- IfModified = 3¶
Only if the target object is modified. Usually it maps to etag!=<specific etag>
- IfNotModified = 2¶
If the target object is not modified. Usually it maps to etag=<specific etag>
- IfPresent = 4¶
If the target object exists. Usually it maps to etag=’*’
- Unconditionally = 1¶
Matches any condition
Subpackages¶
- corehttp.rest package
AsyncHttpResponse
AsyncHttpResponse.close()
AsyncHttpResponse.iter_bytes()
AsyncHttpResponse.iter_raw()
AsyncHttpResponse.json()
AsyncHttpResponse.raise_for_status()
AsyncHttpResponse.read()
AsyncHttpResponse.text()
AsyncHttpResponse.content
AsyncHttpResponse.content_type
AsyncHttpResponse.encoding
AsyncHttpResponse.headers
AsyncHttpResponse.is_closed
AsyncHttpResponse.is_stream_consumed
AsyncHttpResponse.reason
AsyncHttpResponse.request
AsyncHttpResponse.status_code
AsyncHttpResponse.url
HttpRequest
HttpResponse
HttpResponse.close()
HttpResponse.iter_bytes()
HttpResponse.iter_raw()
HttpResponse.json()
HttpResponse.raise_for_status()
HttpResponse.read()
HttpResponse.text()
HttpResponse.content
HttpResponse.content_type
HttpResponse.encoding
HttpResponse.headers
HttpResponse.is_closed
HttpResponse.is_stream_consumed
HttpResponse.reason
HttpResponse.request
HttpResponse.status_code
HttpResponse.url
- corehttp.runtime package
- corehttp.transport package
- corehttp.utils package
CaseInsensitiveDict
CaseInsensitiveDict.clear()
CaseInsensitiveDict.copy()
CaseInsensitiveDict.get()
CaseInsensitiveDict.items()
CaseInsensitiveDict.keys()
CaseInsensitiveDict.lowerkey_items()
CaseInsensitiveDict.pop()
CaseInsensitiveDict.popitem()
CaseInsensitiveDict.setdefault()
CaseInsensitiveDict.update()
CaseInsensitiveDict.values()
CaseInsensitiveEnumMeta
case_insensitive_dict()
Submodules¶
corehttp.credentials module¶
- class corehttp.credentials.AccessToken(token: str, expires_on: int)[source]¶
Represents an OAuth access token.
Create new instance of AccessToken(token, expires_on)
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- class corehttp.credentials.AsyncTokenCredential(*args, **kwargs)[source]¶
Protocol for classes able to provide OAuth tokens.
- async get_token(*scopes: str, claims: str | None = None, **kwargs: Any) AccessToken [source]¶
Request an access token for scopes.
- Parameters:
scopes (str) – The type of access needed.
- Keyword Arguments:
claims (str) – Additional claims required in the token, such as those returned in a resource provider’s claims challenge following an authorization failure.
- Return type:
- Returns:
An AccessToken instance containing the token string and its expiration time in Unix time.
- class corehttp.credentials.ServiceKeyCredential(key: str)[source]¶
Credential type used for authenticating to a service. It provides the ability to update the key without creating a new client.
- Parameters:
key (str) – The key used to authenticate to a service
- Raises:
TypeError
- class corehttp.credentials.ServiceNamedKeyCredential(name: str, key: str)[source]¶
Credential type used for working with any service needing a named key that follows patterns established by the other credential types.
- Parameters:
- Raises:
TypeError
- update(name: str, key: str) None [source]¶
Update the named key credential.
Both name and key must be provided in order to update the named key credential. Individual attributes cannot be updated.
- property named_key: ServiceNamedKey¶
The value of the configured name.
- Return type:
ServiceNamedKey
- Returns:
The value of the configured name.
- class corehttp.credentials.TokenCredential(*args, **kwargs)[source]¶
Protocol for classes able to provide OAuth tokens.
- get_token(*scopes: str, claims: str | None = None, **kwargs: Any) AccessToken [source]¶
Request an access token for scopes.
- Parameters:
scopes (str) – The type of access needed.
- Keyword Arguments:
claims (str) – Additional claims required in the token, such as those returned in a resource provider’s claims challenge following an authorization failure.
- Return type:
- Returns:
An AccessToken instance containing the token string and its expiration time in Unix time.
corehttp.exceptions module¶
- exception corehttp.exceptions.BaseError(message: object | None, *args: Any, **kwargs: Any)[source]¶
Base exception for all errors.
- Parameters:
message (object) – The message object stringified as ‘message’ attribute
- Keyword Arguments:
error (Exception) – The original exception if any
- Variables:
inner_exception (Exception) – The exception passed with the ‘error’ kwarg
exc_type – The exc_type from sys.exc_info()
exc_value – The exc_value from sys.exc_info()
exc_traceback – The exc_traceback from sys.exc_info()
exc_msg – A string formatting of message parameter, exc_type and exc_value
message (str) – A stringified version of the message parameter
continuation_token (str) – A token reference to continue an incomplete operation. This value is optional and will be None where continuation is either unavailable or not applicable.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception corehttp.exceptions.ClientAuthenticationError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
An error response with status code 4xx. This will not be raised directly by the core pipeline.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.DecodeError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
Error raised during response deserialization.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.DeserializationError[source]¶
Raised if an error is encountered during deserialization.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception corehttp.exceptions.HttpResponseError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
A request was made, and a non-success status code was received from the service.
- Parameters:
message (object) – The message object stringified as ‘message’ attribute
response (HttpResponse or AsyncHttpResponse) – The response that triggered the exception.
- Variables:
reason (str) – The HTTP response reason
status_code (int) – HttpResponse’s status code
response (HttpResponse or AsyncHttpResponse) – The response that triggered the exception.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.ResourceExistsError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
An error response with status code 4xx. This will not be raised directly by the core pipeline.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.ResourceModifiedError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
An error response with status code 4xx, typically 412 Conflict. This will not be raised directly by the core pipeline.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.ResourceNotFoundError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
An error response, typically triggered by a 412 response (for update) or 404 (for get/post)
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.ResourceNotModifiedError(message: object | None = None, response: _HttpResponseCommonAPI | None = None, **kwargs: Any)[source]¶
An error response with status code 304. This will not be raised directly by the core pipeline.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.ResponseNotReadError(response: _HttpResponseCommonAPI)[source]¶
Error thrown if you try to access a response’s content without reading first.
It is thrown if you try to access an ~corehttp.rest.HttpResponse or ~corehttp.rest.AsyncHttpResponse’s content without first reading the response’s bytes in first.
- Parameters:
response (HttpResponse or AsyncHttpResponse) – The response that triggered the exception.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.SerializationError[source]¶
Raised if an error is encountered during serialization.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception corehttp.exceptions.ServiceRequestError(message: object | None, *args: Any, **kwargs: Any)[source]¶
An error occurred while attempt to make a request to the service. No request was sent.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.ServiceResponseError(message: object | None, *args: Any, **kwargs: Any)[source]¶
The request was sent, but the client failed to understand the response. The connection may have timed out. These errors can be retried for idempotent or safe operations
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.StreamClosedError(response: _HttpResponseCommonAPI)[source]¶
Error thrown if you try to access the stream of a response once closed.
It is thrown if you try to read / stream an ~corehttp.rest.HttpResponse or ~corehttp.rest.AsyncHttpResponse once the response’s stream has been closed.
- Parameters:
response (HttpResponse or AsyncHttpResponse) – The response that triggered the exception.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
- exception corehttp.exceptions.StreamConsumedError(response: _HttpResponseCommonAPI)[source]¶
Error thrown if you try to access the stream of a response once consumed.
It is thrown if you try to read / stream an ~corehttp.rest.HttpResponse or ~corehttp.rest.AsyncHttpResponse once the response’s stream has been consumed.
- Parameters:
response (HttpResponse or AsyncHttpResponse) – The response that triggered the exception.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exc_traceback: TracebackType | None¶
- exc_value: BaseException | None¶
- inner_exception: BaseException | None¶
corehttp.paging module¶
- class corehttp.paging.AsyncItemPaged(*args: Any, **kwargs: Any)[source]¶
Return an async iterator of items.
args and kwargs will be passed to the AsyncPageIterator constructor directly, except page_iterator_class
- by_page(continuation_token: str | None = None) AsyncIterator[AsyncIterator[ReturnType]] [source]¶
Get an async iterator of pages of objects, instead of an async iterator of objects.
- Parameters:
continuation_token (str) – An opaque continuation token. This value can be retrieved from the continuation_token field of a previous generator object. If specified, this generator will begin returning results from this point.
- Returns:
An async iterator of pages (themselves async iterator of objects)
- Return type:
AsyncIterator[AsyncIterator[ReturnType]]
- class corehttp.paging.AsyncPageIterator(get_next: Callable[[str | None], Awaitable[ResponseType]], extract_data: Callable[[ResponseType], Awaitable[Tuple[str, AsyncIterator[ReturnType]]]], continuation_token: str | None = None)[source]¶
Return an async iterator of pages.
- Parameters:
get_next – Callable that take the continuation token and return a HTTP response
extract_data – Callable that take an HTTP response and return a tuple continuation token, list of ReturnType
continuation_token (str) – The continuation token needed by get_next
- class corehttp.paging.ItemPaged(*args: Any, **kwargs: Any)[source]¶
Return an iterator of items.
args and kwargs will be passed to the PageIterator constructor directly, except page_iterator_class
- by_page(continuation_token: str | None = None) Iterator[Iterator[ReturnType]] [source]¶
Get an iterator of pages of objects, instead of an iterator of objects.
- Parameters:
continuation_token (str) – An opaque continuation token. This value can be retrieved from the continuation_token field of a previous generator object. If specified, this generator will begin returning results from this point.
- Returns:
An iterator of pages (themselves iterator of objects)
- Return type:
iterator[iterator[ReturnType]]
- next() ReturnType ¶
Return the next item from the iterator. When exhausted, raise StopIteration
- class corehttp.paging.PageIterator(get_next: Callable[[str | None], ResponseType], extract_data: Callable[[ResponseType], Tuple[str, Iterable[ReturnType]]], continuation_token: str | None = None)[source]¶
Return an iterator of pages.
- Parameters:
get_next – Callable that take the continuation token and return a HTTP response
extract_data – Callable that take an HTTP response and return a tuple continuation token, list of ReturnType
continuation_token (str) – The continuation token needed by get_next
corehttp.serialization module¶
- class corehttp.serialization.CoreJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
A JSON encoder that’s capable of serializing datetime objects and bytes.
Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.
If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.
If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.
If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.
If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.
If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.
If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is
None
and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a
TypeError
.- default(o: Any) Any [source]¶
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- encode(o)¶
Return a JSON string representation of a Python data structure.
>>> from json.encoder import JSONEncoder >>> JSONEncoder().encode({"foo": ["bar", "baz"]}) '{"foo": ["bar", "baz"]}'
- iterencode(o, _one_shot=False)¶
Encode the given object and yield each string representation as available.
For example:
for chunk in JSONEncoder().iterencode(bigobject): mysocket.write(chunk)
- item_separator = ', '¶
- key_separator = ': '¶
- corehttp.serialization.NULL = <corehttp.serialization._Null object>¶
A falsy sentinel object which is supposed to be used to specify attributes with no data. This gets serialized to null on the wire.