Extract metadata from serialized file
333417
def extract_db_info(self, obj, keys):
        """"""

        objl = self.convert(obj)

        result = super(LinesCatalog, self).extract_db_info(objl, keys)

        result['tags'] = {}
        result['type'] = 'LinesCatalog'
        result['uuid'] = str(uuid.uuid1())
        result['observation_date'] = datetime.datetime.utcnow()
        result['quality_control'] = QC.GOOD
        result['origin'] = {}

        return result
752061
def extract_root_meta(cls, serializer, resource):
        
        many = False
        if hasattr(serializer, 'child'):
            many = True
            serializer = serializer.child

        data = {}
        if getattr(serializer, 'get_root_meta', None):
            json_api_meta = serializer.get_root_meta(resource, many)
            assert isinstance(json_api_meta, dict), 'get_root_meta must return a dict'
            data.update(json_api_meta)
        return data
265631
def parse(self, file, outfile=None):
        
        file = self._ensure_file(file)
        obj = json.load(file)
        items = obj['data']
        return [self.transform_item(item) for item in items]
928586
def c_metadata(api, args, verbose=False):
    
    obj = api.get_object(args['<URL>'].split('/')[-1])
    if not set_metadata(args['<JSON>'], obj):
        return json.dumps(obj.metadata.read(), indent=4)
150948
def extract_metadata(id)
      return {} if metadata_files.blank?
      metadata_file = metadata_files.find { |f| f.id == id }
      metadata_file.extract_metadata if metadata_file
    end
1301008
def get_writable_metadata(self, file_format):
        
        if file_format == 'json':
            metadata = self.json
        elif file_format == 'xml':
            metadata = self.xml
        else:
            raise TypeError('The requested file type (%s) is not yet supported'
                            % file_format)
        return metadata
929661
private static void extractXmpData(@NotNull final Metadata metadata, @NotNull SequentialReader reader) throws IOException
    {
        byte[] bytes = readUntil(reader, "<?xpacket end=\"w\"?>".getBytes());
        String xmp = new String(bytes, Charsets.UTF_8);
        new XmpReader().extract(xmp, metadata);
    }
333948
private static void extractIccData(@NotNull final Metadata metadata, @NotNull SequentialReader reader) throws IOException
    {
        byte[] buffer = decodeHexCommentBlock(reader);

        if (buffer != null)
            new IccReader().extract(new ByteArrayReader(buffer), metadata);
    }
364638
def _parse_metadata(self, meta):
        """"""
        formatted_fields = self.settings['FORMATTED_FIELDS']

        output = collections.OrderedDict()
        for name, value in meta.items():
            name = name.lower()
            if name in formatted_fields:
                rendered = self._render(value).strip()
                output[name] = self.process_metadata(name, rendered)
            else:
                output[name] = self.process_metadata(name, value)
        return output
862197
def _read_routine_metadata(self):
        
        metadata = {}
        if os.path.isfile(self._metadata_filename):
            with open(self._metadata_filename, 'r') as file:
                metadata = json.load(file)

        return metadata
194743
def deserialize(serialized_script):
    '''
    
    '''
    deserialized = []
    i = 0
    while i < len(serialized_script):
        current_byte = serialized_script[i]
        if current_byte == 0xab:
            raise NotImplementedError('OP_CODESEPARATOR is a bad idea.')
        if current_byte <= 75 and current_byte != 0:

            deserialized.append(
                serialized_script[i + 1: i + 1 + current_byte].hex())

            i += 1 + current_byte
            if i > len(serialized_script):
                raise IndexError(
                    'Push {} caused out of bounds exception.'
                    .format(current_byte))

        elif current_byte == 76:
            # next hex blob length
            blob_len = serialized_script[i + 1]

            deserialized.append(
                serialized_script[i + 2: i + 2 + blob_len].hex())

            i += 2 + blob_len

        elif current_byte == 77:
            # next hex blob length
            blob_len = utils.le2i(serialized_script[i + 1: i + 3])

            deserialized.append(
                serialized_script[i + 3: i + 3 + blob_len].hex())

            i += 3 + blob_len

        elif current_byte == 78:
            raise NotImplementedError('OP_PUSHDATA4 is a bad idea.')

        else:
            if current_byte in riemann.network.INT_TO_CODE_OVERWRITE:
                deserialized.append(
                    riemann.network.INT_TO_CODE_OVERWRITE[current_byte])
            elif current_byte in INT_TO_CODE:
                deserialized.append(INT_TO_CODE[current_byte])
            else:
                raise ValueError(
                    'Unsupported opcode. '
                    'Got 0x%x' % serialized_script[i])
            i += 1

    return ' '.join(deserialized)
