def mapped_parser_item_iterator(input_stream, item_path): """ Boilerplate function to setup the event mapper to ensure floats instead of decimals for use with ijson :param input_stream: :param item_path: :return: """ events = map(ijson_decimal_to_float, ijpython.parse(input_stream)) return ijcommon.items(events, item_path)
def _parse_cdmi_msg_body_fields(handle, buffer_size=4194304): """Parses the message body fields of a cdmi request. This function parses all fields except the value field. It returns a dictionary with the fields and a generator that can be used to get the value field. It takes advantage that the value field must always be the last. An excerpt from the cdmi 1.0.2 spec: "The request and response message body JSON fields may be specified or returned in any order, with the exception that, if present, for data objects, the valuerange and value fields shall appear last and in that order." FIXIT: this first implementation is only partial, to accomodate requests that fit in one buffer_size. """ parser = parse(handle) data_json = dict() value_gen = None for prefix, event, value in parser: if value == 'value': def make_value_gen(val, encoding, buffer_size=4 * 1024): """ This function works with the current ijson. ijson itself should be modified so that it can return an iterator. Then this function will become simpler, but will be used to apply any special encoding. """ acc = 0 out = None while out != '': out = val[acc:acc + buffer_size] acc += buffer_size yield out pre, eve, val = next(parser) value_gen = make_value_gen( val, data_json.get('valuetransferencoding', None)) break if prefix != '': data_json[prefix] = value return data_json, value_gen
def load(filename): res = Result() parser = ijson.parse(open(filename)) for prefix, event, value in parser: if prefix == 'total_duration': res.duration = value if prefix == 'started': res.started = value if prefix == 'ended': res.ended = value if prefix == 'connection_stats.item.tcp_pre_init': if res.preInitMin is None or value < res.preInitMin: res.preInitMin = value if res.preInitMax is None or value > res.preInitMax: res.preInitMax = value if prefix == 'connection_stats.item.failed': if value: res.fail += 1 else: res.success += 1 if prefix == 'connection_stats.item.open': res.openTimestamps.append(value) if prefix == 'connection_stats.item.close': res.closeTimestamps.append(value) res.total = res.success + res.fail res.durationWallclock = res.ended - res.started return res
def __init__(self, sock): self._f = SocketWrapper(sock) self._parser = ijson.parse(self._f)