b2sdk.raw_api
– B2 raw api wrapper¶
-
class
b2sdk.raw_api.
AbstractRawApi
[source]¶ Bases:
object
Direct access to the B2 web apis.
-
abstract
copy_file
(api_url, account_auth_token, source_file_id, new_file_name, bytes_range=None, metadata_directive=None, content_type=None, file_info=None, destination_bucket_id=None)[source]¶
-
abstract
list_parts
(api_url, account_auth_token, file_id, start_part_number, max_part_count)[source]¶
-
abstract
list_unfinished_large_files
(api_url, account_auth_token, bucket_id, start_file_id=None, max_file_count=None)[source]¶
-
abstract
start_large_file
(api_url, account_auth_token, bucket_id, file_name, content_type, file_info)[source]¶
-
abstract
-
class
b2sdk.raw_api.
B2RawApi
(b2_http)[source]¶ Bases:
b2sdk.raw_api.AbstractRawApi
Provides access to the B2 web APIs, exactly as they are provided by b2.
Requires that you provide all necessary URLs and auth tokens for each call.
Each API call decodes the returned JSON and returns a dict.
- For details on what each method does, see the B2 docs:
This class is intended to be a super-simple, very thin layer on top of the HTTP calls. It can be mocked-out for testing higher layers. And this class can be tested by exercising each call just once, which is relatively quick.
All public methods of this class except authorize_account shall accept api_url and account_info as first two positional arguments. This is needed for B2Session magic.
-
check_b2_filename
(filename)[source]¶ Raise an appropriate exception with details if the filename is unusable.
See https://www.backblaze.com/b2/docs/files.html for the rules.
- Parameters
filename – A proposed filename in unicode.
- Returns
None if the filename is usable.
-
copy_file
(api_url, account_auth_token, source_file_id, new_file_name, bytes_range=None, metadata_directive=None, content_type=None, file_info=None, destination_bucket_id=None)[source]¶
-
create_bucket
(api_url, account_auth_token, account_id, bucket_name, bucket_type, bucket_info=None, cors_rules=None, lifecycle_rules=None)[source]¶
-
create_key
(api_url, account_auth_token, account_id, capabilities, key_name, valid_duration_seconds, bucket_id, name_prefix)[source]¶
-
download_file_from_url
(_, account_auth_token_or_none, url, range_=None)[source]¶ Issues a streaming request for download of a file, potentially authorized.
- Parameters
_ – unused (caused by B2Session magic)
account_auth_token_or_none – an optional account auth token to pass in
url – The full URL to download from
range – two-element tuple for http Range header
- Returns
b2_http response
-
list_file_names
(api_url, account_auth_token, bucket_id, start_file_name=None, max_file_count=None, prefix=None)[source]¶
-
list_file_versions
(api_url, account_auth_token, bucket_id, start_file_name=None, start_file_id=None, max_file_count=None, prefix=None)[source]¶
-
list_keys
(api_url, account_auth_token, account_id, max_key_count=None, start_application_key_id=None)[source]¶
-
list_unfinished_large_files
(api_url, account_auth_token, bucket_id, start_file_id=None, max_file_count=None)[source]¶
-
start_large_file
(api_url, account_auth_token, bucket_id, file_name, content_type, file_info)[source]¶
-
unprintable_to_hex
(string)[source]¶ Replace unprintable chars in string with a hex representation.
- Parameters
string – An arbitrary string, possibly with unprintable characters.
- Returns
The string, with unprintable characters changed to hex (e.g., “”)
-
update_bucket
(api_url, account_auth_token, account_id, bucket_id, bucket_type=None, bucket_info=None, cors_rules=None, lifecycle_rules=None, if_revision_is=None)[source]¶
-
upload_file
(upload_url, upload_auth_token, file_name, content_length, content_type, content_sha1, file_infos, data_stream)[source]¶ Uploads one small file to b2.
- Parameters
upload_url – The upload_url from b2_authorize_account
upload_auth_token – The auth token from b2_authorize_account
file_name – The name of the B2 file
content_length – Number of bytes in the file.
content_type – MIME type.
content_sha1 – Hex SHA1 of the contents of the file
file_infos – Extra file info to upload
data_stream – A file like object from which the contents of the file can be read.
- Returns
-
class
b2sdk.raw_api.
MetadataDirectiveMode
[source]¶ Bases:
enum.Enum
An enumeration.
-
COPY
= 401¶
-
REPLACE
= 402¶
-
-
b2sdk.raw_api.
test_raw_api
()[source]¶ Exercises the code in B2RawApi by making each call once, just to make sure the parameters are passed in, and the result is passed back.
The goal is to be a complete test of B2RawApi, so the tests for the rest of the code can use the simulator.
Prints to stdout if things go wrong.
- Returns
0 on success, non-zero on failure.
-
b2sdk.raw_api.
test_raw_api_helper
(raw_api)[source]¶ Tries each of the calls to the raw api. Raises an except if anything goes wrong.
This uses a Backblaze account that is just for this test. The account uses the free level of service, which should be enough to run this test a reasonable number of times each day. If somebody abuses the account for other things, this test will break and we’ll have to do something about it.