当前位置: 首页>>代码示例>>Python>>正文


Python rapidjson.loads函数代码示例

本文整理汇总了Python中rapidjson.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了loads函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_precise_float

def test_precise_float():
    f = "1.234567890E+34"
    f1 = "1.2345678900000002e+34"

    assert rapidjson.loads(f) == float(f)
    assert rapidjson.loads(f, precise_float=True) == float(f)
    assert rapidjson.loads(f, precise_float=False) == float(f1)
开发者ID:nhoening,项目名称:python-rapidjson,代码行数:7,代码来源:test_params.py

示例2: test_datetime_mode_loads

def test_datetime_mode_loads():
    import pytz

    utc = datetime.now(pytz.utc)
    utcstr = utc.isoformat()

    jsond = rapidjson.dumps(utc, datetime_mode=rapidjson.DATETIME_MODE_ISO8601)

    assert jsond == '"%s"' % utcstr
    assert rapidjson.loads(jsond, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == utc

    local = utc.astimezone(pytz.timezone('Europe/Rome'))
    locstr = local.isoformat()

    jsond = rapidjson.dumps(local, datetime_mode=rapidjson.DATETIME_MODE_ISO8601)

    assert jsond == '"%s"' % locstr
    assert rapidjson.loads(jsond) == locstr
    assert rapidjson.loads(jsond, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == local

    load_as_utc = rapidjson.loads(jsond, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_UTC)

    assert load_as_utc == utc
    assert not load_as_utc.utcoffset()

    load_as_naive = rapidjson.loads(jsond, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ)

    assert load_as_naive == local.replace(tzinfo=None)
开发者ID:kenrobbins,项目名称:python-rapidjson,代码行数:28,代码来源:test_params.py

示例3: test_uuid_mode

def test_uuid_mode():
    assert rapidjson.UUID_MODE_NONE == 0
    assert rapidjson.UUID_MODE_CANONICAL == 1
    assert rapidjson.UUID_MODE_HEX == 2

    value = uuid.uuid1()
    with pytest.raises(TypeError):
        rapidjson.dumps(value)

    with pytest.raises(ValueError):
        rapidjson.dumps(value, uuid_mode=42)

    with pytest.raises(ValueError):
        rapidjson.loads('""', uuid_mode=42)

    dumped = rapidjson.dumps(value, uuid_mode=rapidjson.UUID_MODE_CANONICAL)
    loaded = rapidjson.loads(dumped, uuid_mode=rapidjson.UUID_MODE_CANONICAL)
    assert loaded == value

    # When loading, hex mode implies canonical format
    loaded = rapidjson.loads(dumped, uuid_mode=rapidjson.UUID_MODE_HEX)
    assert loaded == value

    dumped = rapidjson.dumps(value, uuid_mode=rapidjson.UUID_MODE_HEX)
    loaded = rapidjson.loads(dumped, uuid_mode=rapidjson.UUID_MODE_HEX)
    assert loaded == value
开发者ID:kenrobbins,项目名称:python-rapidjson,代码行数:26,代码来源:test_params.py

示例4: test_infinity

def test_infinity():
    inf = float("inf")
    dumped = rapidjson.dumps(inf)
    loaded = rapidjson.loads(dumped)
    assert loaded == inf

    d = Decimal(inf)
    dumped = rapidjson.dumps(inf, use_decimal=True)
    loaded = rapidjson.loads(dumped, use_decimal=True)
    assert loaded == inf
开发者ID:atomx,项目名称:python-rapidjson,代码行数:10,代码来源:test_float.py

示例5: read_prev

    def read_prev(self):
        """
        Read the previous line from the file, parse and return. Returns None if out of lines.
        """
        original_pos = current_pos = self.file.tell()

        # can't fall off the beginning
        if current_pos == 0:
            return None

        # rewind by chunk_size and read chunk_size bytes
        # repeat until we've found TWO \n - the end of the previous line, and the beginning of the line before the line we want
        # then split n grab
        #print(current_pos)
        rewound_chunk = b""
        while rewound_chunk.count(b"\n") < 3: # changed from 2 to 3 to fix partial reads
            before_jump = current_pos

            # Jump backwards x bytes, and prevent falling off the start
            current_pos = max(0, current_pos-self.chunk_size)
            self.file.seek(current_pos)
            jumped_by = before_jump-current_pos

            # prepend the chunk to our buffer
            rewound_chunk = b''.join([self.file.read(jumped_by), rewound_chunk])
            #rewound_chunk = ''.join([rewound_chunk, '|||||', self.file.read(jumped_by)])
            #print("Read ", jumped_by)

            # If we just read from the beginning of the file this loop should break regardless
            if current_pos == 0:
                break

        # we have a chunk containing at least one full line
        # find the last line in the chunk
        lines_split = rewound_chunk.split(b"\n")

        # -1 => blank
        # -2 => last line emitted
        # -3 => previous line. wont exist if we hit BOF
        # -4+ => line before that and/or partial line garbage
        if len(lines_split) < 3:
            self.line = 0
            self.file.seek(0)
            return json.loads(self.decode(lines_split[0]))
        prev_line = lines_split[-2]

        # Calculate how far backwards we jumped, seek to the beginning of the line we're returning
        # TODO should it be elsewhere so if next_line is called we dont get this line again?
        after_prev_line = lines_split[-1:]
        rewound_len = len(b"\n".join([prev_line] + after_prev_line))
        self.file.seek(original_pos - rewound_len)
        self.line -= 1

        return json.loads(self.decode(prev_line))
开发者ID:dpedu2,项目名称:sless,代码行数:54,代码来源:lazyjson.py

示例6: test_nan

def test_nan():
    nan = float("nan")
    dumped = rapidjson.dumps(nan)
    loaded = rapidjson.loads(dumped)

    assert math.isnan(nan)
    assert math.isnan(loaded)

    d = Decimal(nan)
    dumped = rapidjson.dumps(nan, use_decimal=True)
    loaded = rapidjson.loads(dumped, use_decimal=True)

    assert math.isnan(d)
    assert math.isnan(loaded)
开发者ID:atomx,项目名称:python-rapidjson,代码行数:14,代码来源:test_float.py

示例7: test_datetime_mode_dumps

def test_datetime_mode_dumps():
    import pytz

    assert rapidjson.DATETIME_MODE_NONE == 0
    assert rapidjson.DATETIME_MODE_ISO8601 == 1
    assert rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ == 2
    assert rapidjson.DATETIME_MODE_ISO8601_UTC == 3

    d = datetime.utcnow()
    dstr = d.isoformat()

    with pytest.raises(TypeError):
        rapidjson.dumps(d)

    with pytest.raises(ValueError):
        rapidjson.dumps(d, datetime_mode=42)

    with pytest.raises(ValueError):
        rapidjson.loads('""', datetime_mode=42)

    with pytest.raises(TypeError):
        rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_NONE)

    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == '"%s"' % dstr
    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ) == '"%s"' % dstr

    d = d.replace(tzinfo=pytz.utc)
    dstr = utcstr = d.isoformat()

    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == '"%s"' % dstr
    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ) == '"%s"' % dstr[:-6]

    d = d.astimezone(pytz.timezone('Pacific/Chatham'))
    dstr = d.isoformat()

    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == '"%s"' % dstr
    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ) == '"%s"' % dstr[:-6]

    d = d.astimezone(pytz.timezone('Asia/Kathmandu'))
    dstr = d.isoformat()

    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == '"%s"' % dstr
    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ) == '"%s"' % dstr[:-6]

    d = d.astimezone(pytz.timezone('America/New_York'))
    dstr = d.isoformat()

    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601) == '"%s"' % dstr
    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_IGNORE_TZ) == '"%s"' % dstr[:-6]
    assert rapidjson.dumps(d, datetime_mode=rapidjson.DATETIME_MODE_ISO8601_UTC) == '"%s"' % utcstr
