How to use the b2sdk.utils.b2_url_encode function in b2sdk

To help you get started, we’ve selected a few b2sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Backblaze / b2-sdk-python / test / v1 / test_utils.py View on Github external
def test_it(self):
        for test_case in ENCODING_TEST_CASES:
            string = test_case['string']
            fully_encoded = test_case['fullyEncoded']
            minimally_encoded = test_case['minimallyEncoded']
            encoded = b2sdk.utils.b2_url_encode(string)

            expected_encoded = (minimally_encoded, fully_encoded)
            if encoded not in expected_encoded:
                print(
                    'string: %s   encoded: %s   expected: %s' %
                    (repr(string), encoded, expected_encoded)
                )
            self.assertTrue(encoded in expected_encoded)
            self.assertEqual(string, b2sdk.utils.b2_url_decode(fully_encoded))
            self.assertEqual(string, b2sdk.utils.b2_url_decode(minimally_encoded))
github Backblaze / b2-sdk-python / b2sdk / raw_api.py View on Github external
def get_download_url_by_name(self, download_url, account_auth_token, bucket_name, file_name):
        return download_url + '/file/' + bucket_name + '/' + b2_url_encode(file_name)
github Backblaze / b2-sdk-python / b2sdk / raw_api.py View on Github external
:param content_sha1: hex SHA1 of the contents of the file
        :param file_infos: extra file info to upload
        :param data_stream: a file like object from which the contents of the file can be read
        :return:
        """
        # Raise UnusableFileName if the file_name doesn't meet the rules.
        self.check_b2_filename(file_name)
        headers = {
            'Authorization': upload_auth_token,
            'Content-Length': str(content_length),
            'X-Bz-File-Name': b2_url_encode(file_name),
            'Content-Type': content_type,
            'X-Bz-Content-Sha1': content_sha1
        }
        for k, v in six.iteritems(file_infos):
            headers['X-Bz-Info-' + k] = b2_url_encode(v)

        return self.b2_http.post_content_return_json(upload_url, headers, data_stream)
github Backblaze / b2-sdk-python / b2sdk / raw_api.py View on Github external
:param upload_url: the upload_url from b2_authorize_account
        :param upload_auth_token: the auth token from b2_authorize_account
        :param file_name: the name of the B2 file
        :param content_length: number of bytes in the file
        :param content_type: MIME type
        :param content_sha1: hex SHA1 of the contents of the file
        :param file_infos: extra file info to upload
        :param data_stream: a file like object from which the contents of the file can be read
        :return:
        """
        # Raise UnusableFileName if the file_name doesn't meet the rules.
        self.check_b2_filename(file_name)
        headers = {
            'Authorization': upload_auth_token,
            'Content-Length': str(content_length),
            'X-Bz-File-Name': b2_url_encode(file_name),
            'Content-Type': content_type,
            'X-Bz-Content-Sha1': content_sha1
        }
        for k, v in six.iteritems(file_infos):
            headers['X-Bz-Info-' + k] = b2_url_encode(v)

        return self.b2_http.post_content_return_json(upload_url, headers, data_stream)
github Backblaze / b2-sdk-python / b2sdk / api.py View on Github external
def get_download_url_for_file_name(self, bucket_name, file_name):
        """
        Return a URL to download the given file by name.

        :param str bucket_name: a bucket name
        :param str file_name: a file name
        """
        self.check_bucket_restrictions(bucket_name)
        return '%s/file/%s/%s' % (
            self.account_info.get_download_url(), bucket_name, b2_url_encode(file_name)
        )
github Backblaze / b2-sdk-python / b2sdk / raw_simulator.py View on Github external
def get_download_authorization(
        self, api_url, account_auth_token, bucket_id, file_name_prefix, valid_duration_in_seconds
    ):
        bucket = self._get_bucket_by_id(bucket_id)
        self._assert_account_auth(api_url, account_auth_token, bucket.account_id, 'shareFiles')
        return {
            'bucketId':
                bucket_id,
            'fileNamePrefix':
                file_name_prefix,
            'authorizationToken':
                'fake_download_auth_token_%s_%s_%d' % (
                    bucket_id,
                    b2_url_encode(file_name_prefix),
                    valid_duration_in_seconds,
                )
github Backblaze / b2-sdk-python / b2sdk / bucket.py View on Github external
def get_download_url(self, filename):
        """
        Get file download URL.

        :param str filename: a file name
        :rtype: str
        """
        return "%s/file/%s/%s" % (
            self.api.account_info.get_download_url(),
            b2_url_encode(self.name),
            b2_url_encode(filename),
        )
github Backblaze / b2-sdk-python / b2sdk / bucket.py View on Github external
def get_download_url(self, filename):
        """
        Get file download URL.

        :param str filename: a file name
        :rtype: str
        """
        return "%s/file/%s/%s" % (
            self.api.account_info.get_download_url(),
            b2_url_encode(self.name),
            b2_url_encode(filename),
        )