Get a window of samples not to exceed size (in MB).

        Args:
            type_tag: Type of sample ('exe','pcap','pdf','json','swf', or ...).
            size: Size of samples in MBs.

        Returns:
            a list of md5s.
540021
def get_sample_window(self, type_tag, size=10):
        

        # Convert size to MB
        size = size * 1024 * 1024

        # Grab all the samples of type=type_tag, sort by import_time (newest to oldest)
        cursor = self.database[self.sample_collection].find({'type_tag': type_tag},
            {'md5': 1,'length': 1}).sort('import_time',pymongo.DESCENDING)
        total_size = 0
        md5_list = []
        for item in cursor:
            if total_size > size:
                return md5_list
            md5_list.append(item['md5'])
            total_size += item['length']

        # If you get this far you don't have 'size' amount of data
        # so just return what you've got
        return md5_list
229535
function parse_ExtProp(blob/*::, length*/)/*:Array<any>*/ {
	var extType = blob.read_shift(2);
	var cb = blob.read_shift(2) - 4;
	var o = [extType];
	switch(extType) {
		case 0x04: case 0x05: case 0x07: case 0x08:
		case 0x09: case 0x0A: case 0x0B: case 0x0D:
			o[1] = parse_FullColorExt(blob, cb); break;
		case 0x06: o[1] = parse_XFExtGradient(blob, cb); break;
		case 0x0E: case 0x0F: o[1] = blob.read_shift(cb === 1 ? 1 : 2); break;
		default: throw new Error("Unrecognized ExtProp type: " + extType + " " + cb);
	}
	return o;
}
81528
def types(subtag):
        
        if subtag in index:
            types = index[subtag]
            return [type for type in types.keys() if type != 'redundant' or type != 'grandfathered']
        else:
            return []
1187507
def _prepare_sample_data(self, submission_type):
    
    # write images
    images = np.random.randint(0, 256,
                               size=[BATCH_SIZE, 299, 299, 3], dtype=np.uint8)
    for i in range(BATCH_SIZE):
      Image.fromarray(images[i, :, :, :]).save(
          os.path.join(self._sample_input_dir, IMAGE_NAME_PATTERN.format(i)))
    # write target class for targeted attacks
    if submission_type == 'targeted_attack':
      target_classes = np.random.randint(1, 1001, size=[BATCH_SIZE])
      target_class_filename = os.path.join(self._sample_input_dir,
                                           'target_class.csv')
      with open(target_class_filename, 'w') as f:
        for i in range(BATCH_SIZE):
          f.write((IMAGE_NAME_PATTERN + ',{1}\n').format(i, target_classes[i]))
638030
def ab_read(self, start, size):
        
        wordlen = snap7.snap7types.S7WLByte
        type_ = snap7.snap7types.wordlen_to_ctypes[wordlen]
        data = (type_ * size)()
        logger.debug("ab_read: start: %s: size %s: " % (start, size))
        result = self.library.Cli_ABRead(self.pointer, start, size,
                                         byref(data))
        check_error(result, context="client")
        return bytearray(data)
995430
def get_tag(self, tagtype):
        ''' '''
        for tag in self.__tags:
            if tag.tagtype == tagtype:
                return tag
        return None
524486
def size(self, type=None, failed=False):
        
        return len(self.nodes(type=type, failed=failed))
1338599
def get_tags_from_full_ob(ob, reqtags=None):
    
    # each instrument should have one
    # perhaps each mode...
    files = ob.frames
    cfiles = ob.children
    alltags = {}

    if reqtags is None:
        reqtags = []

    # Init alltags...
    # Open first image
    if files:
        for fname in files[:1]:
            with fname.open() as fd:
                header = fd[0].header
                for t in reqtags:
                    alltags[t] = header[t]
    else:

        for prod in cfiles[:1]:
            prodtags = prod.tags
            for t in reqtags:
                alltags[t] = prodtags[t]

    for fname in files:
        with fname.open() as fd:
            header = fd[0].header

            for t in reqtags:
                if alltags[t] != header[t]:
                    msg = 'wrong tag %s in file %s' % (t, fname)
                    raise ValueError(msg)

    for prod in cfiles:
        prodtags = prod.tags
        for t in reqtags:
            if alltags[t] != prodtags[t]:
                msg = 'wrong tag %s in product %s' % (t, prod)
                raise ValueError(msg)

    return alltags
