b2sdk._internal.scan.policies

class b2sdk._internal.scan.policies.RegexSet(regex_iterable)[source]

Bases: object

Hold a (possibly empty) set of regular expressions and know how to check whether a string matches any of them.

__init__(regex_iterable)[source]
Parameters:

regex_iterable – an interable which yields regexes

matches(s)[source]

Check whether a string matches any of regular expressions.

Parameters:

s (str) – a string to check

Return type:

bool

b2sdk._internal.scan.policies.convert_dir_regex_to_dir_prefix_regex(dir_regex)[source]

The patterns used to match directory names (and file names) are allowed to match a prefix of the name. This ‘feature’ was unintentional, but is being retained for compatibility.

This means that a regex that matches a directory name can’t be used directly to match against a file name and test whether the file should be excluded because it matches the directory.

The pattern ‘photos’ will match directory names ‘photos’ and ‘photos2’, and should exclude files ‘photos/kitten.jpg’, and ‘photos2/puppy.jpg’. It should not exclude ‘photos.txt’, because there is no directory name that matches.

On the other hand, the pattern ‘photos$’ should match ‘photos/kitten.jpg’, but not ‘photos2/puppy.jpg’, nor ‘photos.txt’

If the original regex is valid, there are only two cases to consider: either the regex ends in ‘$’ or does not.

Parameters:

dir_regex (str | Pattern) – a regular expression string or literal

Return type:

str

Returns:

a regular expression string which matches the directory prefix

class b2sdk._internal.scan.policies.IntegerRange(begin, end)[source]

Bases: object

Hold a range of two integers. If the range value is None, it indicates that the value should be treated as -Inf (for begin) or +Inf (for end).

__init__(begin, end)[source]
Parameters:
  • begin (int) – begin position of the range (included)

  • end (int) – end position of the range (included)

class b2sdk._internal.scan.policies.ScanPoliciesManager(exclude_dir_regexes=(), exclude_file_regexes=(), include_file_regexes=(), exclude_all_symlinks=False, exclude_modified_before=None, exclude_modified_after=None, exclude_uploaded_before=None, exclude_uploaded_after=None)[source]

Bases: object

Policy object used when scanning folders, used to decide which files to include in the list of files.

Code that scans through files should at least use should_exclude_file() to decide whether each file should be included; it will check include/exclude patterns for file names, as well as patterns for excluding directories.

Code that scans may optionally use should_exclude_directory() to test whether it can skip a directory completely and not bother listing the files and sub-directories in it.

Parameters:
__init__(exclude_dir_regexes=(), exclude_file_regexes=(), include_file_regexes=(), exclude_all_symlinks=False, exclude_modified_before=None, exclude_modified_after=None, exclude_uploaded_before=None, exclude_uploaded_after=None)[source]
Parameters:
  • exclude_dir_regexes (Iterable[str | Pattern]) – regexes to exclude directories

  • exclude_file_regexes (Iterable[str | Pattern]) – regexes to exclude files

  • include_file_regexes (Iterable[str | Pattern]) – regexes to include files

  • exclude_all_symlinks (bool) – if True, exclude all symlinks

  • exclude_modified_before (Optional[int]) – optionally exclude file versions (both local and b2) modified before (in millis)

  • exclude_modified_after (Optional[int]) – optionally exclude file versions (both local and b2) modified after (in millis)

  • exclude_uploaded_before (Optional[int]) – optionally exclude b2 file versions uploaded before (in millis)

  • exclude_uploaded_after (Optional[int]) – optionally exclude b2 file versions uploaded after (in millis)

The regex matching priority for a given path is: 1) the path is always excluded if it’s dir matches exclude_dir_regexes, if not then 2) the path is always included if it matches include_file_regexes, if not then 3) the path is excluded if it matches exclude_file_regexes, if not then 4) the path is included

should_exclude_local_path(local_path)[source]

Whether a local path should be excluded from the scan or not.

This method assumes that the directory holding the path_ has already been checked for exclusion.

Parameters:

local_path (LocalPath) –

should_exclude_b2_file_version(file_version, relative_path)[source]

Whether a b2 file version should be excluded from the scan or not.

This method assumes that the directory holding the path_ has already been checked for exclusion.

Parameters:
  • file_version (FileVersion) –

  • relative_path (str) –

should_exclude_b2_directory(dir_path)[source]

Given the path of a directory, relative to the scan point, decide if all of the files in it should be excluded from the scan.

Parameters:

dir_path (str) –

should_exclude_local_directory(dir_path)[source]

Given the path of a directory, relative to the scan point, decide if all of the files in it should be excluded from the scan.

Parameters:

dir_path (str) –