extract attachment data

        Returns
        -------
        data : bytes
554084
def extract(self):
        
        if self.flags & v4c.FLAG_AT_EMBEDDED:
            if self.flags & v4c.FLAG_AT_COMPRESSED_EMBEDDED:
                data = decompress(self.embedded_data)
            else:
                data = self.embedded_data
            if self.flags & v4c.FLAG_AT_MD5_VALID:
                md5_worker = md5()
                md5_worker.update(data)
                md5_sum = md5_worker.digest()
                if self.md5_sum == md5_sum:
                    return data
                else:
                    message = f"ATBLOCK md5sum={self.md5_sum} and embedded data md5sum={md5_sum}"
                    logger.warning(message)
            else:
                return data
        else:
            logger.warning("external attachments not supported")
755934
def get_attachment_data(attachmentTable, sql,
                        nameField="ATT_NAME", blobField="DATA",
                        contentTypeField="CONTENT_TYPE",
                        rel_object_field="REL_OBJECTID"):
    
    if arcpyFound == False:
        raise Exception("ArcPy is required to use this function")
    ret_rows = []
    with arcpy.da.SearchCursor(attachmentTable,
                               [nameField,
                                blobField,
                                contentTypeField,
                                rel_object_field],
                               where_clause=sql) as rows:
        for row in rows:
            temp_f = os.environ['temp'] + os.sep + row[0]
            writer = open(temp_f,'wb')
            writer.write(row[1])
            writer.flush()
            writer.close()
            del writer
            ret_rows.append({
                "name" : row[0],
                "blob" : temp_f,
                "content" : row[2],
                "rel_oid" : row[3]
            })
            del row
    return ret_rows
953900
def get_file(self, index, doc_type, id=None):
        
        data = self.get(index, doc_type, id)
        return data['_name'], base64.standard_b64decode(data['content'])
144709
def extract_data(filename, num_images):
  
  print('Extracting', filename)
  with gzip.open(filename) as bytestream:
    bytestream.read(16)
    buf = bytestream.read(IMAGE_SIZE * IMAGE_SIZE * num_images)
    data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
    data = (data - (PIXEL_DEPTH / 2.0)) / PIXEL_DEPTH
    data = data.reshape(num_images, IMAGE_SIZE, IMAGE_SIZE, 1)
    return data
974272
def _get_attachments(self, id):
        """"""
        uri = '/'.join([self.base_url, self.name, id, 'Attachments']) + '/'
        return uri, {}, 'get', None, None, False
1304650
def get_attachment_size(self, attachment):
        
        fsize = 0
        file = attachment.getAttachmentFile()
        if file:
            fsize = file.get_size()
        if fsize < 1024:
            fsize = '%s b' % fsize
        else:
            fsize = '%s Kb' % (fsize / 1024)
        return fsize
147142
def get_report_data(self, report):
        
        ar = report.getAnalysisRequest()
        attachments = map(self.get_attachment_data, ar.getAttachment())
        pdf = self.get_pdf(report)
        filesize = "{} Kb".format(self.get_filesize(pdf))
        filename = "{}.pdf".format(ar.getId())

        return {
            "ar": ar,
            "attachments": attachments,
            "pdf": pdf,
            "obj": report,
            "uid": api.get_uid(report),
            "filesize": filesize,
            "filename": filename,
        }
1193845
def get_data(self) -> bytes:
        
        data = {
            "_class_name": self.__class__.__name__,
            "version": 1,
            "segments_bin": SegmentSequence([self.command_seg, self.tan_request]).render_bytes(),
            "resume_method": self.resume_method,
            "tan_request_structured": self.tan_request_structured,
        }
        return compress_datablob(DATA_BLOB_MAGIC_RETRY, 1, data)