890731
def get_type_size(ty):
    
    m = type_str_re.match(ty)
    if m is None:
        raise ValueError('Type %s does not have size' % ty)
    return int(m.group('size'))
94253
def _get_wmi_sampler(self, instance_key, wmi_class, properties, tag_by="", **kwargs):
        
        properties = list(properties) + [tag_by] if tag_by else list(properties)

        if instance_key not in self.wmi_samplers:
            wmi_sampler = WMISampler(self.log, wmi_class, properties, **kwargs)
            self.wmi_samplers[instance_key] = wmi_sampler

        return self.wmi_samplers[instance_key]
1162254
static function guessFileTypeFromMimeType($mt, $def = '')
	{
		// for audio, image, videos, this is simple, the Mime type is explicit
		if ( strpos($mt, 'audio/') === 0 )
			return 'audio';
		if ( strpos($mt, 'image/') === 0 )
			return 'image';
		if ( strpos($mt, 'video/') === 0 )
			return 'video';
		
			
		switch ( $mt )
		{
			case 'application/pdf':
				return 'pdf';
			case 'text/html':
				return 'html';
			case 'text/plain':
				return 'text';
			case 'message/rfc822':
				return 'email';
			case 'application/msword':
			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
			case 'application/vnd.oasis.opendocument.text':
				return 'word';
			case 'application/vnd.ms-excel':
			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
			case 'application/vnd.oasis.opendocument.spreadsheet':
				return 'excel';
			case 'application/vnd.ms-powerpoint':
			case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
			case 'application/vnd.oasis.opendocument.presentation':
				return 'powerpoint';
			case 'application/zip':
				return 'zip';
			default :
				return $def;
		}
	}
439362
def frame_size(self):
        """"""
        if self.sample_type == SampleType.S16NativeEndian:
            # Sample size is 2 bytes
            return self.sample_size * self.channels
        else:
            raise ValueError('Unknown sample type: %d', self.sample_type)
369878
def raw(self, tag, raw, metadata):
        
        raw = base64.b64encode(raw)
        return {
            'type': 'raw',
            'tag': tag,
            'raw': raw,
            'metadata': metadata
        }
2487
private int getTagSize(TagValue tag) {
    int n = tag.getCardinality();
    int id = tag.getId();

    // Calculate tag size
    int type = tag.getType();

    if (id == 330) {
      // SubIFD
      n = 1000;
    }
    if (id == 700) {
      // XMP
      if (tag.getValue().size() > 0)
        n = tag.getValue().get(0).toString().length();
    }
    if (id == 33723) {
      // IPTC
      n = tag.getReadlength();
    }
    if (id == 34665) {
      // EXIF
      n = 1000;
    }
    if (id == 34675) {
      // ICC
      n = tag.getReadlength();
    }

    int typeSize = TiffTags.getTypeSize(type);
    int tagSize = typeSize * n;
    return tagSize;
  }
76738
def _setSampleSizeBytes(self):
        
        self.sampleSizeBytes = self.getPacketSize()
        if self.sampleSizeBytes > 0:
            self.maxBytesPerFifoRead = (32 // self.sampleSizeBytes)
1171021
def SetClipboardData(type, content):
	
	allocators = {
		clipboard.CF_TEXT: ctypes.create_string_buffer,
		clipboard.CF_UNICODETEXT: ctypes.create_unicode_buffer,
		clipboard.CF_HTML: ctypes.create_string_buffer,
	}
	if type not in allocators:
		raise NotImplementedError(
			"Only text and HTML types are supported at this time")
	# allocate the memory for the data
	content = allocators[type](content)
	flags = memory.GMEM_MOVEABLE
	size = ctypes.sizeof(content)
	handle_to_copy = windll.kernel32.GlobalAlloc(flags, size)
	with LockedMemory(handle_to_copy) as lm:
		ctypes.memmove(lm.data_ptr, content, size)
	result = clipboard.SetClipboardData(type, handle_to_copy)
	if result is None:
		raise WindowsError()
1094979
def check_format(cls, tags):
        
        common, _, _ = tags
        for tag in common:
            if tag.get_type() != 0:  # Unknown type -> incorrect
                return False
        return True