开发者ID:kenrobbins,项目名称:python-rapidjson,代码行数:50,代码来源:test_params.py

示例8: getAddy

def getAddy(apn):
	# cleanup apn by removing dashes
	apn = apn.replace("-","")
	# make http call and assign response
	r = http.request('GET', url + apn)
	# pull data out of response
	data = r.data.decode('utf-8')
	# convert data to json dictionary
	d = rapidjson.loads(data)
	# sometimes there is no data, so write 'apn, NA, 0, 0'
	if len(d) < 1:
		print("\n", apn, ",NA", sep='')
		s = (apn,"NA",0,0)
		return s

	# otherwise there's data
	a = d[0] #address info
	c = d[1]['geometry']['coordinates'] # coordinate list
	pt = c[0][0] # first coordinate
	#debug: print(apn,",",a['from_st']," ",a['street'],",",pt[0],",",pt[1], sep='') #a['st_type'])
	if 'from_st' in a:
		s = (apn,a['from_st']+" "+a['street'],pt[0],pt[1])
		print('.', end='', flush=True) #print(s)
	else:
		s = (apn,"NA",0,0)
	return s
开发者ID:anujgoyal,项目名称:tips,代码行数:26,代码来源:apn2geo.py

示例9: get_input_condition

def get_input_condition(bigchain, fulfillment):
    """

    Args:
        bigchain:
        fulfillment:
    Returns:
    """
    input_tx = fulfillment['input']
    # if `TRANSFER` transaction
    if input_tx:
        # get previous condition
        previous_tx = bigchain.get_transaction(input_tx['txid'])
        conditions = sorted(previous_tx['transaction']['conditions'], key=lambda d: d['cid'])
        return conditions[input_tx['cid']]

    # if `CREATE` transaction
    # there is no previous transaction so we need to create one on the fly
    else:
        current_owner = fulfillment['current_owners'][0]
        condition = cc.Ed25519Fulfillment(public_key=current_owner)

        return {
            'condition': {
                'details': rapidjson.loads(condition.serialize_json()),
                'uri': condition.condition_uri
            }
        }