142286
def get_body(self, msg):
        

        body = ""
        charset = ""

        if msg.is_multipart():
            for part in msg.walk():
                ctype = part.get_content_type()
                cdispo = str(part.get('Content-Disposition'))

                # skip any text/plain (txt) attachments
                if ctype == 'text/plain' and 'attachment' not in cdispo:
                    body = part.get_payload(decode=True)  # decode
                    charset = part.get_content_charset()
                    break

        # not multipart - i.e. plain text, no attachments, keeping fingers crossed
        else:
            body = msg.get_payload(decode=True)
            charset = msg.get_content_charset()

        return body.decode(charset)
633379
def content(self):
        """"""

        if not self.payload:
            return ''

        if self.payload.is_multipart():
            message_bytes = mime_to_bytes(
                self.payload, 0).replace(b'\n', b'\r\n')
            boundary = b'--' + self.payload.get_boundary().encode('utf-8')
            temp = message_bytes.split(boundary)
            temp.pop(0)
            return boundary + boundary.join(temp)
        else:
            content = self.payload.get_payload()
            if isinstance(content, str_cls):
                content = content.encode('utf-8')
            return content
1248349
def get_file(file_id: str, download):
    
    data = current_app.config["data"]  # type: DataStorage
    dao = data.get_files_dao()
    file_fp, filename, upload_date = dao.get(file_id)

    if download:
        mime = mimetypes.guess_type(filename)[0]
        if mime is None:
            # unknown type
            mime = "binary/octet-stream"

        basename = os.path.basename(filename)
        return send_file(file_fp, mimetype=mime, attachment_filename=basename, as_attachment=True)

    else:
        rawdata = file_fp.read()
        try:
            text = rawdata.decode('utf-8')
        except UnicodeDecodeError:
            # not decodable as utf-8
            text = _get_binary_info(rawdata)
        html = render_template("api/file_view.html", content=text)
        file_fp.close()
        return Response(html)
724308
def get_attachment(self, file_path):
        ''''''

        try:
            file_ = open(file_path, 'rb')
            attachment = MIMEBase('application', 'octet-stream')
            attachment.set_payload(file_.read())
            file_.close()
            encoders.encode_base64(attachment)

            attachment.add_header('Content-Disposition', 'attachment',
                                  filename=os.path.basename(file_path))
            return attachment
        except IOError:
            traceback.print_exc()
            message = ('The requested file could not be read. Maybe wrong '
                       'permissions?')
            print >> sys.stderr, message
            sys.exit(6)
500028
def get_attachment(self, id, filename, file):
        
        data = self.get_attachment_data(id, filename)
        file.write(data)
        return len(data)
11968
def get_blob_data(self, tag_target='asset', force=False):
        
        if hasattr(self, '_blob_data') and not force:
            return self._blob_data

        if six.PY2:
            self._blob_data = six.binary_type('')
        elif six.PY3:
            self._blob_data = six.binary_type('', encoding='ascii')
        asset_contents = self.contents.filter(tag=tag_target)
        for asset_content in asset_contents:
            blobs = asset_content.stream.get_blobs()
            for blob in blobs:
                self._blob_data += six.binary_type(blob.data)
        return self._blob_data
1205660
def attachment(filename=nil)
      response['Content-Disposition'] = 'attachment'
      if filename
        params = '; filename="%s"' % File.basename(filename)
        response['Content-Disposition'] << params
        ext = File.extname(filename)
        content_type(ext) unless response['Content-Type'] or ext.empty?
      end
    end
1035662
public static String computeAttachmentHash(byte[] attachment) {

		byte[] rawDigest = MESSAGE_DIGESTER.digest(attachment);

		return Base64.encode(rawDigest);

	}
867219
function getAttachment(binaryKey) {
    // console.log('Adding binary attachment', binaryKey);
    const index = attachments.findIndex((att) => (att.key === binaryKey));
    if (index !== -1) {
      const result = attachments[index].data;
      // TODO if attachment is sent mulitple times, we shouldn't remove it yet.
      attachments.splice(index, 1);
      return result;
    }
    console.error('Binary attachment key found without matching attachment');
    return null;
  }