예제 #1
0
    def loadFromFilesystem(self):
        if os.path.isfile(PROFILE_DIR+'UserProfile/UserProfile.json'):
            # We already have a JSON file. Load the details from the file at the start.
            with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'rb') as f:
                self.__settingsAndProfile = ujson.loads(f.read())

                # Check for old version.
                if 'selectedTopics' in self.__settingsAndProfile:
                    # This is a 1.1.2 JSON file. needs to be migrated.
                    migrationResult = self.__migrateFrom112to120(self.__settingsAndProfile)
                    with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'wb') as f:
                        f.write(ujson.encode(migrationResult))
                    self.__settingsAndProfile = ujson.loads(f.read())
                else:
                    # The main
                    self.__updateBootStatus()
        else:
            # We don't have a JSON file. This means it's not created yet. Create it.
            with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'wb') as f:
            # Now, time to set some defaults.
                newProfileFile = self.__produceProfileWithDefaults()
                newProfileFile['machineDetails']['listeningPort'] = self.__getRandomOpenPort()
                f.write(ujson.encode(newProfileFile))
            # This is the first load ever.
            with open(PROFILE_DIR+'UserProfile/UserProfile.json', 'rb') as f:
                self.__settingsAndProfile = ujson.loads(f.read())
예제 #2
0
def flushcdn():
        
    urlstype = int(request.query.urlstype)
    RawUrls = request.query.urls
    UrlsList = RawUrls.split(",")
    
    urls = ""
    for url in UrlsList:
        urls = urls + url + "|"
    
    urls = urls[:-1] 
    
    print("urls is : %s"%urls)
    
    receive_data_dict = CacheFlush.Flush(urls,urlstype)
    
    timestamp = int(time.time())
    
    if receive_data_dict["head"] == "success":
        redpipe = redata.pipeline()
        
        url_rid_pairs_list = receive_data_dict["body"]
        for item in url_rid_pairs_list:
            for url,rid in item.items():
                redpipe.zadd("CacheFlushingZSet",ujson.encode({rid:url}),timestamp)
                      
        redpipe.execute()
    
    return request.query.jsoncallback + "(" + ujson.encode(receive_data_dict) + ")"
예제 #3
0
 def test_encodeNumericOverflow(self):
     try:
         ujson.encode(12839128391289382193812939)
     except OverflowError:
         pass
     else:
         assert False, "expected OverflowError"
예제 #4
0
파일: tests.py 프로젝트: esnme/ultrajson
 def test_encodeBigEscape(self):
     for x in range(10):
         if six.PY3:
             base = '\u00e5'.encode('utf-8')
         else:
             base = "\xc3\xa5"
         input = base * 1024 * 1024 * 2
         ujson.encode(input)
예제 #5
0
파일: tests.py 프로젝트: stantonk/ultrajson
 def test_encodeDoubleNan(self):
     input = float("nan")
     try:
         ujson.encode(input)
         assert False, "Expected exception!"
     except (OverflowError):
         return
     assert False, "Wrong exception"