开发者ID:lakxraju,项目名称:bigchaindb,代码行数:28,代码来源:util.py

示例10: test_datetime_values

def test_datetime_values(value):
    with pytest.raises(TypeError):
        rapidjson.dumps(value)

    dumped = rapidjson.dumps(value, datetime_mode=rapidjson.DATETIME_MODE_ISO8601)
    loaded = rapidjson.loads(dumped, datetime_mode=rapidjson.DATETIME_MODE_ISO8601)
    assert loaded == value
开发者ID:kenrobbins,项目名称:python-rapidjson,代码行数:7,代码来源:test_params.py

示例11: main

def main():
    """
    """

    # Read command line arguments.
    args = process_command_line()

    # Read the project file 
    projectFileLocation = args.project_file
    f = open(projectFileLocation,'r')
    projectFileString = f.read()
    projectFile = rapidjson.loads(projectFileString)

    if isinstance(projectFile,float):
        raise RuntimeError("could not load project-file json")
    predictor = vp.VoxelPredict(projectFile)



    if args.modus == 'train':
        predictor.doTraining()
    else :
        if args.roiBegin is None or args.roiEnd is None:
            predictor.predict(dataPath=args.data, dataKey=args.key, outPath=args.out)
        else:
            roiBegin = args.roiBegin
            roiEnd = args.roiEnd
            print("ROI ",roiEnd,roiBegin)

            predictor.predictROI(dataPath=args.data, dataKey=args.key, outPath=args.out,
                roiBegin=roiBegin,roiEnd=roiEnd )
    return 0
开发者ID:DerThorsten,项目名称:voxel_prediction,代码行数:32,代码来源:voxel_prediction.py

示例12: test_unicode

 def test_unicode(self):
     text = '"は"'
     rapid_ret = rapidjson.loads(text)
     std_ret = json.loads(text)
     self.assertEqual(std_ret, u"は")
     self.assertEqual(rapid_ret, u"は")
     self.assertEqual(std_ret, rapid_ret)
开发者ID:hhatto,项目名称:pyrapidjson,代码行数:7,代码来源:test_pyrapidjson.py

示例13: read_next

 def read_next(self):
     """
     Read the next line from the file, parse and return. Returns None if out of lines.
     """
     data = self.file.readline().strip()
     if data:
         self.line += 1
     return json.loads(self.decode(data)) if data else None
开发者ID:dpedu2,项目名称:sless,代码行数:8,代码来源:lazyjson.py

示例14: test_doubles

def test_doubles():
    doubles = []

    for x in range(100000):
        d = sys.maxsize * random.random()
        dumped = rapidjson.dumps(d)
        loaded = rapidjson.loads(dumped)
        assert loaded == d
开发者ID:ionelmc,项目名称:cyrapidjson,代码行数:8,代码来源:test_base_types.py

示例15: test_unicode

def test_unicode():
   arabic='بينهم ان يكون مسلما رشيدا عاقلا ًوابنا شرعيا لابوين عمانيين'
   chinese='本站所提供的資料和服務都不收費,因此網站所需要的資金全來自廣告及捐款。若您願意捐款補助'

   for text in [arabic, chinese]:
       dumped = rapidjson.dumps(text)
       loaded = rapidjson.loads(dumped)
       assert text == loaded
开发者ID:ionelmc,项目名称:cyrapidjson,代码行数:8,代码来源:test_base_types.py


注:本文中的rapidjson.loads函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。