Parse a <image> object
513673
def _parse_tree(self, node):
        
        if 'type' in node.attrib:
            self.kind = node.attrib['type']
        if 'width' in node.attrib:
            self.width = int(node.attrib['width'])
        if 'height' in node.attrib:
            self.height = int(node.attrib['height'])
        self.url = node.text
426165
def parse_image_response(self, response):
        
        if 'xml' in response.headers.get('Content-Type'):
            # Got an XML response, likely an error code.
            xml = xmltodict.parse(response.text)
            self.analyze_reply_code(xml_response_dict=xml)

        multi_parts = self._get_multiparts(response)
        parsed = []
        # go through each part of the multipart message
        for part in multi_parts:
            clean_part = part.strip('\r\n\r\n')
            if '\r\n\r\n' in clean_part:
                header, body = clean_part.split('\r\n\r\n', 1)
            else:
                header = clean_part
                body = None
            part_header_dict = {k.strip(): v.strip() for k, v in (h.split(':', 1) for h in header.split('\r\n'))}

            # Some multipart requests respond with a text/XML part stating an error
            if 'xml' in part_header_dict.get('Content-Type'):
                # Got an XML response, likely an error code.
                # Some rets servers give characters after the closing brace.
                body = body[:body.index('/>') + 2]  if '/>' in body else body
                xml = xmltodict.parse(body)
                try:
                    self.analyze_reply_code(xml_response_dict=xml)
                except RETSException as e:
                    if e.reply_code == '20403':
                        # The requested object_id was not found.
                        continue
                    raise e

            if body:
                obj = self._response_object_from_header(
                    obj_head_dict=part_header_dict,
                    content=body.encode('latin-1') if six.PY3 else body)
            else:
                obj = self._response_object_from_header(obj_head_dict=part_header_dict)
            parsed.append(obj)
        return parsed
941009
def parse(self):
        """"""
        start = time.time()

        if self.cache:
            self.load_cache()

        if not self.cache_loaded:
            super(ObjParser, self).parse()

        logger.info("%s: Load time: %s", self.file_name, time.time() - start)
538559
function isTexImageSource(obj) {
  return (typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap) ||
         (typeof ImageData !== 'undefined'  && obj instanceof ImageData) ||
         (typeof HTMLElement !== 'undefined'  && obj instanceof HTMLElement);
}
547309
function imageToImageData ( image ) {
	if ( image instanceof HTMLImageElement ) {
		// http://stackoverflow.com/a/3016076/229189
		if ( ! image.naturalWidth || ! image.naturalHeight || image.complete === false ) {
			throw new Error( "This this image hasn't finished loading: " + image.src );
		}

		const canvas = new Canvas( image.naturalWidth, image.naturalHeight );
		const ctx = canvas.getContext( '2d' );
		
		ctx.drawImage( image, 0, 0, canvas.width, canvas.height );

		const imageData = ctx.getImageData( 0, 0, canvas.width, canvas.height );

		if ( imageData.data && imageData.data.length ) {
			if ( typeof imageData.width === 'undefined' ) {
				imageData.width = image.naturalWidth;
			}

			if ( typeof imageData.height === 'undefined' ) {
				imageData.height = image.naturalHeight;
			}
		}
		
		return imageData;
	} else {
		throw new Error( 'This object does not seem to be an image.' );
		return;
	}
}
1291062
def __parseThunkData(self, thunk,importSection):
        """"""
        offset = to_offset(thunk.header.AddressOfData, importSection)
        if 0xf0000000 & thunk.header.AddressOfData == 0x80000000:
            thunk.ordinal = thunk.header.AddressOfData & 0x0fffffff
        else:
            ibn = IMAGE_IMPORT_BY_NAME.from_buffer(importSection.raw, offset)

            checkOffset(offset+2, importSection)
            name = get_str(importSection.raw, offset+2)
            thunk.importByName = ImportByNameData(header=ibn, hint=ibn.Hint, name=name)
1157673
function _parse(type, obj, options)
{
    if (!obj) return _checkResult(type, lib.newError("empty " + type), obj, options);
    try {
        obj = _parseResult(type, obj, options);
    } catch(err) {
        obj = _checkResult(type, err, obj, options);
    }
    return obj;
}
995290
function parse_BLOB(blob) {
	var size = blob.read_shift(4);
	var bytes = blob.slice(blob.l,blob.l+size);
	blob.l += size;
	if((size & 3) > 0) blob.l += (4 - (size & 3)) & 3;
	return bytes;
}
1336711
def parse(node)
      return nil if node.xpath('*').empty?

      node.xpath('*').each do |node_child|
        case node_child.name
        when 'gradFill'
          @type = :gradient
          @color = GradientColor.new(parent: self).parse(node_child)
        when 'solidFill'
          @type = :solid
          @color = Color.new(parent: self).parse_color(node_child.xpath('*').first)
        when 'blipFill'
          @type = :image
          @image = ImageFill.new(parent: self).parse(node_child)
        when 'pattFill'
          @type = :pattern
          @pattern = PresentationPattern.new(parent: self).parse(node_child)
        when 'noFill'
          @type = :noneColor
          @color = :none
        end
      end
      return nil if @type.nil?

      self
    end
1287932
def parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'style'
          @style_number = node_child.attribute('val').value.to_i
        when 'oleObject'
          @ole_object = OleObject.new(parent: self).parse(node_child)
        end
      end
      self
    end