998018
def parse_meta_data(self, line):
        """"""
        line = line.rstrip()
        logger.debug("Parsing metadata line:{0}".format(line))
        line_info = line[2:].split('=')
        match = False

        if line_info[0] == 'fileformat':
            logger.debug("Parsing fileformat")
            try:
                self.fileformat = line_info[1]
                logger.debug("Found fileformat {0}".format(self.fileformat))
            except IndexError:
                raise SyntaxError("fileformat must have a value")

        elif line_info[0] == 'INFO':
            match = self.info_pattern.match(line)
            if not match:
                raise SyntaxError("One of the INFO lines is malformed:{0}".format(line))

            matches = [
                match.group('id'), match.group('number'),
                match.group('type'), match.group('desc')
            ]

            # extra_info is a dictionary to check the metadata about the INFO values:
            self.extra_info[matches[0]] = dict(
                zip(self.header_keys['info'][1:], matches[1:])
            )

            info_line = dict(list(zip(self.header_keys['info'],matches)))

            if len(info_line['Description'].split('Format:')) > 1:
                info_line['Format'] = [
                    info.strip() for info in info_line['Description'].split('Format:')
                ][-1]
            self.info_lines.append(info_line)

            # Store the vep columns:
            if info_line['ID'] == 'CSQ':
                self.vep_columns = info_line.get('Format', '').split('|')

            if info_line['ID'] == 'ANN':
                self.snpeff_columns = [
                    annotation.strip("' ") for annotation in
                    info_line.get('Description', '').split(':')[-1].split('|')]

            self.info_dict[match.group('id')] = line

        elif line_info[0] == 'FILTER':
            match = self.filter_pattern.match(line)
            if not match:
                raise SyntaxError("One of the FILTER lines is malformed: {0}".format(line))
            matches = [match.group('id'), match.group('desc')]
            self.filter_lines.append(dict(
                list(zip(self.header_keys['filt'],matches)))
            )
            self.filter_dict[match.group('id')] = line

        elif line_info[0] == 'contig':
            match = self.contig_pattern.match(line)
            if not match:
                print()
                raise SyntaxError("One of the contig lines is malformed: {0}".format(line))

            matches = [match.group('id'), match.group('length')]
            self.contig_lines.append(dict(
                list(zip(self.header_keys['contig'],matches)))
            )
            self.contig_dict[match.group('id')] = line

        elif line_info[0] == 'FORMAT':
            match = self.format_pattern.match(line)
            if not match:
                raise SyntaxError("One of the FORMAT lines is malformed: {0}".format(line))

            matches = [
                match.group('id'), match.group('number'),
                match.group('type'), match.group('desc')
            ]
            self.format_lines.append(dict(
                list(zip(self.header_keys['form'],matches)))
            )
            self.format_dict[match.group('id')] = line

        elif line_info[0] == 'ALT':
            match = self.alt_pattern.match(line)
            if not match:
                raise SyntaxError("One of the ALT lines is malformed: {0}".format(line))

            matches = [match.group('id'), match.group('desc')]
            self.alt_lines.append(dict(
                list(zip(self.header_keys['alt'],matches)))
            )
            self.alt_dict[match.group('id')] = line

        else:
            match = self.meta_pattern.match(line)
            if not match:
                raise SyntaxError("One of the meta data lines is malformed: {0}".format(line))

            self.other_lines.append({match.group('key'): match.group('val')})
            self.other_dict[match.group('key')] = line
1266052
def read_all(filename):
    
    array = javabridge.static_call(
        "Lweka/core/SerializationHelper;", "readAll",
        "(Ljava/lang/String;)[Ljava/lang/Object;",
        filename)
    if array is None:
        return None
    else:
        return javabridge.get_env().get_object_array_elements(array)
1300794
def parse_metadata(self):
        """"""

        all_models = defaultdict(list)

        with open(self.metadata_index_json) as f:
            loaded = json.load(f)

        for m in loaded['index']:
            all_models[m['uniprot_ac']].append(m)

        self.all_models = dict(all_models)
772754
def parse_metadata(xml):
    
    try:
        root = etree.fromstring(xml)
    except (ExpatError, etree.ParseError):
        # The Last.fm API occasionally generates malformed XML when its
        # includes an illegal character (UTF8-legal but prohibited by
        # the XML standard).
        raise CommunicationError('malformed XML response')
    
    status = root.attrib['status']
    if status == 'failed':
        error = root.find('error')
        raise APIError(int(error.attrib['code']), error.text)
    
    out = []
    for track in root.find('tracks').findall('track'):
        out.append({
            'rank': float(track.attrib['rank']),
            'artist': track.find('artist').find('name').text,
            'artist_mbid': track.find('artist').find('mbid').text,
            'title': track.find('name').text,
            'track_mbid': track.find('mbid').text,
        })
    return out
574399
def serialized(self, prepend_date=True):
        """"""
        name = self.serialized_name()
        datetime = self.serialized_time(prepend_date)
        return "%s %s" % (datetime, name)
305068
def _parse_metadatas(self, text_lines):
        
        if not text_lines:
            return {}
        expr_metadata = re.compile(r'^#\+([a-zA-Z]+):(.*)')
        return {
            expr_metadata.match(line).group(1).lower()
            : expr_metadata.match(line).group(2).strip()
            for line in text_lines
        }