Code
stringlengths
103
85.9k
Summary
listlengths
0
94
Please provide a description of the function:def safe_import(self, name): module = None if name not in self._modules: self._modules[name] = importlib.import_module(name) module = self._modules[name] if not module: dist = next(iter( dist fo...
[ "Helper utility for reimporting previously imported modules while inside the env" ]
Please provide a description of the function:def resolve_dist(cls, dist, working_set): deps = set() deps.add(dist) try: reqs = dist.requires() except (AttributeError, OSError, IOError): # The METADATA file can't be found return deps for req in r...
[ "Given a local distribution and a working set, returns all dependencies from the set.\n\n :param dist: A single distribution to find the dependencies of\n :type dist: :class:`pkg_resources.Distribution`\n :param working_set: A working set to search for all packages\n :type working_set: :...
Please provide a description of the function:def base_paths(self): prefix = make_posix(self.prefix.as_posix()) install_scheme = 'nt' if (os.name == 'nt') else 'posix_prefix' paths = get_paths(install_scheme, vars={ 'base': prefix, 'platbase': prefix, }) ...
[ "\n Returns the context appropriate paths for the environment.\n\n :return: A dictionary of environment specific paths to be used for installation operations\n :rtype: dict\n\n .. note:: The implementation of this is borrowed from a combination of pip and\n virtualenv and is li...
Please provide a description of the function:def python(self): py = vistir.compat.Path(self.base_paths["scripts"]).joinpath("python").absolute().as_posix() if not py: return vistir.compat.Path(sys.executable).as_posix() return py
[ "Path to the environment python" ]
Please provide a description of the function:def sys_path(self): from .vendor.vistir.compat import JSONDecodeError current_executable = vistir.compat.Path(sys.executable).as_posix() if not self.python or self.python == current_executable: return sys.path elif any([s...
[ "\n The system path inside the environment\n\n :return: The :data:`sys.path` from the environment\n :rtype: list\n " ]
Please provide a description of the function:def sys_prefix(self): command = [self.python, "-c" "import sys; print(sys.prefix)"] c = vistir.misc.run(command, return_object=True, block=True, nospin=True, write_to_stdout=False) sys_prefix = vistir.compat.Path(vistir.misc.to_text(c.out).s...
[ "\n The prefix run inside the context of the environment\n\n :return: The python prefix inside the environment\n :rtype: :data:`sys.prefix`\n " ]
Please provide a description of the function:def pip_version(self): from .vendor.packaging.version import parse as parse_version pip = next(iter( pkg for pkg in self.get_installed_packages() if pkg.key == "pip" ), None) if pip is not None: pip_version = p...
[ "\n Get the pip version in the environment. Useful for knowing which args we can use\n when installing.\n " ]
Please provide a description of the function:def get_distributions(self): pkg_resources = self.safe_import("pkg_resources") libdirs = self.base_paths["libdirs"].split(os.pathsep) dists = (pkg_resources.find_distributions(libdir) for libdir in libdirs) for dist in itertools.chai...
[ "\n Retrives the distributions installed on the library path of the environment\n\n :return: A set of distributions found on the library path\n :rtype: iterator\n " ]
Please provide a description of the function:def find_egg(self, egg_dist): site_packages = self.libdir[1] search_filename = "{0}.egg-link".format(egg_dist.project_name) try: user_site = site.getusersitepackages() except AttributeError: user_site = site.US...
[ "Find an egg by name in the given environment" ]
Please provide a description of the function:def dist_is_in_project(self, dist): from .project import _normalized prefixes = [ _normalized(prefix) for prefix in self.base_paths["libdirs"].split(os.pathsep) if _normalized(prefix).startswith(_normalized(self.prefix.as_posi...
[ "Determine whether the supplied distribution is in the environment." ]
Please provide a description of the function:def is_installed(self, pkgname): return any(d for d in self.get_distributions() if d.project_name == pkgname)
[ "Given a package name, returns whether it is installed in the environment\n\n :param str pkgname: The name of a package\n :return: Whether the supplied package is installed in the environment\n :rtype: bool\n " ]
Please provide a description of the function:def run_py(self, cmd, cwd=os.curdir): c = None if isinstance(cmd, six.string_types): script = vistir.cmdparse.Script.parse("{0} -c {1}".format(self.python, cmd)) else: script = vistir.cmdparse.Script.parse([self.pytho...
[ "Run a python command in the enviornment context.\n\n :param cmd: A command to run in the environment - runs with `python -c`\n :type cmd: str or list\n :param str cwd: The working directory in which to execute the command, defaults to :data:`os.curdir`\n :return: A finished command obje...
Please provide a description of the function:def run_activate_this(self): if self.is_venv: activate_this = os.path.join(self.scripts_dir, "activate_this.py") if not os.path.isfile(activate_this): raise OSError("No such file: {0!s}".format(activate_this)) ...
[ "Runs the environment's inline activation script" ]
Please provide a description of the function:def activated(self, include_extras=True, extra_dists=None): if not extra_dists: extra_dists = [] original_path = sys.path original_prefix = sys.prefix parent_path = vistir.compat.Path(__file__).absolute().parent v...
[ "Helper context manager to activate the environment.\n\n This context manager will set the following variables for the duration\n of its activation:\n\n * sys.prefix\n * sys.path\n * os.environ[\"VIRTUAL_ENV\"]\n * os.environ[\"PATH\"]\n\n In addition...
Please provide a description of the function:def uninstall(self, pkgname, *args, **kwargs): auto_confirm = kwargs.pop("auto_confirm", True) verbose = kwargs.pop("verbose", False) with self.activated(): monkey_patch = next(iter( dist for dist in self.base_wor...
[ "A context manager which allows uninstallation of packages from the environment\n\n :param str pkgname: The name of a package to uninstall\n\n >>> env = Environment(\"/path/to/env/root\")\n >>> with env.uninstall(\"pytz\", auto_confirm=True, verbose=False) as uninstaller:\n clean...
Please provide a description of the function:def stn(s, length, encoding, errors): s = s.encode(encoding, errors) return s[:length] + (length - len(s)) * NUL
[ "Convert a string to a null-terminated bytes object.\n " ]
Please provide a description of the function:def nts(s, encoding, errors): p = s.find(b"\0") if p != -1: s = s[:p] return s.decode(encoding, errors)
[ "Convert a null-terminated bytes object to a string.\n " ]
Please provide a description of the function:def nti(s): # There are two possible encodings for a number field, see # itn() below. if s[0] != chr(0o200): try: n = int(nts(s, "ascii", "strict") or "0", 8) except ValueError: raise InvalidHeaderError("invalid header...
[ "Convert a number field to a python number.\n " ]
Please provide a description of the function:def itn(n, digits=8, format=DEFAULT_FORMAT): # POSIX 1003.1-1988 requires numbers to be encoded as a string of # octal digits followed by a null-byte, this allows values up to # (8**(digits-1))-1. GNU tar allows storing numbers greater than # that if nec...
[ "Convert a python number to a number field.\n " ]
Please provide a description of the function:def calc_chksums(buf): unsigned_chksum = 256 + sum(struct.unpack("148B", buf[:148]) + struct.unpack("356B", buf[156:512])) signed_chksum = 256 + sum(struct.unpack("148b", buf[:148]) + struct.unpack("356b", buf[156:512])) return unsigned_chksum, signed_chksum
[ "Calculate the checksum for a member's header by summing up all\n characters except for the chksum field which is treated as if\n it was filled with spaces. According to the GNU tar sources,\n some tars (Sun and NeXT) calculate chksum with signed char,\n which will be different if there are ...
Please provide a description of the function:def copyfileobj(src, dst, length=None): if length == 0: return if length is None: while True: buf = src.read(16*1024) if not buf: break dst.write(buf) return BUFSIZE = 16 * 1024 ...
[ "Copy length bytes from fileobj src to fileobj dst.\n If length is None, copy the entire content.\n " ]
Please provide a description of the function:def filemode(mode): perm = [] for table in filemode_table: for bit, char in table: if mode & bit == bit: perm.append(char) break else: perm.append("-") return "".join(perm)
[ "Convert a file's mode to a string of the form\n -rwxrwxrwx.\n Used by TarFile.list()\n " ]
Please provide a description of the function:def is_tarfile(name): try: t = open(name) t.close() return True except TarError: return False
[ "Return True if name points to a tar archive that we\n are able to handle, else return False.\n " ]
Please provide a description of the function:def _init_write_gz(self): self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED, -self.zlib.MAX_WBITS, self.zlib.DEF_MEM_LEVEL, ...
[ "Initialize for writing with gzip compression.\n " ]
Please provide a description of the function:def write(self, s): if self.comptype == "gz": self.crc = self.zlib.crc32(s, self.crc) self.pos += len(s) if self.comptype != "tar": s = self.cmp.compress(s) self.__write(s)
[ "Write string s to the stream.\n " ]
Please provide a description of the function:def __write(self, s): self.buf += s while len(self.buf) > self.bufsize: self.fileobj.write(self.buf[:self.bufsize]) self.buf = self.buf[self.bufsize:]
[ "Write string s to the stream if a whole new block\n is ready to be written.\n " ]
Please provide a description of the function:def close(self): if self.closed: return if self.mode == "w" and self.comptype != "tar": self.buf += self.cmp.flush() if self.mode == "w" and self.buf: self.fileobj.write(self.buf) self.buf = b...
[ "Close the _Stream object. No operation should be\n done on it afterwards.\n " ]
Please provide a description of the function:def _init_read_gz(self): self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS) self.dbuf = b"" # taken from gzip.GzipFile with some alterations if self.__read(2) != b"\037\213": raise ReadError("not a gzip file") ...
[ "Initialize for reading a gzip compressed fileobj.\n " ]
Please provide a description of the function:def seek(self, pos=0): if pos - self.pos >= 0: blocks, remainder = divmod(pos - self.pos, self.bufsize) for i in range(blocks): self.read(self.bufsize) self.read(remainder) else: raise S...
[ "Set the stream's file pointer to pos. Negative seeking\n is forbidden.\n " ]
Please provide a description of the function:def read(self, size=None): if size is None: t = [] while True: buf = self._read(self.bufsize) if not buf: break t.append(buf) buf = "".join(t) els...
[ "Return the next size number of bytes from the stream.\n If size is not defined, return all bytes of the stream\n up to EOF.\n " ]
Please provide a description of the function:def _read(self, size): if self.comptype == "tar": return self.__read(size) c = len(self.dbuf) while c < size: buf = self.__read(self.bufsize) if not buf: break try: ...
[ "Return size bytes from the stream.\n " ]
Please provide a description of the function:def __read(self, size): c = len(self.buf) while c < size: buf = self.fileobj.read(self.bufsize) if not buf: break self.buf += buf c += len(buf) buf = self.buf[:size] self...
[ "Return size bytes from stream. If internal buffer is empty,\n read another block from the stream.\n " ]
Please provide a description of the function:def read(self, size=None): if size is None: size = self.size - self.position else: size = min(size, self.size - self.position) buf = b"" while size > 0: while True: data, start, sto...
[ "Read data from the file.\n " ]
Please provide a description of the function:def read(self, size=None): if self.closed: raise ValueError("I/O operation on closed file") buf = b"" if self.buffer: if size is None: buf = self.buffer self.buffer = b"" el...
[ "Read at most size bytes from the file. If size is not\n present or None, read all data until EOF is reached.\n " ]
Please provide a description of the function:def readline(self, size=-1): if self.closed: raise ValueError("I/O operation on closed file") pos = self.buffer.find(b"\n") + 1 if pos == 0: # no newline found. while True: buf = self.fileo...
[ "Read one entire line from the file. If size is present\n and non-negative, return a string with at most that\n size, which may be an incomplete line.\n " ]
Please provide a description of the function:def seek(self, pos, whence=os.SEEK_SET): if self.closed: raise ValueError("I/O operation on closed file") if whence == os.SEEK_SET: self.position = min(max(pos, 0), self.size) elif whence == os.SEEK_CUR: i...
[ "Seek to a position in the file.\n " ]
Please provide a description of the function:def get_info(self): info = { "name": self.name, "mode": self.mode & 0o7777, "uid": self.uid, "gid": self.gid, "size": self.size, "mtime": self.mtime, ...
[ "Return the TarInfo's attributes as a dictionary.\n " ]
Please provide a description of the function:def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape"): info = self.get_info() if format == USTAR_FORMAT: return self.create_ustar_header(info, encoding, errors) elif format == GNU_FORMAT: ...
[ "Return a tar header as a string of 512 byte blocks.\n " ]
Please provide a description of the function:def create_ustar_header(self, info, encoding, errors): info["magic"] = POSIX_MAGIC if len(info["linkname"]) > LENGTH_LINK: raise ValueError("linkname is too long") if len(info["name"]) > LENGTH_NAME: info["prefix"], ...
[ "Return the object as a ustar header block.\n " ]
Please provide a description of the function:def create_gnu_header(self, info, encoding, errors): info["magic"] = GNU_MAGIC buf = b"" if len(info["linkname"]) > LENGTH_LINK: buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors) i...
[ "Return the object as a GNU header block sequence.\n " ]
Please provide a description of the function:def create_pax_header(self, info, encoding): info["magic"] = POSIX_MAGIC pax_headers = self.pax_headers.copy() # Test string fields for values that exceed the field length or cannot # be represented in ASCII encoding. for nam...
[ "Return the object as a ustar header block. If it cannot be\n represented this way, prepend a pax extended header sequence\n with supplement information.\n " ]
Please provide a description of the function:def _posix_split_name(self, name): prefix = name[:LENGTH_PREFIX + 1] while prefix and prefix[-1] != "/": prefix = prefix[:-1] name = name[len(prefix):] prefix = prefix[:-1] if not prefix or len(name) > LENGTH_NAM...
[ "Split a name longer than 100 chars into a prefix\n and a name part.\n " ]
Please provide a description of the function:def _create_header(info, format, encoding, errors): parts = [ stn(info.get("name", ""), 100, encoding, errors), itn(info.get("mode", 0) & 0o7777, 8, format), itn(info.get("uid", 0), 8, format), itn(info.get("gi...
[ "Return a header block. info is a dictionary with file\n information, format must be one of the *_FORMAT constants.\n " ]
Please provide a description of the function:def _create_payload(payload): blocks, remainder = divmod(len(payload), BLOCKSIZE) if remainder > 0: payload += (BLOCKSIZE - remainder) * NUL return payload
[ "Return the string payload filled with zero bytes\n up to the next 512 byte border.\n " ]
Please provide a description of the function:def _create_gnu_long_header(cls, name, type, encoding, errors): name = name.encode(encoding, errors) + NUL info = {} info["name"] = "././@LongLink" info["type"] = type info["size"] = len(name) info["magic"] = GNU_MAGI...
[ "Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence\n for name.\n " ]
Please provide a description of the function:def frombuf(cls, buf, encoding, errors): if len(buf) == 0: raise EmptyHeaderError("empty header") if len(buf) != BLOCKSIZE: raise TruncatedHeaderError("truncated header") if buf.count(NUL) == BLOCKSIZE: rai...
[ "Construct a TarInfo object from a 512 byte bytes object.\n " ]
Please provide a description of the function:def fromtarfile(cls, tarfile): buf = tarfile.fileobj.read(BLOCKSIZE) obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors) obj.offset = tarfile.fileobj.tell() - BLOCKSIZE return obj._proc_member(tarfile)
[ "Return the next TarInfo object from TarFile object\n tarfile.\n " ]
Please provide a description of the function:def _proc_member(self, tarfile): if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK): return self._proc_gnulong(tarfile) elif self.type == GNUTYPE_SPARSE: return self._proc_sparse(tarfile) elif self.type in (XHDTYPE, ...
[ "Choose the right processing method depending on\n the type and call it.\n " ]
Please provide a description of the function:def _proc_builtin(self, tarfile): self.offset_data = tarfile.fileobj.tell() offset = self.offset_data if self.isreg() or self.type not in SUPPORTED_TYPES: # Skip the following data blocks. offset += self._block(self.si...
[ "Process a builtin type or an unknown type which\n will be treated as a regular file.\n " ]
Please provide a description of the function:def _proc_gnulong(self, tarfile): buf = tarfile.fileobj.read(self._block(self.size)) # Fetch the next header and process it. try: next = self.fromtarfile(tarfile) except HeaderError: raise SubsequentHeaderErro...
[ "Process the blocks that hold a GNU longname\n or longlink member.\n " ]
Please provide a description of the function:def _proc_sparse(self, tarfile): # We already collected some sparse structures in frombuf(). structs, isextended, origsize = self._sparse_structs del self._sparse_structs # Collect sparse structures from extended header blocks. ...
[ "Process a GNU sparse header plus extra headers.\n " ]
Please provide a description of the function:def _proc_pax(self, tarfile): # Read the header information. buf = tarfile.fileobj.read(self._block(self.size)) # A pax header stores supplemental information for either # the following file (extended) or all following files ...
[ "Process an extended or global header as described in\n POSIX.1-2008.\n " ]
Please provide a description of the function:def _proc_gnusparse_00(self, next, pax_headers, buf): offsets = [] for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf): offsets.append(int(match.group(1))) numbytes = [] for match in re.finditer(br"\d+ GNU.spa...
[ "Process a GNU tar extended sparse header, version 0.0.\n " ]
Please provide a description of the function:def _proc_gnusparse_01(self, next, pax_headers): sparse = [int(x) for x in pax_headers["GNU.sparse.map"].split(",")] next.sparse = list(zip(sparse[::2], sparse[1::2]))
[ "Process a GNU tar extended sparse header, version 0.1.\n " ]
Please provide a description of the function:def _proc_gnusparse_10(self, next, pax_headers, tarfile): fields = None sparse = [] buf = tarfile.fileobj.read(BLOCKSIZE) fields, buf = buf.split(b"\n", 1) fields = int(fields) while len(sparse) < fields * 2: ...
[ "Process a GNU tar extended sparse header, version 1.0.\n " ]
Please provide a description of the function:def _apply_pax_info(self, pax_headers, encoding, errors): for keyword, value in pax_headers.items(): if keyword == "GNU.sparse.name": setattr(self, "path", value) elif keyword == "GNU.sparse.size": seta...
[ "Replace fields with supplemental information from a previous\n pax extended or global header.\n " ]
Please provide a description of the function:def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors): try: return value.decode(encoding, "strict") except UnicodeDecodeError: return value.decode(fallback_encoding, fallback_errors)
[ "Decode a single field from a pax record.\n " ]
Please provide a description of the function:def _block(self, count): blocks, remainder = divmod(count, BLOCKSIZE) if remainder: blocks += 1 return blocks * BLOCKSIZE
[ "Round up a byte count by BLOCKSIZE and return it,\n e.g. _block(834) => 1024.\n " ]
Please provide a description of the function:def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs): if not name and not fileobj: raise ValueError("nothing to open") if mode in ("r", "r:*"): # Find out which *open() is appropriate for opening th...
[ "Open a tar archive for reading, writing or appending. Return\n an appropriate TarFile class.\n\n mode:\n 'r' or 'r:*' open for reading with transparent compression\n 'r:' open for reading exclusively uncompressed\n 'r:gz' open for reading with gzip co...
Please provide a description of the function:def taropen(cls, name, mode="r", fileobj=None, **kwargs): if len(mode) > 1 or mode not in "raw": raise ValueError("mode must be 'r', 'a' or 'w'") return cls(name, mode, fileobj, **kwargs)
[ "Open uncompressed tar archive name for reading or writing.\n " ]
Please provide a description of the function:def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): if len(mode) > 1 or mode not in "rw": raise ValueError("mode must be 'r' or 'w'") try: import gzip gzip.GzipFile except (ImportErro...
[ "Open gzip compressed tar archive name for reading or writing.\n Appending is not allowed.\n " ]
Please provide a description of the function:def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs): if len(mode) > 1 or mode not in "rw": raise ValueError("mode must be 'r' or 'w'.") try: import bz2 except ImportError: raise Compr...
[ "Open bzip2 compressed tar archive name for reading or writing.\n Appending is not allowed.\n " ]
Please provide a description of the function:def getmember(self, name): tarinfo = self._getmember(name) if tarinfo is None: raise KeyError("filename %r not found" % name) return tarinfo
[ "Return a TarInfo object for member `name'. If `name' can not be\n found in the archive, KeyError is raised. If a member occurs more\n than once in the archive, its last occurrence is assumed to be the\n most up-to-date version.\n " ]
Please provide a description of the function:def getmembers(self): self._check() if not self._loaded: # if we want to obtain a list of self._load() # all members, we first have to # scan the whole archive. return self.members
[ "Return the members of the archive as a list of TarInfo objects. The\n list has the same order as the members in the archive.\n " ]
Please provide a description of the function:def gettarinfo(self, name=None, arcname=None, fileobj=None): self._check("aw") # When fileobj is given, replace name by # fileobj's real name. if fileobj is not None: name = fileobj.name # Building the name of th...
[ "Create a TarInfo object for either the file `name' or the file\n object `fileobj' (using os.fstat on its file descriptor). You can\n modify some of the TarInfo's attributes before you add it using\n addfile(). If given, `arcname' specifies an alternative name for the\n file ...
Please provide a description of the function:def list(self, verbose=True): self._check() for tarinfo in self: if verbose: print(filemode(tarinfo.mode), end=' ') print("%s/%s" % (tarinfo.uname or tarinfo.uid, tarinfo.g...
[ "Print a table of contents to sys.stdout. If `verbose' is False, only\n the names of the members are printed. If it is True, an `ls -l'-like\n output is produced.\n " ]
Please provide a description of the function:def addfile(self, tarinfo, fileobj=None): self._check("aw") tarinfo = copy.copy(tarinfo) buf = tarinfo.tobuf(self.format, self.encoding, self.errors) self.fileobj.write(buf) self.offset += len(buf) # If there's data...
[ "Add the TarInfo object `tarinfo' to the archive. If `fileobj' is\n given, tarinfo.size bytes are read from it and added to the archive.\n You can create TarInfo objects using gettarinfo().\n On Windows platforms, `fileobj' should always be opened with mode\n 'rb' to avoid ir...
Please provide a description of the function:def extractall(self, path=".", members=None): directories = [] if members is None: members = self for tarinfo in members: if tarinfo.isdir(): # Extract directories with a safe mode. di...
[ "Extract all members from the archive to the current working\n directory and set owner, modification time and permissions on\n directories afterwards. `path' specifies a different directory\n to extract to. `members' is optional and must be a subset of the\n list returned by ...
Please provide a description of the function:def extract(self, member, path="", set_attrs=True): self._check("r") if isinstance(member, str): tarinfo = self.getmember(member) else: tarinfo = member # Prepare the link target for makelink(). if ta...
[ "Extract a member from the archive to the current working directory,\n using its full name. Its file information is extracted as accurately\n as possible. `member' may be a filename or a TarInfo object. You can\n specify a different directory using `path'. File attributes (owner,\n ...
Please provide a description of the function:def extractfile(self, member): self._check("r") if isinstance(member, str): tarinfo = self.getmember(member) else: tarinfo = member if tarinfo.isreg(): return self.fileobject(self, tarinfo) ...
[ "Extract a member from the archive as a file object. `member' may be\n a filename or a TarInfo object. If `member' is a regular file, a\n file-like object is returned. If `member' is a link, a file-like\n object is constructed from the link's target. If `member' is none of\n ...
Please provide a description of the function:def _extract_member(self, tarinfo, targetpath, set_attrs=True): # Fetch the TarInfo object for the given name # and build the destination pathname, replacing # forward slashes to platform specific separators. targetpath = targetpath.r...
[ "Extract the TarInfo object tarinfo to a physical\n file called targetpath.\n " ]
Please provide a description of the function:def makedir(self, tarinfo, targetpath): try: # Use a safe mode for the directory, the real mode is set # later in _extract_member(). os.mkdir(targetpath, 0o700) except EnvironmentError as e: if e.errno ...
[ "Make a directory called targetpath.\n " ]
Please provide a description of the function:def makefile(self, tarinfo, targetpath): source = self.fileobj source.seek(tarinfo.offset_data) target = bltn_open(targetpath, "wb") if tarinfo.sparse is not None: for offset, size in tarinfo.sparse: target...
[ "Make a file called targetpath.\n " ]
Please provide a description of the function:def makeunknown(self, tarinfo, targetpath): self.makefile(tarinfo, targetpath) self._dbg(1, "tarfile: Unknown file type %r, " \ "extracted as regular file." % tarinfo.type)
[ "Make a file from a TarInfo object with an unknown type\n at targetpath.\n " ]
Please provide a description of the function:def makefifo(self, tarinfo, targetpath): if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
[ "Make a fifo called targetpath.\n " ]
Please provide a description of the function:def makedev(self, tarinfo, targetpath): if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_I...
[ "Make a character or block device called targetpath.\n " ]
Please provide a description of the function:def makelink(self, tarinfo, targetpath): try: # For systems that support symbolic and hard links. if tarinfo.issym(): os.symlink(tarinfo.linkname, targetpath) else: # See extract(). ...
[ "Make a (symbolic) link called targetpath. If it cannot be created\n (platform limitation), we try to make a copy of the referenced file\n instead of a link.\n " ]
Please provide a description of the function:def chown(self, tarinfo, targetpath): if pwd and hasattr(os, "geteuid") and os.geteuid() == 0: # We have to be root to do so. try: g = grp.getgrnam(tarinfo.gname)[2] except KeyError: g = tar...
[ "Set owner of targetpath according to tarinfo.\n " ]
Please provide a description of the function:def chmod(self, tarinfo, targetpath): if hasattr(os, 'chmod'): try: os.chmod(targetpath, tarinfo.mode) except EnvironmentError as e: raise ExtractError("could not change mode")
[ "Set file permissions of targetpath according to tarinfo.\n " ]
Please provide a description of the function:def utime(self, tarinfo, targetpath): if not hasattr(os, 'utime'): return try: os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime)) except EnvironmentError as e: raise ExtractError("could not change modific...
[ "Set modification time of targetpath according to tarinfo.\n " ]
Please provide a description of the function:def next(self): self._check("ra") if self.firstmember is not None: m = self.firstmember self.firstmember = None return m # Read the next block. self.fileobj.seek(self.offset) tarinfo = None...
[ "Return the next member of the archive as a TarInfo object, when\n TarFile is opened for reading. Return None if there is no more\n available.\n " ]
Please provide a description of the function:def _getmember(self, name, tarinfo=None, normalize=False): # Ensure that all members have been loaded. members = self.getmembers() # Limit the member search list up to tarinfo. if tarinfo is not None: members = members[:m...
[ "Find an archive member by name from bottom to top.\n If tarinfo is given, it is used as the starting point.\n " ]
Please provide a description of the function:def _load(self): while True: tarinfo = self.next() if tarinfo is None: break self._loaded = True
[ "Read through the entire archive file and look for readable\n members.\n " ]
Please provide a description of the function:def _check(self, mode=None): if self.closed: raise IOError("%s is closed" % self.__class__.__name__) if mode is not None and self.mode not in mode: raise IOError("bad operation for mode %r" % self.mode)
[ "Check if TarFile is still open, and if the operation's mode\n corresponds to TarFile's mode.\n " ]
Please provide a description of the function:def _find_link_target(self, tarinfo): if tarinfo.issym(): # Always search the entire archive. linkname = os.path.dirname(tarinfo.name) + "/" + tarinfo.linkname limit = None else: # Search the archive be...
[ "Find the target member of a symlink or hardlink member in the\n archive.\n " ]
Please provide a description of the function:def _dbg(self, level, msg): if level <= self.debug: print(msg, file=sys.stderr)
[ "Write debugging output to sys.stderr.\n " ]
Please provide a description of the function:def path_to(self, p): if os.path.isabs(p): return p return os.sep.join([self._original_dir, p])
[ "Returns the absolute path to a given relative path." ]
Please provide a description of the function:def _build_package_list(self, package_section): from pipenv.vendor.requirementslib.utils import is_vcs ps = {} # TODO: Separate the logic for showing packages from the filters for supplying pip-tools for k, v in self.parsed_pipfile.ge...
[ "Returns a list of packages for pip-tools to consume." ]
Please provide a description of the function:def _get_virtualenv_hash(self, name): def get_name(name, location): name = self._sanitize(name) hash = hashlib.sha256(location.encode()).digest()[:6] encoded_hash = base64.urlsafe_b64encode(hash).decode() retu...
[ "Get the name of the virtualenv adjusted for windows if needed\n\n Returns (name, encoded_hash)\n " ]
Please provide a description of the function:def register_proper_name(self, name): with self.proper_names_db_path.open("a") as f: f.write(u"{0}\n".format(name))
[ "Registers a proper name to the database." ]
Please provide a description of the function:def parsed_pipfile(self): contents = self.read_pipfile() # use full contents to get around str/bytes 2/3 issues cache_key = (self.pipfile_location, contents) if cache_key not in _pipfile_cache: parsed = self._parse_pipfile...
[ "Parse Pipfile into a TOMLFile and cache it\n\n (call clear_pipfile_cache() afterwards if mutating)" ]
Please provide a description of the function:def _lockfile(self): pfile = pipfile.load(self.pipfile_location, inject_env=False) lockfile = json.loads(pfile.lock()) for section in ("default", "develop"): lock_section = lockfile.get(section, {}) for key in list(loc...
[ "Pipfile.lock divided by PyPI and external dependencies." ]
Please provide a description of the function:def all_packages(self): p = dict(self.parsed_pipfile.get("dev-packages", {})) p.update(self.parsed_pipfile.get("packages", {})) return p
[ "Returns a list of all packages." ]
Please provide a description of the function:def create_pipfile(self, python=None): from .vendor.pip_shims.shims import ( ConfigOptionParser, make_option_group, index_group ) config_parser = ConfigOptionParser(name=self.name) config_parser.add_option_group(make_opti...
[ "Creates the Pipfile, filled with juicy defaults." ]
Please provide a description of the function:def write_toml(self, data, path=None): if path is None: path = self.pipfile_location data = convert_toml_outline_tables(data) try: formatted_data = tomlkit.dumps(data).rstrip() except Exception: doc...
[ "Writes the given data structure out as TOML." ]
Please provide a description of the function:def write_lockfile(self, content): s = self._lockfile_encoder.encode(content) open_kwargs = {"newline": self._lockfile_newlines, "encoding": "utf-8"} with vistir.contextmanagers.atomic_open_for_write( self.lockfile_location, **ope...
[ "Write out the lockfile.\n " ]
Please provide a description of the function:def find_source(self, source): if not is_valid_url(source): try: source = self.get_source(name=source) except SourceNotFound: source = self.get_source(url=source) else: source = self...
[ "\n Given a source, find it.\n\n source can be a url or an index name.\n " ]
Please provide a description of the function:def get_package_name_in_pipfile(self, package_name, dev=False): key = "dev-packages" if dev else "packages" section = self.parsed_pipfile.get(key, {}) package_name = pep423_name(package_name) for name in section.keys(): if...
[ "Get the equivalent package name in pipfile" ]
Please provide a description of the function:def add_index_to_pipfile(self, index, verify_ssl=True): # Read and append Pipfile. p = self.parsed_pipfile try: self.get_source(url=index) except SourceNotFound: source = {"url": index, "verify_ssl": verify_ssl...
[ "Adds a given index to the Pipfile." ]
Please provide a description of the function:def ensure_proper_casing(self): pfile = self.parsed_pipfile casing_changed = self.proper_case_section(pfile.get("packages", {})) casing_changed |= self.proper_case_section(pfile.get("dev-packages", {})) return casing_changed
[ "Ensures proper casing of Pipfile packages" ]