416872
function parseObject(obj){
  obj = obj.vals;
  for (var key in obj) {
    var nodes = obj[key].nodes[0].nodes;
    if (nodes && nodes.length) {
      obj[key] = [];
      for (var i = 0, len = nodes.length; i < len; ++i) {
        obj[key].push(convert(nodes[i]));
      }
    } else {
      obj[key] = convert(obj[key].first);
    }
  }
  return obj;

  function convert(node){
    switch (node.nodeName) {
      case 'object':
        return parseObject(node);
      case 'boolean':
        return node.isTrue;
      case 'unit':
        return node.type ? node.toString() : +node.val;
      case 'string':
      case 'literal':
        return node.val;
      default:
        return node.toString();
    }
  }
}
336206
def parse_size(image, size):
        
        bits = size.split("x")
        if image.size[0] == 0 or image.size[1] == 0:
            ratio = 1.0
        else:
            ratio = float(image.size[0]) / float(image.size[1])

        if len(bits) == 1 or not bits[1]:
            width = int(bits[0])
            height = int(1 / ratio * width)
        elif not bits[0]:
            height = int(bits[1])
            width = int(height * ratio)
        else:
            width, height = map(int, bits)
        return width, height
4220
def image_from(from_value):
    
    regex = re.compile(r"""(?xi)     # readable, case-insensitive regex
        \s*                          # ignore leading whitespace
        (?P<image> \S+ )             # image and optional tag
        (?:                          # optional "AS name" clause for stage
            \s+ AS \s+
            (?P<name> \S+ )
        )?
        """)
    match = re.match(regex, from_value)
    return match.group('image', 'name') if match else (None, None)
1027591
function parseObject(obj){
  var ret = { base: {} };

  forEach(objectKeys(obj), function(name){
    merge(ret, name, obj[name]);
  });

  return compact(ret.base);
}
969099
function parse(string) {
    var result = {},
        lines = string.split(/\r\n|\r|\n/),
        count = lines.length,
        pieces,
        key,
        value,
        meta,
        namespace;

    for (var i = 0; i < count; i++) {
        if (lines[i] === '') {
            continue;
        }
        if (lines[i].toUpperCase() === PREFIX || lines[i].toUpperCase() === POSTFIX) {
            continue;
        }
        var data = lines[i];

        /**
         * Check that next line continues current
         * @param {number} i
         * @returns {boolean}
         */
        var isValueContinued = function (i) {
            return i + 1 < count && (lines[i + 1][0] === ' ' || lines[i + 1][0] === '\t');
        };
        // handle multiline properties (i.e. photo).
        // next line should start with space or tab character
        if (isValueContinued(i)) {
            while (isValueContinued(i)) {
                data += lines[i + 1].trim();
                i++;
            }
        }

        pieces = data.split(':');
        key = pieces.shift();
        value = pieces.join(':');
        namespace = false;
        meta = {};

        // meta fields in property
        if (key.match(/;/)) {
            key = key
                .replace(/\\;/g, 'ΩΩΩ')
                .replace(/\\,/, ',');
            var metaArr = key.split(';').map(function (item) {
                return item.replace(/ΩΩΩ/g, ';');
            });
            key = metaArr.shift();
            metaArr.forEach(function (item) {
                var arr = item.split('=');
                arr[0] = arr[0].toLowerCase();
                if (arr[0].length === 0) {
                    return;
                }
                if (meta[arr[0]]) {
                    meta[arr[0]].push(arr[1]);
                } else {
                    meta[arr[0]] = [arr[1]];
                }
            });
        }

        // values with \n
        value = value
            .replace(/\\n/g, '\n');

        value = tryToSplit(value);

        // Grouped properties
        if (key.match(/\./)) {
            var arr = key.split('.');
            key = arr[1];
            namespace = arr[0];
        }

        var newValue = {
            value: value
        };
        if (Object.keys(meta).length) {
            newValue.meta = meta;
        }
        if (namespace) {
            newValue.namespace = namespace;
        }

        if (key.indexOf('X-') !== 0) {
            key = key.toLowerCase();
        }

        if (typeof result[key] === 'undefined') {
            result[key] = [newValue];
        } else {
            result[key].push(newValue);
        }

    }

    return result;
}
212312
def _is_image(self, var):
        """"""
        try:
            from PIL import Image
            return isinstance(var, Image.Image)
        except:
            return False
1301678
def _parse(self):
        """"""
        if not self.pattern:
            raise TiffSequence.ParseError('invalid pattern')
        pattern = re.compile(self.pattern, re.IGNORECASE | re.VERBOSE)
        matches = pattern.findall(os.path.split(self.files[0])[-1])
        if not matches:
            raise TiffSequence.ParseError('pattern does not match file names')
        matches = matches[-1]
        if len(matches) % 2:
            raise TiffSequence.ParseError(
                'pattern does not match axis name and index')
        axes = ''.join(m for m in matches[::2] if m)
        if not axes:
            raise TiffSequence.ParseError('pattern does not match file names')

        indices = []
        for fname in self.files:
            fname = os.path.split(fname)[-1]
            matches = pattern.findall(fname)[-1]
            if axes != ''.join(m for m in matches[::2] if m):
                raise ValueError('axes do not match within image sequence')
            indices.append([int(m) for m in matches[1::2] if m])
        shape = tuple(numpy.max(indices, axis=0))
        startindex = tuple(numpy.min(indices, axis=0))
        shape = tuple(i-j+1 for i, j in zip(shape, startindex))
        if product(shape) != len(self.files):
            log.warning(
                'TiffSequence: files are missing. Missing data are zeroed')

        self.axes = axes.upper()
        self.shape = shape
        self._indices = indices
        self._startindex = startindex