예제 #6
0
파일: tests.py 프로젝트: benjamn/ultrajson
    def test_encodeDictWithUnicodeKeys(self):
        input = { u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1" }
        output = ujson.encode(input)

        input = { u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1", u"بن": u"value1" }
        output = ujson.encode(input)

        pass
예제 #7
0
 def test_encodeDoubleNegInf(self):
     input = -float('inf')
     try:
         ujson.encode(input)
         assert False, "Expected exception!"
     except(OverflowError):
         return
     assert False, "Wrong exception"
예제 #8
0
파일: tests.py 프로젝트: warot/ultrajson
    def test_sepcial__json__(self):
        class TestObj(dict):
            def __json__(self):
                return {'hello_new': 'world_new'}

        json = ujson.encode(TestObj())
        self.assertEqual(json, '{"hello_new":"world_new"}')

        json_list = ujson.encode([TestObj()])
        self.assertEqual(json_list, '[{"hello_new":"world_new"}]')
예제 #9
0
파일: tests.py 프로젝트: dignio/ultrajson
 def test_hooks_exceptionHandling(self):
     class TestHookException(Exception):
         pass
     
     call_counters = {
         'pre_encode_hook': 0,
         'string_hook': 0,
         'object_hook': 0,
     }
     
     def pre_encode_hook(_unused_obj):
         call_counters['pre_encode_hook'] += 1
         raise TestHookException()
     
     def string_hook(_unused_obj):
         call_counters['string_hook'] += 1
         raise TestHookException()
     
     def object_hook(_unused_obj):
         call_counters['object_hook'] += 1
         raise TestHookException()
     
     input = {
         'foo': 1,
         'bar': {
             'a': 'a',
             'b': 'b',
         },
     }
     json = """
     {
         "foo": 1,
         "bar": {
             "a": "a",
             "b": "b"
         }
     }
     """
     
     with self.assertRaises(TestHookException):
         ujson.encode(input, pre_encode_hook=pre_encode_hook)
     
     with self.assertRaises(TestHookException):
         ujson.decode(json, string_hook=string_hook)
     
     with self.assertRaises(TestHookException):
         ujson.decode(json, object_hook=object_hook)
     
     # Test not only that the exception is raised, but also that the hook
     # is called only once. I.e. that the low-level code detects the error
     # and stops the iteration process after the first call.    
     self.assertEqual(call_counters['pre_encode_hook'], 1)
     self.assertEqual(call_counters['string_hook'], 1)
     self.assertEqual(call_counters['object_hook'], 1)
예제 #10
0
    def test_toJson(self):
        d = {u"key": 31337}
        json = ujson.encode(d)

        class AlreadyJson:
            def toJson(self):
                return json

        o = AlreadyJson()
        output = ujson.encode(o)
        dec = ujson.decode(output)
        self.assertEquals(dec, d)
예제 #11
0
    def test_encodeNumericOverflowNested(self):
        for n in xrange(0, 100):
            class Nested:
                x = 12839128391289382193812939

            nested = Nested()

            try:
                ujson.encode(nested)
            except OverflowError:
                pass
            else:
                assert False, "expected OverflowError"
예제 #12
0
 def connectionMade(self):
     if len(self.pattern):
         for job in self.pattern:
             if self.byKey.has_key(job) and self.byKey.get(job):
                 self.transport.write("%s\r\n" % ujson.encode({
                     'c': 'reg',
                     'p': {'n': job, 'k': True}
                 }));
             else:
                 self.transport.write("%s\r\n" % ujson.encode({
                     'c': 'reg',
                     'p': {'n': job, 'k': False}
                 }));
예제 #13
0
    def test_encodeUTF8EncodedString(self):
        unicode_str = u"مرحبا العالم Salam dünya Прывітанне свет Здравей, свят"
        utf_str = unicode_str.encode('utf-8')

        encoded_from_unicode = ujson.encode(unicode_str)
        encoded_from_utf_str = ujson.encode(utf_str)

        self.assertEqual(encoded_from_unicode, encoded_from_utf_str)

        encoded_from_unicode = ujson.encode(unicode_str, ensure_ascii=False)
        encoded_from_utf_str = ujson.encode(utf_str, ensure_ascii=False)

        self.assertEqual(encoded_from_unicode, encoded_from_utf_str)
예제 #14
0
    def test_doublePrecisionTest(self):
        input = 30.012345678901234
        output = ujson.encode(input, double_precision = 15)
        self.assertEqual(input, json.loads(output))
        self.assertEqual(input, ujson.decode(output))

        output = ujson.encode(input, double_precision = 9)
        self.assertEqual(round(input, 9), json.loads(output))
        self.assertEqual(round(input, 9), ujson.decode(output))

        output = ujson.encode(input, double_precision = 3)
        self.assertEqual(round(input, 3), json.loads(output))
        self.assertEqual(round(input, 3), ujson.decode(output))
예제 #15
0
    def test_encodeNullCharacter(self):
        input = "31337 \x00 1337"
        output = ujson.encode(input)
        self.assertEqual(input, json.loads(output))
        self.assertEqual(output, json.dumps(input))
        self.assertEqual(input, ujson.decode(output))

        input = "\x00"
        output = ujson.encode(input)
        self.assertEqual(input, json.loads(output))
        self.assertEqual(output, json.dumps(input))
        self.assertEqual(input, ujson.decode(output))

        self.assertEqual('"  \\u0000\\r\\n "', ujson.dumps(u"  \u0000\r\n "))
예제 #16
0
 def test_encodeUnicode4BytesUTF8Fail(self):
     input = b"\xfd\xbf\xbf\xbf\xbf\xbf"
     try:
         enc = ujson.encode(input)
         assert False, "Expected exception"
     except OverflowError:
         pass
예제 #17
0
    def test_encodeLongUnsignedConversion(self):
        input = 18446744073709551615
        output = ujson.encode(input)

        self.assertEquals(input, json.loads(output))
        self.assertEquals(output, json.dumps(input))
        self.assertEquals(input, ujson.decode(output))
예제 #18
0
    def test_encodeUnicode4BytesUTF8Highest(self):
        input = "\xf3\xbf\xbf\xbfTRAILINGNORMAL"
        enc = ujson.encode(input)
        dec = ujson.decode(enc)

        self.assertEqual(enc, json_unicode(input))
        self.assertEqual(dec, json.loads(enc))
예제 #19
0
 def test_encodeDatetimeConversion(self):
     ts = time.time()
     input = datetime.datetime.fromtimestamp(ts)
     output = ujson.encode(input)
     expected = calendar.timegm(input.utctimetuple())
     self.assertEqual(int(expected), json.loads(output))
     self.assertEqual(int(expected), ujson.decode(output))
예제 #20
0
    def test_encodeArrayInArray(self):
        input = [[[[]]]]
        output = ujson.encode(input)

        self.assertEqual(input, json.loads(output))
        self.assertEqual(output, json.dumps(input))
        self.assertEqual(input, ujson.decode(output))
예제 #21
0
    def test_encodeUnicodeSurrogatePair(self):
        input = "\xf0\x90\x8d\x86"
        enc = ujson.encode(input)
        dec = ujson.decode(enc)

        self.assertEqual(enc, json_unicode(input))
        self.assertEqual(dec, json.loads(enc))
예제 #22
0
파일: tests.py 프로젝트: benjamn/ultrajson
 def test_encodeLongConversion(self):
     input = 9223372036854775807
     output = ujson.encode(input)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(output, json.dumps(input))
     self.assertEquals(input, ujson.decode(output))
     pass
예제 #23
0
    def test_encodeUnicode4BytesUTF8(self):
        input = "\xf0\x91\x80\xb0TRAILINGNORMAL"
        enc = ujson.encode(input)
        dec = ujson.decode(enc)

        self.assertEqual(enc, json_unicode(input))
        self.assertEqual(dec, json.loads(enc))
예제 #24
0
    def test_encodeSet(self):
        s = set([1,2,3,4,5,6,7,8,9])
        enc = ujson.encode(s)
        dec = ujson.decode(enc)

        for v in dec:
            self.assertTrue(v in s)
예제 #25
0
파일: tests.py 프로젝트: benjamn/ultrajson
 def test_encodeFalseConversion(self):
     input = False
     output = ujson.encode(input)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(output, json.dumps(input))
     self.assertEquals(input, ujson.decode(output))
     pass
예제 #26
0
파일: tests.py 프로젝트: benjamn/ultrajson
 def test_encodeIntNegConversion(self):
     input = -31337
     output = ujson.encode(input)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(output, json.dumps(input))
     self.assertEquals(input, ujson.decode(output))
     pass
예제 #27
0
    def test_invalidDoublePrecision(self):
        input = 30.12345678901234567890
        output = ujson.encode(input, double_precision = 20)
        # should snap to the max, which is 15
        self.assertEqual(round(input, 15), json.loads(output))
        self.assertEqual(round(input, 15), ujson.decode(output))

        output = ujson.encode(input, double_precision = -1)
        # also should snap to the max, which is 15
        self.assertEqual(round(input, 15), json.loads(output))
        self.assertEqual(round(input, 15), ujson.decode(output))

        # will throw typeError
        self.assertRaises(TypeError, ujson.encode, input, double_precision = '9')
        # will throw typeError
        self.assertRaises(TypeError, ujson.encode, input, double_precision = None)
예제 #28
0
 def connectionMade(self):
     if len(self.pattern):
         for job in self.pattern:
             self.transport.write("%s\r\n" % ujson.encode({
                 'c': 'reg',
                 'p': {'n': job}
             }));
예제 #29
0
파일: tests.py 프로젝트: stantonk/ultrajson
 def test_encodeStringConversion(self):
     input = "A string \\ / \b \f \n \r \t"
     output = ujson.encode(input)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(output, '"A string \\\\ \\/ \\b \\f \\n \\r \\t"')
     self.assertEquals(input, ujson.decode(output))
     pass
예제 #30
0
파일: tests.py 프로젝트: benjamn/ultrajson
 def test_encodeDictConversion(self):
     input = { "k1": 1, "k2":  2, "k3": 3, "k4": 4 }
     output = ujson.encode(input)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(input, ujson.decode(output))
     self.assertEquals(input, ujson.decode(output))
     pass
예제 #31
0
        else:
            PathList.append(Tpath)

    if QuitFlag == False:
        try:
            #调用刷新类
            PurgeCacheObj =  exeCachePurge(UrlType,PathList,DomainName,LogKeyName)
            PurgeCacheObj.start()
        except Exception,e:
            DataDict =  {'success':'0','text':'%s'%e}
        else:
            DataDict =  {'success':'1'}
    else:
        DataDict = {'success':'0','text':'刷新的URLS需是同域名同类型的!'}    
              
    return prefix+"("+ujson.encode(DataDict)+")"  

@route('/getstdout',method="GET")
def getStdout ():
    prefix = request.query.jsoncallback
    keyname = "key"+str(request.query.key)
    redispool = redis.ConnectionPool(host=RedisIP,port=RedisPort,db=RedisDB)
    redata = redis.Redis(connection_pool=redispool)
    line = redata.blpop(keyname,245)
    if line == None:
        DataDict = {"success":'0'}
    else:
        DataDict = {"success":'1','text':line[1]}
    return prefix+"("+ujson.encode(DataDict)+")"
    sys.exit()
예제 #32
0
 def test_encodeToUTF8(self):
     input = "\xe6\x97\xa5\xd1\x88"
     enc = ujson.encode(input, ensure_ascii=False)
     dec = ujson.decode(enc)
     self.assertEquals(enc, json_unicode(input, ensure_ascii=False))
     self.assertEquals(dec, json.loads(enc))
예제 #33
0
 def test_encodeDecimal(self):
     sut = decimal.Decimal("1337.1337")
     encoded = ujson.encode(sut, double_precision=100)
     decoded = ujson.decode(encoded)
     self.assertEquals(decoded, 1337.1337)
예제 #34
0
    def test_encodeDoubleNegConversion(self):
        input = -math.pi
        output = ujson.encode(input)

        self.assertEqual(round(input, 5), round(json.loads(output), 5))
        self.assertEqual(round(input, 5), round(ujson.decode(output), 5))
예제 #35
0
 def test_encodeUnicodeConversion1(self):
     input = "Räksmörgås اسامة بن محمد بن عوض بن لادن"
     enc = ujson.encode(input)
     dec = ujson.decode(enc)
     self.assertEqual(enc, json_unicode(input))
     self.assertEqual(dec, json.loads(enc))
예제 #36
0
 def test_encodeIntNegConversion(self):
     input = -31337
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
예제 #37
0
 def test_encodeLongConversion(self):
     input = 9223372036854775807
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
예제 #38
0
    def test_encodeOrderedDict(self):
        from collections import OrderedDict

        input = OrderedDict([(1, 1), (0, 0), (8, 8), (2, 2)])
        self.assertEqual('{"1":1,"0":0,"8":8,"2":2}', ujson.encode(input))
예제 #39
0
파일: tests.py 프로젝트: segfault/ultrajson
 def test_decimalDecodeTest(self):
     sut = {'a': 4.56}
     encoded = ujson.encode(sut)
     decoded = ujson.decode(encoded)
     self.assertAlmostEqual(sut[u'a'], decoded[u'a'])
예제 #40
0
 def test_encodeFalseConversion(self):
     input = False
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
예제 #41
0
 def test_encodeDictConversion(self):
     input = {"k1": 1, "k2": 2, "k3": 3, "k4": 4}
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(input, ujson.decode(output))
     self.assertEqual(input, ujson.decode(output))
예제 #42
0
 def test_encodeListConversion(self):
     input = [1, 2, 3, 4]
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(input, ujson.decode(output))
예제 #43
0
 def test_encodeUnicodeConversion2(self):
     input = "\xe6\x97\xa5\xd1\x88"
     enc = ujson.encode(input)
     dec = ujson.decode(enc)
     self.assertEqual(enc, json_unicode(input))
     self.assertEqual(dec, json.loads(enc))
예제 #44
0
 def test_encodeDecimal(self):
     sut = decimal.Decimal("1337.1337")
     encoded = ujson.encode(sut)
     decoded = ujson.decode(encoded)
     self.assertEqual(decoded, 1337.1337)
예제 #45
0
파일: tests.py 프로젝트: segfault/ultrajson
 def __json__(self):
     return ujson.encode(obj)
예제 #46
0
 def test_encodeControlEscaping(self):
     input = "\x19"
     enc = ujson.encode(input)
     dec = ujson.decode(enc)
     self.assertEqual(input, dec)
     self.assertEqual(enc, json_unicode(input))
예제 #47
0
def test_ujson_roundtrip(obj, kwargs):
    """Check that all JSON objects round-trip regardless of other options."""
    assert obj == ujson.decode(ujson.encode(obj, **kwargs))
예제 #48
0
 def test_encodeArrayOfDoubles(self):
     input = [31337.31337, 31337.31337, 31337.31337, 31337.31337] * 10
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     # self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
예제 #49
0
        # --/
        #     调用handleoffset.sh脚本,对视频进行预处理
        # --/

        cmd = "cd /tmp/%s/ && /bin/sh %s/handleoffset.sh %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s"
        cmdstr = cmd % (vid, myselfdir, VideoFilePath, vid, OriginVideoFormat,
                        PartNums, BlockSizeSecondNum, VideoDuration, VFlag,
                        BitRate, VideoBitRate, VideoCode, AudioBitRate,
                        AudioCode, AudioSampleRate, AudioChannels, myselfdir)
        RunCmdObj.run([cmdstr])

        ShellReturnDict = json.loads(RunCmdObj.stdout[0].strip())

        logger.info("shell return dict is : %s" %
                    (ujson.encode(ShellReturnDict)))

        if ShellReturnDict["IsHaveStream"] == "YES":
            break
        else:
            logger.debug("Now ,ready to delete files in /tmp/%s/avfiles/*" %
                         (vid))
            RunCmdObj.run(["rm -f /tmp/%s/avfiles/*" % (vid)])

    NewVideoFormat = ShellReturnDict["suffix"]
    VideoBitRate = int(ShellReturnDict["vb"])
    AudioBitRate = int(ShellReturnDict["ab"])
    PartNums = int(ShellReturnDict["RealPartNums"])

    logger.debug("Shell return data :   \n \
                  New video format : %s \n \
예제 #50
0
 def test_encodeStringConversion2(self):
     input = "A string \\ / \b \f \n \r \t"
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, '"A string \\\\ \\/ \\b \\f \\n \\r \\t"')
     self.assertEqual(input, ujson.decode(output))
예제 #51
0
 def handle_store(self, files):
     self.add_ajax_response(json.encode(self.store(files)))
예제 #52
0
 def test_encodeArrayOfNestedArrays(self):
     input = [[[[]]]] * 20
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     # self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
예제 #53
0
 def test_encodeEmptySet(self):
     s = set()
     self.assertEquals("[]", ujson.encode(s))
예제 #54
0
파일: server.py 프로젝트: bmcfee/graffw
def get_track_analysis(track_id):
    return json.encode(data_layer.get_track_analysis(track_id))
예제 #55
0
 def test_decimalDecodeTestPrecise(self):
     sut = {u'a': 4.56}
     encoded = ujson.encode(sut)
     decoded = ujson.decode(encoded, precise_float=True)
     self.assertEqual(sut, decoded)
예제 #56
0
 def test_encodeWithDecimal(self):
     input = 1.0
     output = ujson.encode(input)
     self.assertEqual(output, "1.0")
예제 #57
0
 def test_decimalDecodeTest(self):
     sut = {u'a': 4.56}
     encoded = ujson.encode(sut)
     decoded = ujson.decode(encoded)
     self.assertNotEqual(sut, decoded)
예제 #58
0
 def helper(expected_output, **encode_kwargs):
     output = ujson.encode(input, **encode_kwargs)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(output, expected_output)
     self.assertEquals(input, ujson.decode(output))
예제 #59
0
 def helper(expected_output, **encode_kwargs):
     output = ujson.encode(input, **encode_kwargs)
     self.assertEqual(output, expected_output)
     if encode_kwargs.get("escape_forward_slashes", True):
         self.assertEqual(input, json.loads(output))
         self.assertEqual(input, ujson.decode(output))
예제 #60
0
 def test_encodeBigSet(self):
     s = set()
     for x in xrange(0, 100000):
         s.add(x)
     ujson.encode(s)