Parse current offsets from json-file.
559839
def parse_consumer_offsets(cls, json_file):
        """"""
        with open(json_file, 'r') as consumer_offsets_json:
            try:
                parsed_offsets = {}
                parsed_offsets_data = json.load(consumer_offsets_json)
                # Create new dict with partition-keys as integers
                parsed_offsets['groupid'] = parsed_offsets_data['groupid']
                parsed_offsets['offsets'] = {}
                for topic, topic_data in six.iteritems(parsed_offsets_data['offsets']):
                    parsed_offsets['offsets'][topic] = {}
                    for partition, offset in six.iteritems(topic_data):
                        parsed_offsets['offsets'][topic][int(partition)] = offset
                return parsed_offsets
            except ValueError:
                print(
                    "Error: Given consumer-data json data-file {file} could not be "
                    "parsed".format(file=json_file),
                    file=sys.stderr,
                )
                raise
826978
def _parse_refraction(line, lines):
    """"""
    split_line = line.split()

    energy = float(split_line[0])
    ref_ind_xx = float(split_line[1])
    ref_ind_zz = float(split_line[2])
    extinct_xx = float(split_line[3])
    extinct_zz = float(split_line[4])

    return {"energy": energy, "ref_ind_xx": ref_ind_xx, "ref_ind_zz": ref_ind_zz, "extinct_xx": extinct_xx,
            "extinct_zz": extinct_zz}
1024675
def get_offset(self):
    
    if not self._is_open:
      raise IOError('Not opened.')

    if not hasattr(self._file_object, 'get_offset'):
      return self._file_object.tell()
    return self._file_object.get_offset()
1127577
def validate_json(file):
    """"""
    max_file_size = current_app.config.get(
        'PREVIEWER_MAX_FILE_SIZE_BYTES', 1 * 1024 * 1024)
    if file.size > max_file_size:
        return False

    with file.open() as fp:
        try:
            json.loads(fp.read().decode('utf-8'))
            return True
        except:
            return False
543876
def read_json(fh, byteorder, dtype, count, offsetsize):
    """"""
    data = fh.read(count)
    try:
        return json.loads(unicode(stripnull(data), 'utf-8'))
    except ValueError:
        log.warning('read_json: invalid JSON')
995211
def _update_offsets(start_x, spacing, terminations, offsets, length):
    '''
    '''
    return (start_x + spacing[0] * terminations / 2.,
            offsets[1] + spacing[1] * 2. + length)
634396
def coords_string_parser(self, coords):
        """"""

        lat, lon = coords.split(',')
        return {"lat": lat.strip(), "lon": lon.strip(), "bounds": {}}
1121325
def _parse_dict(self, text, i):
        """"""
        old_current_type = self.current_type
        new_type = self.current_type
        if new_type is None:
            # customparameter.value needs to be set from the found value
            new_type = dict
        elif type(new_type) == list:
            new_type = new_type[0]
        res = new_type()
        i = self._parse_dict_into_object(res, text, i)
        self.current_type = old_current_type
        return res, i
755153
def _cache_offsets(self, up_to_index=None, verbose=True):
        """"""
        if not up_to_index:
            if verbose:
                self.print("Caching event file offsets, this may take a bit.")
            self.blob_file.seek(0, 0)
            self.event_offsets = []
            if not self.raw_header:
                self.event_offsets.append(0)
        else:
            self.blob_file.seek(self.event_offsets[-1], 0)
        for line in iter(self.blob_file.readline, ''):
            line = try_decode_string(line)
            if line.startswith('end_event:'):
                self._record_offset()
                if len(self.event_offsets) % 100 == 0:
                    if verbose:
                        print('.', end='')
                    sys.stdout.flush()
            if up_to_index and len(self.event_offsets) >= up_to_index + 1:
                return
        self.event_offsets.pop()    # get rid of the last entry
        if not up_to_index:
            self.whole_file_cached = True
        self.print("\n{0} events indexed.".format(len(self.event_offsets)))
1223634
def _parse(res, params, n, api, **kwds):
    """"""
    cursor = "cursor" in params
    if not cursor:
        start = params["start"]
    if n == 0:
        return ""
    _json = res.get('search-results', {}).get('entry', [])
    # Download the remaining information in chunks
    while n > 0:
        n -= params["count"]
        if cursor:
            pointer = res['search-results']['cursor'].get('@next')
            params.update({'cursor': pointer})
        else:
            start += params["count"]
            params.update({'start': start})
        res = download(url=URL[api], params=params, accept="json", **kwds).json()
        _json.extend(res.get('search-results', {}).get('entry', []))
    return _json
729741
def load_json_from_file(file_path):
    """"""
    try:
        with open(file_path) as f:
            json_data = json.load(f)
    except ValueError as e:
        raise ValueError('Given file {} is not a valid JSON file: {}'.format(file_path, e))
    else:
        return json_data
1195241
def _parse_eloss(line, lines):
    """"""

    split_line = line.split()

    energy = float(split_line[0])
    eloss_xx = float(split_line[1])
    eloss_zz = float(split_line[2])

    return {"energy": energy, "eloss_xx": eloss_xx, "eloss_zz": eloss_zz}
277000
def read_json(file_or_path):
    """"""
    try:
        with (open(file_or_path, 'r') if isinstance(file_or_path, (str, bytes)) else file_or_path) as f:
            obj = json.load(f)
    except IOError:
        obj = json.loads(file_or_path)
    return obj
1115827
def parse(self,fileName,offset):
        '''
        '''
        p = Parser()
        p.file = open(fileName, 'rb')
        a = p.parse_synset(offset=offset)
        p.file.close()
        self.__dict__.update(a.__dict__)
1204923
def parse(out):
    '''
    
    '''
    jsonret = []
    in_json = False
    for ln_ in out.split('\n'):
        if '{' in ln_:
            in_json = True
        if in_json:
            jsonret.append(ln_)
        if '}' in ln_:
            in_json = False
    return salt.utils.json.loads('\n'.join(jsonret))
716948
def _parse(self, stream, context, path):
        """"""
        objs = []
        while True:
            start = stream.tell()
            test = stream.read(len(self.find))
            stream.seek(start)
            if test == self.find:
                break
            else:
                subobj = self.subcon._parse(stream, context, path)
                objs.append(subobj)
        return objs
104604
def offsets(self):
      """"""
      for path, tailedfile in self._tailedfiles.iteritems():
         yield path, tailedfile._offset