MCPcopy Index your code
hub / github.com/RustPython/RustPython / add

Method add

Lib/test/test_tarfile.py:3599–3638  ·  view source on GitHub ↗

Add a member to the test archive. Call within `with`. Provides many shortcuts: - default `type` is based on symlink_to, hardlink_to, and trailing `/` in name (which is stripped) - size & content defaults are based on each other - content can be str or bytes

(self, name, *, type=None, symlink_to=None, hardlink_to=None,
            mode=None, size=None, content=None, **kwargs)

Source from the content-addressed store, hash-verified

3597 self.bio = None
3598
3599 def add(self, name, *, type=None, symlink_to=None, hardlink_to=None,
3600 mode=None, size=None, content=None, **kwargs):
3601 """Add a member to the test archive. Call within `with`.
3602
3603 Provides many shortcuts:
3604 - default `type` is based on symlink_to, hardlink_to, and trailing `/`
3605 in name (which is stripped)
3606 - size & content defaults are based on each other
3607 - content can be str or bytes
3608 - mode should be textual ('-rwxrwxrwx')
3609
3610 (add more! this is unstable internal test-only API)
3611 """
3612 name = str(name)
3613 tarinfo = tarfile.TarInfo(name).replace(**kwargs)
3614 if content is not None:
3615 if isinstance(content, str):
3616 content = content.encode()
3617 size = len(content)
3618 if size is not None:
3619 tarinfo.size = size
3620 if content is None:
3621 content = bytes(tarinfo.size)
3622 if mode:
3623 tarinfo.mode = _filemode_to_int(mode)
3624 if symlink_to is not None:
3625 type = tarfile.SYMTYPE
3626 tarinfo.linkname = str(symlink_to)
3627 if hardlink_to is not None:
3628 type = tarfile.LNKTYPE
3629 tarinfo.linkname = str(hardlink_to)
3630 if name.endswith('/') and type is None:
3631 type = tarfile.DIRTYPE
3632 if type is not None:
3633 tarinfo.type = type
3634 if tarinfo.isreg():
3635 fileobj = io.BytesIO(content)
3636 else:
3637 fileobj = None
3638 self.tar_w.addfile(tarinfo, fileobj)
3639
3640 def open(self, **kwargs):
3641 """Open the resulting archive as TarFile. Call after `with`."""

Callers 15

add_dir_and_getmemberMethod · 0.45
test_tar_sizeMethod · 0.45
test_add_selfMethod · 0.45
test_filterMethod · 0.45
_test_pathnameMethod · 0.45
test_cwdMethod · 0.45
test_createMethod · 0.45
test_create_existingMethod · 0.45
test_create_taropenMethod · 0.45

Calls 9

strFunction · 0.85
isinstanceFunction · 0.85
lenFunction · 0.85
_filemode_to_intFunction · 0.85
isregMethod · 0.80
addfileMethod · 0.80
replaceMethod · 0.45
encodeMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected