docstring stringlengths 52 499 | function stringlengths 67 35.2k | __index_level_0__ int64 52.6k 1.16M |
|---|---|---|
Adapt weights according one desired value and its input.
Args:
* `d` : desired value (float)
* `x` : input array (1-dimensional array) | def adapt(self, d, x):
self.update_memory_x(x)
m_d, m_x = self.read_memory()
# estimate
y = np.dot(self.w, x-m_x) + m_d
e = d - y
nu = self.mu / (self.eps + np.dot(x-m_x, x-m_x))
dw = nu * e * (x-m_x)
self.w += dw
self.update_memory_d(d) | 504,576 |
Counts the number of entities that match this query.
Note:
Since Datastore doesn't provide a native way to count
entities by query, this method paginates through all the
entities' keys and counts them.
Parameters:
\**options(QueryOptions, optional)
Retu... | def count(self, *, page_size=DEFAULT_BATCH_SIZE, **options):
entities = 0
options = QueryOptions(self).replace(keys_only=True)
for page in self.paginate(page_size=page_size, **options):
entities += len(list(page))
return entities | 504,830 |
Deletes all the entities that match this query.
Note:
Since Datasotre doesn't provide a native way to delete
entities by query, this method paginates through all the
entities' keys and issues a single delete_multi call per
page.
Parameters:
\**options(... | def delete(self, *, page_size=DEFAULT_BATCH_SIZE, **options):
from .model import delete_multi
deleted = 0
options = QueryOptions(self).replace(keys_only=True)
for page in self.paginate(page_size=page_size, **options):
keys = list(page)
deleted += len(key... | 504,831 |
Run this query and get the first result.
Parameters:
\**options(QueryOptions, optional)
Returns:
Model: An entity or None if there were no results. | def get(self, **options):
sub_query = self.with_limit(1)
options = QueryOptions(sub_query).replace(batch_size=1)
for result in sub_query.run(**options):
return result
return None | 504,832 |
Run this query and return a page iterator.
Parameters:
page_size(int): The number of entities to fetch per page.
\**options(QueryOptions, optional)
Returns:
Pages: An iterator for this query's pages of results. | def paginate(self, *, page_size, **options):
return Pages(self._prepare(), page_size, QueryOptions(self, **options)) | 504,833 |
Look up the model instance for a given Datastore kind.
Parameters:
kind(str)
Raises:
RuntimeError: If a model for the given kind has not been
defined.
Returns:
model: The model class. | def lookup_model_by_kind(kind):
model = _known_models.get(kind)
if model is None:
raise RuntimeError(f"Model for kind {kind!r} not found.")
return model | 504,880 |
Build up a Datastore key from a path.
Parameters:
\*path(tuple[str or int]): The path segments.
namespace(str): An optional namespace for the key. This is
applied to each key in the tree.
Returns:
anom.Key: The Datastore represented by the given path. | def from_path(cls, *path, namespace=None):
parent = None
for i in range(0, len(path), 2):
parent = cls(*path[i:i + 2], parent=parent, namespace=namespace)
return parent | 504,885 |
Validates that `value` can be assigned to this Property.
Parameters:
value: The value to validate.
Raises:
TypeError: If the type of the assigned value is invalid.
Returns:
The value that should be assigned to the entity. | def validate(self, value):
if isinstance(value, self._types):
return value
elif self.optional and value is None:
return [] if self.repeated else None
elif self.repeated and isinstance(value, (tuple, list)) and all(isinstance(x, self._types) for x in value):
... | 504,891 |
Prepare `value` for storage. Called by the Model for each
Property, value pair it contains before handing the data off
to an adapter.
Parameters:
entity(Model): The entity to which the value belongs.
value: The value being stored.
Raises:
RuntimeError: If... | def prepare_to_store(self, entity, value):
if value is None and not self.optional:
raise RuntimeError(f"Property {self.name_on_model} requires a value.")
return value | 504,892 |
Get an entity by id.
Parameters:
id_or_name(int or str): The entity's id.
parent(anom.Key, optional): The entity's parent Key.
namespace(str, optional): The entity's namespace.
Returns:
Model: An entity or ``None`` if the entity doesn't exist in
Datast... | def get(cls, id_or_name, *, parent=None, namespace=None):
return Key(cls, id_or_name, parent=parent, namespace=namespace).get() | 504,902 |
Handle any exceptions during API request or
parsing its response status code.
Parameters:
resp: requests.Response instance obtained during concerning request
or None, when request failed
Returns: True if should retry our request or raises original Exception | def _handle_retry(self, resp):
exc_t, exc_v, exc_tb = sys.exc_info()
if exc_t is None:
raise TypeError('Must be called in except block.')
retry_on_exc = tuple(
(x for x in self._retry_on if inspect.isclass(x)))
retry_on_codes = tuple(
(x for... | 506,386 |
Extract the most likely article content from the html page
Args:
url (str): URL to pull and parse
raw_html (str): String representation of the HTML page
Returns:
Article: Representation of the article contents \
including other par... | def extract(self, url=None, raw_html=None):
crawl_candidate = CrawlCandidate(self.config, url, raw_html)
return self.__crawl(crawl_candidate) | 506,952 |
Processes a user command using aliases
Arguments:
command A user command list (e.g. argv)
Returns: A ScubaContext object with the following attributes:
script: a list of command line strings
image: the docker image name to use | def process_command(self, command):
result = ScubaContext()
result.script = None
result.image = self.image
result.entrypoint = self.entrypoint
result.environment = self.environment.copy()
if command:
alias = self.aliases.get(command[0])
i... | 507,227 |
Sorts the rows of a matrix by hierarchical clustering.
Parameters:
U (ndarray) : matrix of data
Returns:
prm (ndarray) : permutation of the rows | def hclust_linearize(U):
from scipy.cluster import hierarchy
Z = hierarchy.ward(U)
return hierarchy.leaves_list(hierarchy.optimal_leaf_ordering(Z, U)) | 508,154 |
Broadcasts plotting option `arg` to all factors.
Args:
U : KTensor
arg : argument provided by the user
argtype : expected type for arg
name : name of the variable, used for error handling
Returns:
iterable version of arg of length U.ndim | def _broadcast_arg(U, arg, argtype, name):
# if input is not iterable, broadcast it all dimensions of the tensor
if arg is None or isinstance(arg, argtype):
return [arg for _ in range(U.ndim)]
# check if iterable input is valid
elif np.iterable(arg):
if len(arg) != U.ndim:
... | 508,166 |
Create a job using current backend. Blocks until all tasks are up and initialized.
Args:
name: name of the job
run_name: name of the run (auto-assigned if empty)
num_tasks: number of tasks
install_script: bash-runnable script
**kwargs:
Returns:
backend.Job | def make_job(name: str = '',
run_name: str = '',
num_tasks: int = 0,
install_script: str = '',
**kwargs
) -> backend.Job:
return _backend.make_job(name=name, run_name=run_name, num_tasks=num_tasks,
install_script=install_sc... | 508,489 |
Switches currently active tmux window for given task. 0 is the default window
Args:
window_id: integer id of tmux window to use | def switch_window(self, window_id: int):
# windows are numbered sequentially 0, 1, 2, ...
# create any missing windows and make them point to the same directory
if window_id not in self.tmux_available_window_ids:
for i in range(max(self.tmux_available_window_ids)+1, window_id+1):
self._r... | 508,495 |
Waits for file maximum of max_wait_sec. Returns True if file was detected within specified max_wait_sec
Args:
fn: filename on task machine
max_wait_sec: how long to wait in seconds
check_interval: how often to check in seconds
Returns:
False if waiting was was cut short by max_wait_sec l... | def wait_for_file(self, fn: str, max_wait_sec: int = 3600 * 24 * 365,
check_interval: float = 0.02) -> bool:
print("Waiting for file", fn)
start_time = time.time()
while True:
if time.time() - start_time > max_wait_sec:
util.log(f"Timeout exceeded ({max_wait_sec} sec) ... | 508,515 |
Uploads given file to the task. If remote_fn is not specified, dumps it
into task current directory with the same name.
Args:
local_fn: location of file locally
remote_fn: location of file on task
dont_overwrite: if True, will be no-op if target file exists | def upload(self, local_fn: str, remote_fn: str = '',
dont_overwrite: bool = False):
raise NotImplementedError() | 508,516 |
Returns ec2.Instance object whose name contains fragment, in reverse order of launching (ie,
most recent intance first). Optionally filters by key, only including instances launched with
key_name matching current username.
args:
verbose: print information about all matching instances found
filter_by_key... | def lookup_instances(fragment, verbose=True, filter_by_key=True):
def vprint(*args):
if verbose:
print(*args)
region = get_region()
client = get_ec2_client()
ec2 = get_ec2_resource()
response = client.describe_instances()
assert is_good_response(response)
instance_list = []
for instance ... | 508,547 |
Initializes Task on top of existing AWS instance. Blocks until instance is ready to execute
shell commands.
Args:
name: task name
instance: ec2.Instance object (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#instance)
install_script:
image_name: AWS i... | def __init__(self, name, *, instance, install_script='', image_name='',
**extra_kwargs):
self._cmd_fn = None
self._cmd = None
self._status_fn = None # location of output of last status
self.last_status = -1
self._can_run = False # indicates that things needed for .run were cre... | 508,582 |
Switches currently active tmux window for given task. 0 is the default window
Args:
window_id: integer id of tmux window to use | def switch_window(self, window_id: int):
# windows are numbered sequentially 0, 1, 2, ...
# create any missing windows and make them point to the same directory
if window_id not in self.tmux_available_window_ids:
for i in range(max(self.tmux_available_window_ids) + 1, window_id + 1):
sel... | 508,595 |
Reverses components in the name of task. Reversed convention is used for filenames since
it groups log/scratch files of related tasks together
0.somejob.somerun -> somerun.somejob.0
0.somejob -> somejob.0
somename -> somename
Args:
name: name of task | def reverse_taskname(name: str) -> str:
components = name.split('.')
assert len(components) <= 3
return '.'.join(components[::-1]) | 508,609 |
A method to parse an ISO9660 Path Table Record out of a string.
Parameters:
data - The string to parse.
Returns:
Nothing. | def parse(self, data):
# type: (bytes) -> None
(self.len_di, self.xattr_length, self.extent_location,
self.parent_directory_num) = struct.unpack_from(self.FMT, data[:8], 0)
if self.len_di % 2 != 0:
self.directory_identifier = data[8:-1]
else:
se... | 510,945 |
An internal method to generate a string representing this Path Table Record.
Parameters:
ext_loc - The extent location to place in this Path Table Record.
parent_dir_num - The parent directory number to place in this Path Table
Record.
Returns:
A str... | def _record(self, ext_loc, parent_dir_num):
# type: (int, int) -> bytes
return struct.pack(self.FMT, self.len_di, self.xattr_length,
ext_loc, parent_dir_num) + self.directory_identifier + b'\x00' * (self.len_di % 2) | 510,946 |
A method to generate a string representing the little endian version of
this Path Table Record.
Parameters:
None.
Returns:
A string representing the little endian version of this Path Table Record. | def record_little_endian(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Path Table Record not yet initialized')
return self._record(self.extent_location, self.parent_directory_num) | 510,947 |
A method to generate a string representing the big endian version of
this Path Table Record.
Parameters:
None.
Returns:
A string representing the big endian version of this Path Table Record. | def record_big_endian(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Path Table Record not yet initialized')
return self._record(utils.swab_32bit(self.extent_location),
utils.swab_16bit(self.pare... | 510,948 |
An internal method to create a new Path Table Record.
Parameters:
name - The name for this Path Table Record.
parent_dir_num - The directory number of the parent of this Path Table
Record.
Returns:
Nothing. | def _new(self, name, parent_dir_num):
# type: (bytes, int) -> None
self.len_di = len(name)
self.xattr_length = 0 # FIXME: we don't support xattr for now
self.parent_directory_num = parent_dir_num
self.directory_identifier = name
self._initialized = True | 510,949 |
A method to create a new Path Table Record.
Parameters:
name - The name for this Path Table Record.
Returns:
Nothing. | def new_dir(self, name):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Path Table Record already initialized')
# Zero for the parent dir num is bogus, but that will get fixed later.
self._new(name, 0) | 510,950 |
A method to update the extent location for this Path Table Record.
Parameters:
extent_loc - The new extent location.
Returns:
Nothing. | def update_extent_location(self, extent_loc):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Path Table Record not yet initialized')
self.extent_location = extent_loc | 510,951 |
A method to update the parent directory number for this Path Table
Record from the directory record.
Parameters:
parent_dir_num - The new parent directory number to assign to this PTR.
Returns:
Nothing. | def update_parent_directory_number(self, parent_dir_num):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Path Table Record not yet initialized')
self.parent_directory_num = parent_dir_num | 510,952 |
A method to compare a little-endian path table record to its
big-endian counterpart. This is used to ensure that the ISO is sane.
Parameters:
be_record - The big-endian object to compare with the little-endian
object.
Returns:
True if this record is equal... | def equal_to_be(self, be_record):
# type: (PathTableRecord) -> bool
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('This Path Table Record is not yet initialized')
if be_record.len_di != self.len_di or \
be_record.xattr_length != self.xattr... | 510,953 |
A utility function to copy data from the input file object to the output
file object. This function will use the most efficient copy method available,
which is often sendfile.
Parameters:
data_length - The amount of data to copy.
blocksize - How much data to copy per iteration.
infp - The f... | def copy_data(data_length, blocksize, infp, outfp):
# type: (int, int, BinaryIO, BinaryIO) -> None
use_sendfile = False
if have_sendfile:
# Python 3 implements the fileno method for all file-like objects, so
# we can't just use the existence of the method to tell whether it is
#... | 510,954 |
A function to pad out an input string with spaces to the length specified.
The space is first encoded into the specified encoding, then appended to
the input string until the length is reached.
Parameters:
instr - The input string to encode and pad.
length - The length to pad the input string to.... | def encode_space_pad(instr, length, encoding):
# type: (bytes, int, str) -> bytes
output = instr.decode('utf-8').encode(encoding)
if len(output) > length:
raise pycdlibexception.PyCdlibInvalidInput('Input string too long!')
encoded_space = ' '.encode(encoding)
left = length - len(outp... | 510,955 |
A method to normalize the path, eliminating double slashes, etc. This
method is a copy of the built-in python normpath, except we do *not* allow
double slashes at the start.
Parameters:
path - The path to normalize.
Returns:
The normalized path. | def normpath(path):
# type: (str) -> bytes
sep = '/'
empty = ''
dot = '.'
dotdot = '..'
if path == empty:
return dot.encode('utf-8')
initial_slashes = path.startswith(sep)
comps = path.split(sep)
new_comps = [] # type: List[str]
for comp in comps:
if comp ... | 510,956 |
A function to compute the GMT offset from the time in seconds since the epoch
and the local time object.
Parameters:
tm - The time in seconds since the epoch.
local - The struct_time object representing the local time.
Returns:
The gmtoffset. | def gmtoffset_from_tm(tm, local):
# type: (float, time.struct_time) -> int
gmtime = time.gmtime(tm)
tmpyear = gmtime.tm_year - local.tm_year
tmpyday = gmtime.tm_yday - local.tm_yday
tmphour = gmtime.tm_hour - local.tm_hour
tmpmin = gmtime.tm_min - local.tm_min
if tmpyday < 0:
t... | 510,957 |
A function to write padding out from data_size up to pad_size
efficiently.
Parameters:
fp - The file object to use to write padding out to.
data_size - The current size of the data.
pad_size - The boundary size of data to pad out to.
Returns:
Nothing. | def zero_pad(fp, data_size, pad_size):
# type: (BinaryIO, int, int) -> None
padbytes = pad_size - (data_size % pad_size)
if padbytes == pad_size:
# Nothing to pad, get out.
return
fp.seek(padbytes - 1, os.SEEK_CUR)
fp.write(b'\x00') | 510,958 |
A function to check whether a file-like object supports binary mode.
Parameters:
fp - The file-like object to check for binary mode support.
Returns:
True if the file-like object supports binary mode, False otherwise. | def file_object_supports_binary(fp):
# type: (BinaryIO) -> bool
if hasattr(fp, 'mode'):
return 'b' in fp.mode
# Python 3
if sys.version_info >= (3, 0):
return isinstance(fp, (io.RawIOBase, io.BufferedIOBase))
# Python 2
return isinstance(fp, (cStringIO.OutputType, cStringI... | 510,959 |
A method to parse ISO hybridization info out of an existing ISO.
Parameters:
instr - The data for the ISO hybridization.
Returns:
Nothing. | def parse(self, instr):
# type: (bytes) -> bool
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized')
if len(instr) != 512:
raise pycdlibexception.PyCdlibInvalidISO('Invalid size of the instr')
... | 510,960 |
A method to calculate the 'cc' and the 'padding' values for this
hybridization.
Parameters:
iso_size - The size of the ISO, excluding the hybridization.
Returns:
A tuple containing the cc value and the padding. | def _calc_cc(self, iso_size):
# type: (int) -> Tuple[int, int]
cylsize = self.geometry_heads * self.geometry_sectors * 512
frac = iso_size % cylsize
padding = 0
if frac > 0:
padding = cylsize - frac
cc = (iso_size + padding) // cylsize
if cc >... | 510,962 |
A method to generate a string containing the ISO hybridization.
Parameters:
iso_size - The size of the ISO, excluding the hybridization.
Returns:
A string containing the ISO hybridization. | def record(self, iso_size):
# type: (int) -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized')
outlist = [struct.pack('=32s400sLLLH', self.header, self.mbr, self.rba,
0,... | 510,963 |
A method to record padding for the ISO hybridization.
Parameters:
iso_size - The size of the ISO, excluding the hybridization.
Returns:
A string of zeros the right size to pad the ISO. | def record_padding(self, iso_size):
# type: (int) -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized')
return b'\x00' * self._calc_cc(iso_size)[1] | 510,964 |
A method to update the current rba for the ISO hybridization.
Parameters:
current_extent - The new extent to set the RBA to.
Returns:
Nothing. | def update_rba(self, current_extent):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized')
self.rba = current_extent | 510,965 |
Parse an Extended Attribute Record out of a string.
Parameters:
xastr - The string to parse.
Returns:
Nothing. | def parse(self, xastr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized!')
(self._group_id, self._user_id, self._attributes, signature, self._filenum,
unused) = struct.unpack_from(self.... | 510,966 |
Create a new Extended Attribute Record.
Parameters:
None.
Returns:
Nothing. | def new(self):
# type: () -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized!')
# FIXME: we should allow the user to set these
self._group_id = 0
self._user_id = 0
self._attributes = 0
... | 510,967 |
Record this Extended Attribute Record.
Parameters:
None.
Returns:
A string representing this Extended Attribute Record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('This XARecord is not yet initialized!')
return struct.pack(self.FMT, self._group_id, self._user_id,
self._attributes, b'XA', self._filenum... | 510,968 |
Parse a directory record out of a string.
Parameters:
vd - The Volume Descriptor this record is part of.
record - The string to parse for this record.
parent - The parent of this record.
Returns:
The Rock Ridge version as a string if this Directory Record has Rock
... | def parse(self, vd, record, parent):
# type: (headervd.PrimaryOrSupplementaryVD, bytes, Optional[DirectoryRecord]) -> str
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized')
if len(record) > 255:
# Since the ... | 510,970 |
Create a new root Directory Record.
Parameters:
vd - The Volume Descriptor this record is part of.
seqnum - The sequence number for this directory record.
log_block_size - The logical block size to use.
Returns:
Nothing. | def new_root(self, vd, seqnum, log_block_size):
# type: (headervd.PrimaryOrSupplementaryVD, int, int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized')
self._new(vd, b'\x00', None, seqnum, True, log_block_size,... | 510,975 |
Change the ISO9660 existence flag of this Directory Record.
Parameters:
is_hidden - True if this Directory Record should be hidden, False otherwise.
Returns:
Nothing. | def change_existence(self, is_hidden):
# type: (bool) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
if is_hidden:
self.file_flags |= (1 << self.FILE_FLAG_EXISTENCE_BIT)
else:
... | 510,979 |
Internal method to recalculate the extents and offsets associated with
children of this directory record.
Parameters:
index - The index at which to start the recalculation.
logical_block_size - The block size to use for comparisons.
Returns:
A tuple where the first el... | def _recalculate_extents_and_offsets(self, index, logical_block_size):
# type: (int, int) -> Tuple[int, int]
if index == 0:
dirrecord_offset = 0
num_extents = 1
else:
dirrecord_offset = self.children[index - 1].offset_to_here
num_extents =... | 510,980 |
A method to track an existing child of this directory record.
Parameters:
child - The child directory record object to add.
logical_block_size - The size of a logical block for this volume descriptor.
allow_duplicate - Whether to allow duplicate names, as there are
... | def track_child(self, child, logical_block_size, allow_duplicate=False):
# type: (DirectoryRecord, int, bool) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
self._add_child(child, logical_block_size, all... | 510,983 |
A method to remove a child from this Directory Record.
Parameters:
child - The child DirectoryRecord object to remove.
index - The index of the child into this DirectoryRecord children list.
logical_block_size - The size of a logical block on this volume descriptor.
Returns:
... | def remove_child(self, child, index, logical_block_size):
# type: (DirectoryRecord, int, int) -> bool
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
if index < 0:
# This should never happen
... | 510,984 |
A method to generate the string representing this Directory Record.
Parameters:
None.
Returns:
String representing this Directory Record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
# Ecma-119 9.1.5 says the date should reflect the time when the
# record was written, so we make a new date now and us... | 510,985 |
A method to determine whether this file is 'associated' with another file
on the ISO.
Parameters:
None.
Returns:
True if this file is associated with another file on the ISO, False
otherwise. | def is_associated_file(self):
# type: () -> bool
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
return self.file_flags & (1 << self.FILE_FLAG_ASSOCIATED_FILE_BIT) | 510,986 |
A method to set the Path Table Record associated with this Directory
Record.
Parameters:
ptr - The path table record to associate with this Directory Record.
Returns:
Nothing. | def set_ptr(self, ptr):
# type: (path_table_record.PathTableRecord) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
self.ptr = ptr | 510,987 |
A method to set the new extent location that the data for this Directory
Record should live at.
Parameters:
current_extent - The new extent.
Returns:
Nothing. | def set_data_location(self, current_extent, tag_location): # pylint: disable=unused-argument
# type: (int, int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
self.new_extent_loc = current_extent
... | 510,988 |
A method to get the length of the data that this Directory Record
points to.
Parameters:
None.
Returns:
The length of the data that this Directory Record points to. | def get_data_length(self):
# type: () -> int
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
if self.inode is not None:
return self.inode.get_data_length()
return self.data_length | 510,989 |
A method to set the length of the data that this Directory Record
points to.
Parameters:
length - The new length for the data.
Returns:
The length of the data that this Directory Record points to. | def set_data_length(self, length):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')
self.data_length = length | 510,990 |
Initialize a new Inode.
Parameters:
None.
Returns:
Nothing. | def new(self, length, fp, manage_fp, offset):
# type: (int, BinaryIO, bool, int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Inode is already initialized')
self.data_length = length
self.data_fp = fp
self.manage_fp = manage_fp... | 510,994 |
Parse an existing Inode. This just saves off the extent for later use.
Parameters:
extent - The original extent that the data lives at.
Returns:
Nothing. | def parse(self, extent, length, fp, log_block_size):
# type: (int, int, BinaryIO, int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Inode is already initialized')
self.orig_extent_loc = extent
self.data_length = length
self.da... | 510,995 |
A method to add a boot info table to this Inode.
Parameters:
boot_info_table - The Boot Info Table object to add to this Inode.
Returns:
Nothing. | def add_boot_info_table(self, boot_info_table):
# type: (eltorito.EltoritoBootInfoTable) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized')
self.boot_info_table = boot_info_table | 510,996 |
Update the Inode to use a different file object and length.
Parameters:
fp - A file object that contains the data for this Inode.
length - The length of the data.
Returns:
Nothing. | def update_fp(self, fp, length):
# type: (BinaryIO, int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized')
self.original_data_location = self.DATA_IN_EXTERNAL_FP
self.data_fp = fp
self.data_length =... | 510,997 |
A cacheable function to take an input string and decode it into a
time.struct_time from the time module. If the string cannot be decoded
because of an illegal value, then the all-zero time.struct_time will be
returned instead.
Parameters:
input_string - The string to attempt to parse.
Returns... | def string_to_timestruct(input_string):
# type: (bytes) -> time.struct_time
try:
timestruct = time.strptime(input_string.decode('utf-8'), VolumeDescriptorDate.TIME_FMT)
except ValueError:
# Ecma-119, 8.4.26.1 specifies that if the string was all the digit
# zero, with the last b... | 511,000 |
Parse a Directory Record date out of a string.
Parameters:
datestr - The string to parse the date out of.
Returns:
Nothing. | def parse(self, datestr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized')
(self.years_since_1900, self.month, self.day_of_month, self.hour,
self.minute, self.second,
sel... | 511,001 |
Create a new Directory Record date based on the current time.
Parameters:
tm - An optional argument that must be None
Returns:
Nothing. | def new(self):
# type: () -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized')
# This algorithm was ported from cdrkit, genisoimage.c:iso9660_date()
tm = time.time()
local = time.localtime(tm)... | 511,002 |
Return a string representation of the Directory Record date.
Parameters:
None.
Returns:
A string representing this Directory Record Date. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record Date not initialized')
return struct.pack(self.FMT, self.years_since_1900, self.month,
self.day_of_month, self.hour, self... | 511,003 |
Parse a Volume Descriptor Date out of a string. A string of all zeros
is valid, which means that the date in this field was not specified.
Parameters:
datestr - string to be parsed
Returns:
Nothing. | def parse(self, datestr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This Volume Descriptor Date object is already initialized')
if len(datestr) != 17:
raise pycdlibexception.PyCdlibInvalidISO('Invalid ISO9660 date... | 511,005 |
Parse a Rock Ridge Sharing Protocol record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
Nothing. | def parse(self, rrstr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('SP record already initialized!')
(su_len, su_entry_version_unused, check_byte1, check_byte2,
self.bytes_to_skip) = struct.unpack_from('=BBBBB', rrstr[... | 511,009 |
Create a new Rock Ridge Sharing Protocol record.
Parameters:
bytes_to_skip - The number of bytes to skip.
Returns:
Nothing. | def new(self, bytes_to_skip):
# type: (int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('SP record already initialized!')
self.bytes_to_skip = bytes_to_skip
self._initialized = True | 511,010 |
Generate a string representing the Rock Ridge Sharing Protocol record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SP record not yet initialized!')
return b'SP' + struct.pack('=BBBBB', RRSPRecord.length(), SU_ENTRY_VERSION, 0xbe, 0xef, self.bytes_to_skip) | 511,011 |
Create a new Rock Ridge Rock Ridge record.
Parameters:
None.
Returns:
Nothing. | def new(self):
# type: () -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('RR record already initialized!')
self.rr_flags = 0
self._initialized = True | 511,012 |
Mark a field as present in the Rock Ridge records.
Parameters:
fieldname - The name of the field to mark as present; should be one
of 'PX', 'PN', 'SL', 'NM', 'CL', 'PL', 'RE', or 'TF'.
Returns:
Nothing. | def append_field(self, fieldname):
# type: (str) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('RR record not yet initialized!')
if fieldname == 'PX':
bit = 0
elif fieldname == 'PN':
bit = 1
elif fieldn... | 511,013 |
Generate a string representing the Rock Ridge Rock Ridge record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('RR record not yet initialized!')
return b'RR' + struct.pack('=BBB', RRRRRecord.length(), SU_ENTRY_VERSION, self.rr_flags) | 511,014 |
Parse a Rock Ridge Continuation Entry record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
Nothing. | def parse(self, rrstr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('CE record already initialized!')
(su_len, su_entry_version_unused, bl_cont_area_le, bl_cont_area_be,
offset_cont_area_le, offset_cont_area_be,
... | 511,015 |
Create a new Rock Ridge Continuation Entry record.
Parameters:
None.
Returns:
Nothing. | def new(self):
# type: () -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('CE record already initialized!')
self.bl_cont_area = 0 # This will get set during reshuffle_extents
self.offset_cont_area = 0 # This will get set during reshuffle_... | 511,016 |
Update the extent for this CE record.
Parameters:
extent - The new extent for this CE record.
Returns:
Nothing. | def update_extent(self, extent):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!')
self.bl_cont_area = extent | 511,017 |
Update the offset for this CE record.
Parameters:
extent - The new offset for this CE record.
Returns:
Nothing. | def update_offset(self, offset):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!')
self.offset_cont_area = offset | 511,018 |
Add some more length to this CE record. Used when a new record is going
to get recorded into the CE (rather than the DR).
Parameters:
length - The length to add to this CE record.
Returns:
Nothing. | def add_record(self, length):
# type: (int) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!')
self.len_cont_area += length | 511,019 |
Generate a string representing the Rock Ridge Continuation Entry record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!')
return b'CE' + struct.pack('=BBLLLLLL',
RRCERecord.length(),
S... | 511,020 |
Parse a Rock Ridge POSIX File Attributes record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
A string representing the RR version, either 1.09 or 1.12. | def parse(self, rrstr):
# type: (bytes) -> int
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('PX record already initialized!')
(su_len, su_entry_version_unused, posix_file_mode_le, posix_file_mode_be,
posix_file_links_le, posix_file_links_be, po... | 511,022 |
Create a new Rock Ridge POSIX File Attributes record.
Parameters:
mode - The Unix file mode for this record.
Returns:
Nothing. | def new(self, mode):
# type: (int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('PX record already initialized!')
self.posix_file_mode = mode
self.posix_file_links = 1
self.posix_user_id = 0
self.posix_group_id = 0
... | 511,023 |
Generate a string representing the Rock Ridge POSIX File Attributes
record.
Parameters:
rr_version - The Rock Ridge version to use.
Returns:
String containing the Rock Ridge record. | def record(self, rr_version):
# type: (str) -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('PX record not yet initialized!')
outlist = [b'PX', struct.pack('=BBLLLLLLLL', RRPXRecord.length(rr_version),
SU_... | 511,024 |
Parse a Rock Ridge Extensions Reference record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
Nothing. | def parse(self, rrstr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('ER record already initialized!')
(su_len, su_entry_version_unused, len_id, len_des, len_src,
self.ext_ver) = struct.unpack_from('=BBBBBB', rrstr[:8], ... | 511,026 |
Create a new Rock Ridge Extensions Reference record.
Parameters:
ext_id - The extension identifier to use.
ext_des - The extension descriptor to use.
ext_src - The extension specification source to use.
Returns:
Nothing. | def new(self, ext_id, ext_des, ext_src):
# type: (bytes, bytes, bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('ER record already initialized!')
self.ext_id = ext_id
self.ext_des = ext_des
self.ext_src = ext_src
self... | 511,027 |
Generate a string representing the Rock Ridge Extensions Reference
record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('ER record not yet initialized!')
return b'ER' + struct.pack('=BBBBBB', RRERRecord.length(self.ext_id, self.ext_des, self.ext_src), SU_ENTRY_VERSION, len(self.ext_id)... | 511,028 |
Static method to return the length of the Rock Ridge Extensions Reference
record.
Parameters:
ext_id - The extension identifier to use.
ext_des - The extension descriptor to use.
ext_src - The extension specification source to use.
Returns:
The length of this... | def length(ext_id, ext_des, ext_src):
# type: (bytes, bytes, bytes) -> int
return 8 + len(ext_id) + len(ext_des) + len(ext_src) | 511,029 |
Create a new Rock Ridge Extension Selector record.
Parameters:
extension_sequence - The sequence number of this extension.
Returns:
Nothing. | def new(self, extension_sequence):
# type: (int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('ES record already initialized!')
self.extension_sequence = extension_sequence
self._initialized = True | 511,030 |
Generate a string representing the Rock Ridge Extension Selector record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('ES record not yet initialized!')
return b'ES' + struct.pack('=BBB', RRESRecord.length(), SU_ENTRY_VERSION, self.extension_sequence) | 511,031 |
Parse a Rock Ridge POSIX Device Number record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
Nothing. | def parse(self, rrstr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('PN record already initialized!')
(su_len, su_entry_version_unused, dev_t_high_le, dev_t_high_be,
dev_t_low_le, dev_t_low_be) = struct.unpack_from('=BB... | 511,032 |
Create a new Rock Ridge POSIX device number record.
Parameters:
dev_t_high - The high-order 32-bits of the device number.
dev_t_low - The low-order 32-bits of the device number.
Returns:
Nothing. | def new(self, dev_t_high, dev_t_low):
# type: (int, int) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('PN record already initialized!')
self.dev_t_high = dev_t_high
self.dev_t_low = dev_t_low
self._initialized = True | 511,033 |
Generate a string representing the Rock Ridge POSIX Device Number
record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('PN record not yet initialized!')
return b'PN' + struct.pack('=BBLLLL', RRPNRecord.length(), SU_ENTRY_VERSION, self.dev_t_high, utils.swab_32bit(self.dev_t_high), sel... | 511,034 |
Parse a Rock Ridge Symbolic Link record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
Nothing. | def parse(self, rrstr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record already initialized!')
(su_len, su_entry_version_unused, self.flags) = struct.unpack_from('=BBB', rrstr[:5], 2)
# We assume that the caller ... | 511,035 |
Add a new component to this symlink record.
Parameters:
symlink_comp - The string to add to this symlink record.
Returns:
Nothing. | def add_component(self, symlink_comp):
# type: (bytes) -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!')
if (self.current_length() + RRSLRecord.Component.length(symlink_comp)) > 255:
raise pycdlibexce... | 511,036 |
Calculate the current length of this symlink record.
Parameters:
None.
Returns:
Length of this symlink record. | def current_length(self):
# type: () -> int
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!')
strlist = []
for comp in self.symlink_components:
strlist.append(comp.name())
return RRSLRecord.l... | 511,037 |
Generate a string representing the Rock Ridge Symbolic Link record.
Parameters:
None.
Returns:
String containing the Rock Ridge record. | def record(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!')
outlist = [b'SL', struct.pack('=BBB', self.current_length(), SU_ENTRY_VERSION, self.flags)]
for comp in self.symlink_compone... | 511,038 |
Generate a string that contains all components of the symlink.
Parameters:
None
Returns:
String containing all components of the symlink. | def name(self):
# type: () -> bytes
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!')
outlist = [] # type: List[bytes]
continued = False
for comp in self.symlink_components:
name = comp.name(... | 511,039 |
Set the previous component of this SL record to continued.
Parameters:
None.
Returns:
Nothing. | def set_last_component_continued(self):
# type: () -> None
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!')
if not self.symlink_components:
raise pycdlibexception.PyCdlibInternalError('Trying to set continue... | 511,040 |
Determines whether the previous component of this SL record is a
continued one or not.
Parameters:
None.
Returns:
True if the previous component of this SL record is continued, False otherwise. | def last_component_continued(self):
# type: () -> bool
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!')
if not self.symlink_components:
raise pycdlibexception.PyCdlibInternalError('Trying to get continued on... | 511,041 |
Static method to return the length of the Rock Ridge Symbolic Link
record.
Parameters:
symlink_components - A list containing a string for each of the
symbolic link components.
Returns:
The length of this record in bytes. | def length(symlink_components):
# type: (List[bytes]) -> int
length = RRSLRecord.header_length()
for comp in symlink_components:
length += RRSLRecord.Component.length(comp)
return length | 511,042 |
Parse a Rock Ridge Alternate Name record out of a string.
Parameters:
rrstr - The string to parse the record out of.
Returns:
Nothing. | def parse(self, rrstr):
# type: (bytes) -> None
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('NM record already initialized!')
(su_len, su_entry_version_unused, self.posix_name_flags) = struct.unpack_from('=BBB', rrstr[:5], 2)
# We assume that ... | 511,044 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.