_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q14500 | AWSAuth.get_token | train | def get_token(self):
"""Returns a client token from Cerberus"""
signed_headers = self._get_v4_signed_headers()
for header in self.HEADERS:
signed_headers[header] = self.HEADERS[header]
resp = post_with_retry(self.cerberus_url + '/v2/auth/sts-identity', headers=signed_headers)
throw_if_bad_response(resp)
token = resp.json()['client_token']
iam_principal_arn = resp.json()['metadata']['aws_iam_principal_arn']
| python | {
"resource": ""
} |
q14501 | tiff_header | train | def tiff_header(read_buffer):
"""
Interpret the uuid raw data as a tiff header.
"""
# First 8 should be (73, 73, 42, 8) or (77, 77, 42, 8)
data = struct.unpack('BB', read_buffer[0:2])
if data[0] == 73 and data[1] == 73:
# little endian
endian = '<'
elif data[0] == 77 and data[1] == 77:
# big endian
endian = '>'
else:
msg = ("The byte order indication in the TIFF header ({byte_order}) "
"is invalid. It should be either {little_endian} or "
"{big_endian}.")
msg = msg.format(byte_order=read_buffer[6:8], | python | {
"resource": ""
} |
q14502 | Ifd.parse_tag | train | def parse_tag(self, dtype, count, offset_buf):
"""Interpret an Exif image tag data payload.
"""
try:
fmt = self.datatype2fmt[dtype][0] * count
payload_size = self.datatype2fmt[dtype][1] * count
except KeyError:
msg = 'Invalid TIFF tag datatype ({0}).'.format(dtype)
raise IOError(msg)
if payload_size <= 4:
# Interpret the payload from the 4 bytes in the tag entry.
target_buffer = offset_buf[:payload_size]
else:
# Interpret the payload at the offset specified by the 4 bytes in
# the tag entry.
offset, = struct.unpack(self.endian + 'I', offset_buf)
target_buffer = self.read_buffer[offset:offset + payload_size]
if dtype == 2:
# ASCII
payload = target_buffer.decode('utf-8').rstrip('\x00')
else:
payload = struct.unpack(self.endian + fmt, target_buffer)
if dtype == 5 or dtype == 10:
| python | {
"resource": ""
} |
q14503 | Ifd.post_process | train | def post_process(self, tagnum2name):
"""Map the tag name instead of tag number to the tag value.
"""
for tag, value in self.raw_ifd.items():
try:
tag_name = tagnum2name[tag]
except KeyError:
# Ok, we don't recognize this | python | {
"resource": ""
} |
q14504 | SavedQueriesInterface.all | train | def all(self):
"""
Gets all saved queries for a project from the Keen IO API.
Master key must be set.
"""
| python | {
"resource": ""
} |
q14505 | SavedQueriesInterface.get | train | def get(self, query_name):
"""
Gets a single saved query for a project from the Keen IO API given a
query name.
Master key must be set.
"""
| python | {
"resource": ""
} |
q14506 | SavedQueriesInterface.results | train | def results(self, query_name):
"""
Gets a single saved query with a 'result' object for a project from the
Keen IO API given a query name.
Read or Master key must be set.
"""
url = | python | {
"resource": ""
} |
q14507 | SavedQueriesInterface.create | train | def create(self, query_name, saved_query):
"""
Creates the saved query via a PUT request to Keen IO Saved Query endpoint.
Master key must be set.
"""
url = "{0}/{1}".format(self.saved_query_url, query_name)
payload = saved_query
# To support clients that may have already called dumps() to work around how this used to
# work, make sure it's not a str. Hopefully it's some sort of mapping. When we actually
| python | {
"resource": ""
} |
q14508 | SavedQueriesInterface.delete | train | def delete(self, query_name):
"""
Deletes a saved query from a project with a query name.
Master key must be set.
"""
| python | {
"resource": ""
} |
q14509 | UserAuth.get_auth | train | def get_auth(self):
"""Returns auth response which has client token unless MFA is required"""
auth_resp = get_with_retry(self.cerberus_url + '/v2/auth/user',
| python | {
"resource": ""
} |
q14510 | UserAuth.get_token | train | def get_token(self):
"""sets client token from Cerberus"""
auth_resp = self.get_auth()
if auth_resp['status'] == 'mfa_req':
token_resp = self.get_mfa(auth_resp)
else:
| python | {
"resource": ""
} |
q14511 | UserAuth.get_mfa | train | def get_mfa(self, auth_resp):
"""Gets MFA code from user and returns response which includes the client token"""
devices = auth_resp['data']['devices']
if len(devices) == 1:
# If there's only one option, don't show selection prompt
selection = "0"
x = 1
else:
print("Found the following MFA devices")
x=0
for device in devices:
print("{0}: {1}".format(x, device['name']))
x = x + 1
selection = input("Enter a selection: ")
if selection.isdigit():
selection_num=int(str(selection))
else:
raise CerberusClientException( str.join('', ["Selection: '", selection,"' is not a number"]))
if (selection_num >= x) or (selection_num < 0):
| python | {
"resource": ""
} |
q14512 | _parse_standard_flag | train | def _parse_standard_flag(read_buffer, mask_length):
"""Construct standard flag, standard mask data from the file.
Specifically working on Reader Requirements box.
Parameters
----------
fptr : file object
File object for JP2K file.
mask_length : int
Length of standard mask flag
"""
# The mask length tells us the format string to use when unpacking
# from the | python | {
"resource": ""
} |
q14513 | _parse_vendor_features | train | def _parse_vendor_features(read_buffer, mask_length):
"""Construct vendor features, vendor mask data from the file.
Specifically working on Reader Requirements box.
Parameters
----------
fptr : file object
File object for JP2K file.
mask_length : int
Length of vendor mask flag
"""
# The mask length tells us the format string to use when unpacking
# from the buffer read from file.
mask_format = {1: 'B', 2: 'H', 4: 'I'}[mask_length]
num_vendor_features, = struct.unpack_from('>H', read_buffer)
# Each vendor feature consists of a 16-byte UUID plus a mask whose
# length is specified by, you guessed it, "mask_length".
entry_length = 16 + mask_length
vendor_feature = []
vendor_mask = []
| python | {
"resource": ""
} |
q14514 | Jp2kBox._dispatch_validation_error | train | def _dispatch_validation_error(self, msg, writing=False):
"""Issue either a warning or an error depending on circumstance.
If writing to file, then error | python | {
"resource": ""
} |
q14515 | Jp2kBox._indent | train | def _indent(self, textstr, indent_level=4):
"""
Indent a string.
Textwrap's indent method only exists for 3.3 or above. In 2.7 we have
to fake it.
Parameters
----------
textstring : str
String to be indented.
indent_level : str
Number of spaces of indentation to add.
Returns
-------
str
Possibly multi-line string indented by the specified amount.
| python | {
"resource": ""
} |
q14516 | Jp2kBox._write_superbox | train | def _write_superbox(self, fptr, box_id):
"""Write a superbox.
Parameters
----------
fptr : file or file object
Superbox (box of boxes) to be written to this file.
box_id : bytes
4-byte sequence that identifies the superbox.
"""
# Write the contained boxes, then come back and write the length.
| python | {
"resource": ""
} |
q14517 | Jp2kBox._parse_this_box | train | def _parse_this_box(self, fptr, box_id, start, num_bytes):
"""Parse the current box.
Parameters
----------
fptr : file
Open file object, currently points to start of box payload, not the
start of the box.
box_id : str
4-letter identifier for the current box.
start, num_bytes : int
Byte offset and length of the current box.
Returns
-------
Jp2kBox
Object corresponding to the current box.
"""
try:
parser = _BOX_WITH_ID[box_id].parse
except KeyError:
# We don't recognize the box ID, so create an UnknownBox and be
# done with it.
msg = ('Unrecognized box ({box_id}) encountered at byte offset '
'{offset}.')
msg = msg.format(box_id=box_id, offset=fptr.tell() - 8)
warnings.warn(msg, UserWarning)
box = UnknownBox(box_id, offset=start, length=num_bytes,
longname='Unknown')
return box
| python | {
"resource": ""
} |
q14518 | Jp2kBox.parse_superbox | train | def parse_superbox(self, fptr):
"""Parse a superbox (box consisting of nothing but other boxes.
Parameters
----------
fptr : file
Open file object.
Returns
-------
list
List of top-level boxes in the JPEG 2000 file.
"""
superbox = []
start = fptr.tell()
while True:
# Are we at the end of the superbox?
if start >= self.offset + self.length:
break
read_buffer = fptr.read(8)
if len(read_buffer) < 8:
msg = "Extra bytes at end of file ignored."
warnings.warn(msg, UserWarning)
return superbox
(box_length, box_id) = struct.unpack('>I4s', read_buffer)
if box_length == 0:
# The length of the box is presumed to last until the end of
# the file. Compute the effective length of the box.
num_bytes = os.path.getsize(fptr.name) - fptr.tell() + 8
elif box_length == 1:
# The length of the box is in the XL field, a 64-bit value.
read_buffer = fptr.read(8)
num_bytes, = struct.unpack('>Q', read_buffer)
else:
# The box_length value really is the length of the box!
num_bytes = box_length
box = self._parse_this_box(fptr, box_id, start, num_bytes)
superbox.append(box)
# Position to the start of the next box.
if num_bytes > self.length:
# Length of the current box goes past the end of the
# enclosing superbox.
| python | {
"resource": ""
} |
q14519 | ColourSpecificationBox._write_validate | train | def _write_validate(self):
"""In addition to constructor validation steps, run validation steps
for writing."""
if self.colorspace is None:
msg = ("Writing colr boxes without enumerated "
"colorspaces is not supported at this time.")
| python | {
"resource": ""
} |
q14520 | ColourSpecificationBox.write | train | def write(self, fptr):
"""Write an Colour Specification box to file.
"""
self._write_validate()
length = 15 if self.icc_profile is None else 11 + len(self.icc_profile)
fptr.write(struct.pack('>I4s', length, b'colr'))
read_buffer = struct.pack('>BBBI',
self.method,
| python | {
"resource": ""
} |
q14521 | ColourSpecificationBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse JPEG 2000 color specification box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
ColourSpecificationBox
Instance of the current colour specification box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
lst = struct.unpack_from('>BBB', read_buffer, offset=0)
method, precedence, approximation = lst
if method == 1:
# enumerated colour space
colorspace, = struct.unpack_from('>I', read_buffer, offset=3)
if colorspace not in _COLORSPACE_MAP_DISPLAY.keys():
msg = "Unrecognized colorspace ({colorspace})."
msg = msg.format(colorspace=colorspace)
warnings.warn(msg, UserWarning)
icc_profile = None
else:
# ICC profile
colorspace = None
| python | {
"resource": ""
} |
q14522 | ChannelDefinitionBox.write | train | def write(self, fptr):
"""Write a channel definition box to file.
"""
self._validate(writing=True)
num_components = len(self.association)
fptr.write(struct.pack('>I4s', 8 + 2 + num_components * 6, b'cdef'))
fptr.write(struct.pack('>H', num_components))
for j in range(num_components):
| python | {
"resource": ""
} |
q14523 | ChannelDefinitionBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse component definition box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
ComponentDefinitionBox
Instance of the current component definition box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
# Read the number of components.
num_components, = struct.unpack_from('>H', read_buffer)
data = struct.unpack_from('>' + 'HHH' * num_components, read_buffer,
| python | {
"resource": ""
} |
q14524 | ColourGroupBox.write | train | def write(self, fptr):
"""Write a colour group box to file.
| python | {
"resource": ""
} |
q14525 | ComponentMappingBox.write | train | def write(self, fptr):
"""Write a Component Mapping box to file.
"""
length = 8 + 4 * len(self.component_index)
write_buffer = struct.pack('>I4s', length, b'cmap')
fptr.write(write_buffer)
| python | {
"resource": ""
} |
q14526 | ComponentMappingBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse component mapping box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
ComponentMappingBox
Instance of the current component mapping box.
"""
num_bytes = offset + length - fptr.tell()
num_components = int(num_bytes / 4)
read_buffer = fptr.read(num_bytes)
| python | {
"resource": ""
} |
q14527 | ContiguousCodestreamBox.parse | train | def parse(cls, fptr, offset=0, length=0):
"""Parse a codestream box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
ContiguousCodestreamBox
| python | {
"resource": ""
} |
q14528 | DataReferenceBox.write | train | def write(self, fptr):
"""Write a Data Reference box to file.
"""
self._write_validate()
# Very similar to the way a superbox is written.
orig_pos = fptr.tell()
fptr.write(struct.pack('>I4s', 0, b'dtbl'))
# Write the number of data entry url boxes.
write_buffer = struct.pack('>H', len(self.DR))
| python | {
"resource": ""
} |
q14529 | DataReferenceBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse data reference box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
DataReferenceBox
Instance of the current data reference box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
# Read the number of data references
ndr, = struct.unpack_from('>H', read_buffer, offset=0)
# Need to keep track of where the next url box starts.
box_offset = 2
data_entry_url_box_list = []
for j in range(ndr):
# Create an in-memory binary stream for each URL box.
box_fptr = io.BytesIO(read_buffer[box_offset:])
box_buffer = box_fptr.read(8)
(box_length, box_id) = struct.unpack_from('>I4s', box_buffer,
| python | {
"resource": ""
} |
q14530 | FileTypeBox._validate | train | def _validate(self, writing=False):
"""
Validate the box before writing to file.
"""
if self.brand not in ['jp2 ', 'jpx ']:
msg = ("The file type brand was '{brand}'. "
"It should be either 'jp2 ' or 'jpx '.")
msg = msg.format(brand=self.brand)
if writing:
raise IOError(msg)
else:
warnings.warn(msg, UserWarning)
for item in self.compatibility_list:
if item not in self._valid_cls:
msg = ("The file type compatibility list {items} is " | python | {
"resource": ""
} |
q14531 | FileTypeBox.write | train | def write(self, fptr):
"""Write a File Type box to file.
"""
self._validate(writing=True)
length = 16 + 4 * len(self.compatibility_list)
fptr.write(struct.pack('>I4s', length, b'ftyp'))
| python | {
"resource": ""
} |
q14532 | FileTypeBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse JPEG 2000 file type box.
Parameters
----------
f : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
FileTypeBox
Instance of the current file type box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
# Extract the brand, minor version.
(brand, minor_version) = struct.unpack_from('>4sI', read_buffer, 0)
| python | {
"resource": ""
} |
q14533 | FragmentListBox._validate | train | def _validate(self, writing=False):
"""Validate internal correctness."""
if (((len(self.fragment_offset) != len(self.fragment_length)) or
(len(self.fragment_length) != len(self.data_reference)))):
msg = ("The lengths of the fragment offsets ({len_offsets}), "
"fragment lengths ({len_fragments}), and "
"data reference items ({len_drefs}) must be the same.")
msg = msg.format(len_offsets=len(self.fragment_offset),
len_fragments=len(self.fragment_length),
| python | {
"resource": ""
} |
q14534 | FragmentListBox.write | train | def write(self, fptr):
"""Write a fragment list box to file.
"""
self._validate(writing=True)
num_items = len(self.fragment_offset)
length = 8 + 2 + num_items * 14
fptr.write(struct.pack('>I4s', length, b'flst'))
fptr.write(struct.pack('>H', num_items))
for j in range(num_items):
write_buffer = struct.pack('>QIH',
| python | {
"resource": ""
} |
q14535 | FragmentTableBox._validate | train | def _validate(self, writing=False):
"""Self-validate the box before writing."""
box_ids = [box.box_id for box in self.box]
if len(box_ids) != 1 or box_ids[0] != 'flst':
| python | {
"resource": ""
} |
q14536 | FragmentTableBox.write | train | def write(self, fptr):
"""Write a fragment table box to file.
| python | {
"resource": ""
} |
q14537 | ImageHeaderBox.write | train | def write(self, fptr):
"""Write an Image Header box to file.
"""
fptr.write(struct.pack('>I4s', 22, b'ihdr'))
# signedness and bps are stored together in a single byte
bit_depth_signedness = 0x80 if self.signed else 0x00
bit_depth_signedness |= self.bits_per_component - 1
read_buffer = struct.pack('>IIHBBBB',
self.height,
self.width,
self.num_components,
| python | {
"resource": ""
} |
q14538 | ImageHeaderBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse JPEG 2000 image header box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
ImageHeaderBox
Instance of the current image header box.
"""
# Read the box information
read_buffer = fptr.read(14)
params = struct.unpack('>IIHBBBB', read_buffer)
height = params[0]
width = params[1]
num_components = params[2]
bits_per_component = (params[3] & 0x7f) + 1
signed = (params[3] & 0x80) | python | {
"resource": ""
} |
q14539 | BitsPerComponentBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse bits per component box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
BitsPerComponent
Instance of the current bits per component box.
"""
nbytes = length | python | {
"resource": ""
} |
q14540 | JP2HeaderBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse JPEG 2000 header box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
JP2HeaderBox
Instance of the current JP2 header box.
| python | {
"resource": ""
} |
q14541 | JPEG2000SignatureBox.write | train | def write(self, fptr):
"""Write a JPEG 2000 Signature box to file.
| python | {
"resource": ""
} |
q14542 | JPEG2000SignatureBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse JPEG 2000 signature box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
| python | {
"resource": ""
} |
q14543 | PaletteBox.write | train | def write(self, fptr):
"""Write a Palette box to file.
"""
self._validate(writing=True)
bytes_per_row = sum(self.bits_per_component) / 8
bytes_per_palette = bytes_per_row * self.palette.shape[0]
box_length = 8 + 3 + self.palette.shape[1] + bytes_per_palette
# Write the usual (L, T) header.
write_buffer = struct.pack('>I4s', int(box_length), b'pclr')
fptr.write(write_buffer)
# NE, NPC
write_buffer = struct.pack('>HB', self.palette.shape[0],
self.palette.shape[1])
| python | {
"resource": ""
} |
q14544 | PaletteBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse palette box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
PaletteBox
Instance of the current palette box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
nrows, ncols = struct.unpack_from('>HB', read_buffer, offset=0)
bps_signed = struct.unpack_from('>' + 'B' * ncols, read_buffer,
offset=3)
bps = [((x & 0x7f) + 1) for x in bps_signed]
signed = [((x & 0x80) > 1) for x in bps_signed]
# Are any components signed or differently sized? We don't handle
# that.
if any(signed) or len(set(bps)) != 1:
msg = ("Palettes with signed components or | python | {
"resource": ""
} |
q14545 | ReaderRequirementsBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse reader requirements box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
ReaderRequirementsBox
Instance of the current reader requirements box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
mask_length, = struct.unpack_from('>B', read_buffer, offset=0)
# Fully Understands Aspect Mask
# Decodes Completely Mask
fuam = dcm = standard_flag = standard_mask = []
vendor_feature = vendor_mask = []
# The mask length tells us the format string to use when unpacking
# from the buffer read from file.
| python | {
"resource": ""
} |
q14546 | CaptureResolutionBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse CaptureResolutionBox.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
CaptureResolutionBox
Instance of the current capture resolution box.
"""
read_buffer = fptr.read(10)
| python | {
"resource": ""
} |
q14547 | LabelBox.write | train | def write(self, fptr):
"""Write a Label box to file.
"""
length = 8 + len(self.label.encode())
| python | {
"resource": ""
} |
q14548 | LabelBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse Label box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
LabelBox
Instance of the current label box.
| python | {
"resource": ""
} |
q14549 | NumberListBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse number list box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
LabelBox
Instance of the current number list box.
"""
num_bytes = offset + | python | {
"resource": ""
} |
q14550 | NumberListBox.write | train | def write(self, fptr):
"""Write a NumberList box to file.
"""
fptr.write(struct.pack('>I4s',
len(self.associations) * 4 + 8, b'nlst'))
fmt = '>' + 'I' * | python | {
"resource": ""
} |
q14551 | XMLBox.write | train | def write(self, fptr):
"""
Write an XML box to file.
"""
read_buffer = ET.tostring(self.xml.getroot(), encoding='utf-8')
| python | {
"resource": ""
} |
q14552 | XMLBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse XML box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
XMLBox
Instance of the current XML box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
if sys.hexversion < 0x03000000 and codecs.BOM_UTF8 in read_buffer:
# Python3 with utf-8 handles this just fine. Actually so does
# Python2 right here since we decode using utf-8. The real
# problem comes when __str__ is used on the XML box, and that
# is where Python2 falls short because of the ascii codec.
msg = ('A BOM (byte order marker) was detected and '
'removed from the XML contents in the box starting at byte '
'offset {offset:d}.')
msg = msg.format(offset=offset)
warnings.warn(msg, UserWarning)
read_buffer = read_buffer.replace(codecs.BOM_UTF8, b'')
| python | {
"resource": ""
} |
q14553 | UUIDListBox.write | train | def write(self, fptr):
"""Write a UUID list box to file.
"""
num_uuids = len(self.ulst)
length = 4 + 4 + 2 + num_uuids * 16
write_buffer = struct.pack('>I4sH', length, b'ulst', | python | {
"resource": ""
} |
q14554 | UUIDListBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse UUIDList box.
Parameters
----------
f : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
UUIDListBox
Instance of the current UUID list box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = fptr.read(num_bytes)
num_uuids, | python | {
"resource": ""
} |
q14555 | DataEntryURLBox.write | train | def write(self, fptr):
"""Write a data entry url box to file.
"""
# Make sure it is written out as null-terminated.
url = self.url
if self.url[-1] != chr(0):
url = url + chr(0)
url = url.encode()
length = 8 + 1 + 3 + len(url)
write_buffer = struct.pack('>I4sBBBB',
| python | {
"resource": ""
} |
q14556 | DataEntryURLBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse data entry URL box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
DataEntryURLbox
Instance of the current data entry URL box.
"""
num_bytes = offset + length - fptr.tell()
read_buffer = | python | {
"resource": ""
} |
q14557 | UUIDBox._parse_raw_data | train | def _parse_raw_data(self):
"""
Private function for parsing UUID payloads if possible.
"""
if self.uuid == _XMP_UUID:
txt = self.raw_data.decode('utf-8')
elt = ET.fromstring(txt)
self.data = ET.ElementTree(elt)
elif self.uuid == _GEOTIFF_UUID:
| python | {
"resource": ""
} |
q14558 | UUIDBox._print_geotiff | train | def _print_geotiff(self):
"""
Print geotiff information. Shamelessly ripped off from gdalinfo.py
Returns
-------
str
String representation of the degenerate geotiff.
"""
if self.data is None:
return "corrupt"
in_mem_name = '/vsimem/geo.tif'
gdal.FileFromMemBuffer(in_mem_name, self.raw_data)
gtif = gdal.Open(in_mem_name)
# Report projection
proj_ref = gtif.GetProjectionRef()
sref = osr.SpatialReference()
sref.ImportFromWkt(proj_ref)
psz_pretty_wkt = sref.ExportToPrettyWkt(False)
# report geotransform
geo_transform = gtif.GetGeoTransform(can_return_null=True)
fmt = ('Origin = ({origin_x:.15f},{origin_y:.15f})\n'
'Pixel Size = ({pixel_x:.15f},{pixel_y:.15f})')
geotransform_str = fmt.format(origin_x=geo_transform[0],
origin_y=geo_transform[3],
pixel_x=geo_transform[1],
pixel_y=geo_transform[5])
# setup projected to lat/long transform if appropriate
if proj_ref is not None and len(proj_ref) > 0:
hProj = osr.SpatialReference(proj_ref)
if hProj is not None:
hLatLong = hProj.CloneGeogCS()
if hLatLong is not None:
gdal.PushErrorHandler('CPLQuietErrorHandler')
hTransform = osr.CoordinateTransformation(hProj, hLatLong)
gdal.PopErrorHandler()
msg = 'Unable to load PROJ.4 library'
# report corners
uleft = self.GDALInfoReportCorner(gtif, hTransform, "Upper Left", 0, 0)
lleft = self.GDALInfoReportCorner(gtif, hTransform, "Lower Left",
0, gtif.RasterYSize)
uright = self.GDALInfoReportCorner(gtif, hTransform, "Upper Right",
| python | {
"resource": ""
} |
q14559 | UUIDBox.write | train | def write(self, fptr):
"""Write a UUID box to file.
"""
length = 4 + 4 + 16 + len(self.raw_data)
write_buffer = struct.pack('>I4s', length, b'uuid')
| python | {
"resource": ""
} |
q14560 | UUIDBox.parse | train | def parse(cls, fptr, offset, length):
"""Parse UUID box.
Parameters
----------
fptr : file
Open file object.
offset : int
Start position of box in bytes.
length : int
Length of the box in bytes.
Returns
-------
UUIDBox
Instance of the current UUID box.
"""
| python | {
"resource": ""
} |
q14561 | _parse_precinct_size | train | def _parse_precinct_size(spcod):
"""Compute precinct size from SPcod or SPcoc."""
spcod = np.frombuffer(spcod, dtype=np.uint8)
precinct_size = []
for item in spcod:
ep2 = (item & 0xF0) >> 4
| python | {
"resource": ""
} |
q14562 | _context_string | train | def _context_string(context):
"""Produce a string to represent the code block context"""
msg = 'Code block context:\n '
lines = ['Selective arithmetic coding bypass: {0}',
'Reset context probabilities on coding pass boundaries: {1}',
'Termination on each coding pass: {2}',
'Vertically stripe causal context: {3}',
'Predictable termination: {4}',
'Segmentation symbols: {5}']
msg += '\n | python | {
"resource": ""
} |
q14563 | parse_quantization | train | def parse_quantization(read_buffer, sqcd):
"""Tease out the quantization values.
Parameters
----------
read_buffer: sequence of bytes from the QCC and QCD segments.
Returns
------
tuple
Mantissa and exponents from quantization buffer.
"""
numbytes = len(read_buffer)
exponent = []
mantissa = []
if sqcd & 0x1f == 0: # no quantization
data = struct.unpack('>' + 'B' * numbytes, read_buffer)
for j in range(len(data)):
exponent.append(data[j] >> 3)
| python | {
"resource": ""
} |
q14564 | _print_quantization_style | train | def _print_quantization_style(sqcc):
"""Only to be used with QCC and QCD segments."""
msg = '\n Quantization style: '
if sqcc & 0x1f == 0:
msg += 'no quantization, '
elif sqcc & 0x1f == 1:
| python | {
"resource": ""
} |
q14565 | Codestream._parse_unrecognized_segment | train | def _parse_unrecognized_segment(self, fptr):
"""Looks like a valid marker, but not sure from reading the specs.
"""
msg = ("Unrecognized codestream marker 0x{marker_id:x} encountered at "
"byte offset {offset}.")
msg = msg.format(marker_id=self._marker_id, offset=fptr.tell())
warnings.warn(msg, UserWarning)
cpos = fptr.tell()
read_buffer = fptr.read(2)
next_item, = struct.unpack('>H', read_buffer)
fptr.seek(cpos)
if ((next_item & 0xff00) >> 8) == 255:
| python | {
"resource": ""
} |
q14566 | Codestream._parse_reserved_segment | train | def _parse_reserved_segment(self, fptr):
"""Parse valid marker segment, segment description is unknown.
Parameters
----------
fptr : file object
The file to parse.
Returns
-------
Segment
The current segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(2)
length, = struct.unpack('>H', read_buffer)
if length > 0:
data = | python | {
"resource": ""
} |
q14567 | Codestream._parse_tile_part_bit_stream | train | def _parse_tile_part_bit_stream(self, fptr, sod_marker, tile_length):
"""Parse the tile part bit stream for SOP, EPH marker segments."""
read_buffer = fptr.read(tile_length)
# The tile length could possibly be too large and extend past
# the end of file. We need to be a bit resilient.
count = min(tile_length, len(read_buffer))
packet = np.frombuffer(read_buffer, dtype=np.uint8, count=count)
indices = np.where(packet == 0xff)
for idx in indices[0]:
try:
if packet[idx + 1] == 0x91 and (idx < (len(packet) - 5)):
offset = sod_marker.offset + 2 + idx
length = 4
nsop = packet[(idx + 4):(idx + 6)].view('uint16')[0]
if sys.byteorder == 'little':
| python | {
"resource": ""
} |
q14568 | Codestream._parse_cme_segment | train | def _parse_cme_segment(self, fptr):
"""Parse the CME marker segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
CMESegment
The current CME segment.
"""
offset = fptr.tell() | python | {
"resource": ""
} |
q14569 | Codestream._parse_coc_segment | train | def _parse_coc_segment(self, fptr):
"""Parse the COC marker segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
COCSegment
The current COC segment.
"""
kwargs = {}
offset = fptr.tell() - 2
kwargs['offset'] = offset
read_buffer = fptr.read(2)
length, = struct.unpack('>H', read_buffer)
kwargs['length'] = length
fmt = '>B' if self._csiz <= 255 else '>H'
nbytes = 1 if self._csiz <= 255 else 2
read_buffer = fptr.read(nbytes)
| python | {
"resource": ""
} |
q14570 | Codestream._parse_cod_segment | train | def _parse_cod_segment(cls, fptr):
"""Parse the COD segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
CODSegment
The current COD segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(2)
length, = struct.unpack('>H', read_buffer)
read_buffer = fptr.read(length - 2)
lst = struct.unpack_from('>BBHBBBBBB', read_buffer, offset=0)
scod, prog, nlayers, mct, nr, xcb, ycb, cstyle, xform = lst
if len(read_buffer) > 10:
precinct_size = _parse_precinct_size(read_buffer[10:])
else:
| python | {
"resource": ""
} |
q14571 | Codestream._parse_crg_segment | train | def _parse_crg_segment(self, fptr):
"""Parse the CRG marker segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
CRGSegment
The current CRG segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(2)
| python | {
"resource": ""
} |
q14572 | Codestream._parse_plt_segment | train | def _parse_plt_segment(self, fptr):
"""Parse the PLT segment.
The packet headers are not parsed, i.e. they remain uninterpreted raw
data buffers.
Parameters
----------
fptr : file
Open file object.
Returns
-------
PLTSegment
The current PLT segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(3)
length, zplt = struct.unpack('>HB', read_buffer)
numbytes = length - 3
read_buffer = fptr.read(numbytes)
iplt = np.frombuffer(read_buffer, dtype=np.uint8)
packet_len = []
| python | {
"resource": ""
} |
q14573 | Codestream._parse_pod_segment | train | def _parse_pod_segment(self, fptr):
"""Parse the POD segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
PODSegment
The current POD segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(2)
| python | {
"resource": ""
} |
q14574 | Codestream._parse_ppm_segment | train | def _parse_ppm_segment(self, fptr):
"""Parse the PPM segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
PPMSegment
The current PPM segment.
"""
offset = fptr.tell() | python | {
"resource": ""
} |
q14575 | Codestream._parse_ppt_segment | train | def _parse_ppt_segment(self, fptr):
"""Parse the PPT segment.
The packet headers are not parsed, i.e. they remain "uninterpreted"
raw data beffers.
Parameters
----------
fptr : file object
The file to parse.
Returns
-------
PPTSegment
The current PPT segment.
"""
offset = fptr.tell() - 2
| python | {
"resource": ""
} |
q14576 | Codestream._parse_qcc_segment | train | def _parse_qcc_segment(cls, fptr):
"""Parse the QCC segment.
Parameters
----------
fptr : file object
The file to parse.
Returns
-------
QCCSegment
The current QCC segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(2)
length, = struct.unpack('>H', read_buffer)
read_buffer = fptr.read(length - 2)
fmt = '>HB' if cls._csiz > 256 else '>BB'
mantissa_exponent_offset = 3 if cls._csiz > 256 else 2
cqcc, sqcc = struct.unpack_from(fmt, read_buffer)
if cqcc >= cls._csiz:
| python | {
"resource": ""
} |
q14577 | Codestream._parse_qcd_segment | train | def _parse_qcd_segment(self, fptr):
"""Parse the QCD segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
| python | {
"resource": ""
} |
q14578 | Codestream._parse_rgn_segment | train | def _parse_rgn_segment(cls, fptr):
"""Parse the RGN segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
RGNSegment
The current RGN segment.
"""
offset = fptr.tell() - 2
| python | {
"resource": ""
} |
q14579 | Codestream._parse_sot_segment | train | def _parse_sot_segment(self, fptr):
"""Parse the SOT segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
SOTSegment
The current SOT segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(10)
data = struct.unpack('>HHIBB', read_buffer)
length = data[0]
isot = data[1]
psot = data[2]
tpsot = data[3]
tnsot = data[4]
segment = SOTsegment(isot, psot, tpsot, tnsot, length, offset)
# Need to keep easy access | python | {
"resource": ""
} |
q14580 | Codestream._parse_tlm_segment | train | def _parse_tlm_segment(self, fptr):
"""Parse the TLM segment.
Parameters
----------
fptr : file
Open file object.
Returns
-------
TLMSegment
The current TLM segment.
"""
offset = fptr.tell() - 2
read_buffer = fptr.read(2)
length, = struct.unpack('>H', read_buffer)
read_buffer = fptr.read(length - 2)
ztlm, stlm = struct.unpack_from('>BB', read_buffer)
ttlm_st = (stlm >> 4) & 0x3
ptlm_sp = (stlm >> 6) & 0x1
nbytes = length - 4
if ttlm_st == 0:
ntiles = nbytes / ((ptlm_sp + 1) * 2)
else:
ntiles = nbytes / (ttlm_st + (ptlm_sp + 1) * 2)
if ttlm_st == 0:
ttlm = None
fmt = ''
elif ttlm_st == 1:
| python | {
"resource": ""
} |
q14581 | Codestream._parse_reserved_marker | train | def _parse_reserved_marker(self, fptr):
"""Marker range between 0xff30 and 0xff39.
"""
the_id = '0x{0:x}'.format(self._marker_id)
| python | {
"resource": ""
} |
q14582 | Event.to_json | train | def to_json(self):
""" Serializes the event to JSON.
:returns: a string
"""
event_as_dict = copy.deepcopy(self.event_body)
if self.timestamp:
if "keen" in event_as_dict:
event_as_dict["keen"]["timestamp"] = self.timestamp.isoformat()
| python | {
"resource": ""
} |
q14583 | KeenClient.delete_events | train | def delete_events(self, event_collection, timeframe=None, timezone=None, filters=None):
""" Deletes events.
:param event_collection: string, the event collection from which event are being deleted
:param timeframe: string or dict, the timeframe in which the events happened
example: "previous_7_days"
| python | {
"resource": ""
} |
q14584 | KeenClient._base64_encode | train | def _base64_encode(self, string_to_encode):
""" Base64 encodes a string, with either Python 2 or 3.
:param string_to_encode: the string to encode
"""
try:
# python 2
return base64.b64encode(string_to_encode)
except TypeError:
| python | {
"resource": ""
} |
q14585 | KeenClient.select_unique | train | def select_unique(self, event_collection, target_property, timeframe=None, timezone=None, interval=None,
filters=None, group_by=None, order_by=None, max_age=None, limit=None):
""" Performs a select unique query
Returns an array of the unique values of a target property for events that meet the given criteria.
:param event_collection: string, the name of the collection to query
:param target_property: string, the name of the event property you would like use
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param filters: array of dict, contains | python | {
"resource": ""
} |
q14586 | KeenClient.funnel | train | def funnel(self, steps, timeframe=None, timezone=None, max_age=None, all_keys=False):
""" Performs a Funnel query
Returns an object containing the results for each step of the funnel.
:param steps: array of dictionaries, one for each step. example:
[{"event_collection":"signup","actor_property":"user.id"},
{"event_collection":"purchase","actor_property:"user.id"}]
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
| python | {
"resource": ""
} |
q14587 | cio_open | train | def cio_open(cinfo, src=None):
"""Wrapper for openjpeg library function opj_cio_open."""
argtypes = [ctypes.POINTER(CommonStructType), ctypes.c_char_p,
ctypes.c_int]
OPENJPEG.opj_cio_open.argtypes = argtypes
OPENJPEG.opj_cio_open.restype = ctypes.POINTER(CioType)
if src is None:
length = 0
else:
| python | {
"resource": ""
} |
q14588 | cio_close | train | def cio_close(cio):
"""Wraps openjpeg library function cio_close.
"""
| python | {
"resource": ""
} |
q14589 | cio_tell | train | def cio_tell(cio):
"""Get position in byte stream."""
OPENJPEG.cio_tell.argtypes | python | {
"resource": ""
} |
q14590 | create_compress | train | def create_compress(fmt):
"""Wrapper for openjpeg library function opj_create_compress.
Creates a J2K/JPT/JP2 compression structure.
| python | {
"resource": ""
} |
q14591 | create_decompress | train | def create_decompress(fmt):
"""Wraps openjpeg library function opj_create_decompress.
"""
OPENJPEG.opj_create_decompress.argtypes = [ctypes.c_int]
restype = ctypes.POINTER(DecompressionInfoType) | python | {
"resource": ""
} |
q14592 | decode | train | def decode(dinfo, cio):
"""Wrapper for opj_decode.
"""
argtypes = [ctypes.POINTER(DecompressionInfoType), ctypes.POINTER(CioType)]
OPENJPEG.opj_decode.argtypes = argtypes
| python | {
"resource": ""
} |
q14593 | destroy_compress | train | def destroy_compress(cinfo):
"""Wrapper for openjpeg library function opj_destroy_compress.
Release resources for a compressor handle.
"""
argtypes = [ctypes.POINTER(CompressionInfoType)]
| python | {
"resource": ""
} |
q14594 | encode | train | def encode(cinfo, cio, image):
"""Wrapper for openjpeg library function opj_encode.
Encodes an image into a JPEG-2000 codestream.
Parameters
----------
cinfo : compression handle
cio : output buffer stream
image : image to encode
"""
argtypes = [ctypes.POINTER(CompressionInfoType),
| python | {
"resource": ""
} |
q14595 | destroy_decompress | train | def destroy_decompress(dinfo):
"""Wraps openjpeg library function opj_destroy_decompress."""
| python | {
"resource": ""
} |
q14596 | image_create | train | def image_create(cmptparms, cspace):
"""Wrapper for openjpeg library function opj_image_create.
"""
lst = [ctypes.c_int, ctypes.POINTER(ImageComptParmType), ctypes.c_int]
OPENJPEG.opj_image_create.argtypes = lst
| python | {
"resource": ""
} |
q14597 | image_destroy | train | def image_destroy(image):
"""Wraps openjpeg library function opj_image_destroy."""
| python | {
"resource": ""
} |
q14598 | set_default_encoder_parameters | train | def set_default_encoder_parameters():
"""Wrapper for openjpeg library function opj_set_default_encoder_parameters.
"""
cparams = CompressionParametersType()
argtypes = [ctypes.POINTER(CompressionParametersType)]
| python | {
"resource": ""
} |
q14599 | set_default_decoder_parameters | train | def set_default_decoder_parameters(dparams_p):
"""Wrapper for opj_set_default_decoder_parameters.
"""
argtypes = [ctypes.POINTER(DecompressionParametersType)]
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.