Python simplejson.encoder.c_make_encoder() Examples

The following are code examples for showing how to use simplejson.encoder.c_make_encoder(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_speedups.py    MIT License 6 votes vote down vote up
def test_bad_str_encoder(self):
        # Issue #31505: There shouldn't be an assertion failure in case
        # c_make_encoder() receives a bad encoder() argument.
        import decimal
        def bad_encoder1(*args):
            return None
        enc = encoder.c_make_encoder(
                None, lambda obj: str(obj),
                bad_encoder1, None, ': ', ', ',
                False, False, False, {}, False, False, False,
                None, None, 'utf-8', False, False, decimal.Decimal, False)
        self.assertRaises(TypeError, enc, 'spam', 4)
        self.assertRaises(TypeError, enc, {'spam': 42}, 4)

        def bad_encoder2(*args):
            1/0
        enc = encoder.c_make_encoder(
                None, lambda obj: str(obj),
                bad_encoder2, None, ': ', ', ',
                False, False, False, {}, False, False, False,
                None, None, 'utf-8', False, False, decimal.Decimal, False)
        self.assertRaises(ZeroDivisionError, enc, 'spam', 4) 
Example 2
Project: fund   Author: Frank-qlu   File: test_speedups.py    Apache License 2.0 6 votes vote down vote up
def test_bad_str_encoder(self):
        # Issue #31505: There shouldn't be an assertion failure in case
        # c_make_encoder() receives a bad encoder() argument.
        import decimal
        def bad_encoder1(*args):
            return None
        enc = encoder.c_make_encoder(
                None, lambda obj: str(obj),
                bad_encoder1, None, ': ', ', ',
                False, False, False, {}, False, False, False,
                None, None, 'utf-8', False, False, decimal.Decimal, False)
        self.assertRaises(TypeError, enc, 'spam', 4)
        self.assertRaises(TypeError, enc, {'spam': 42}, 4)

        def bad_encoder2(*args):
            1/0
        enc = encoder.c_make_encoder(
                None, lambda obj: str(obj),
                bad_encoder2, None, ': ', ', ',
                False, False, False, {}, False, False, False,
                None, None, 'utf-8', False, False, decimal.Decimal, False)
        self.assertRaises(ZeroDivisionError, enc, 'spam', 4) 
Example 3
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_speedups.py    MIT License 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 4
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_speedups.py    MIT License 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 5
Project: tra-tracking-on-gae   Author: elliot79313   File: test_speedups.py    MIT License 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 6
Project: tra-tracking-on-gae   Author: elliot79313   File: test_speedups.py    MIT License 5 votes vote down vote up
def test_make_encoder(self):
        if not has_speedups():
            return
        self.assertRaises(TypeError, encoder.c_make_encoder,
            None,
            "\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
            None) 
Example 7
Project: ableton-live-webapi   Author: valsteen   File: test_speedups.py    The Unlicense 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 8
Project: ableton-live-webapi   Author: valsteen   File: test_speedups.py    The Unlicense 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 9
Project: Bitly-Symbian   Author: gauravssnl   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def _toggle_speedups(enabled):
    import simplejson.decoder as dec
    import simplejson.encoder as enc
    import simplejson.scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii or 
            enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner
    dec.make_scanner = scan.make_scanner
    global _default_decoder
    _default_decoder = JSONDecoder(
        encoding=None,
        object_hook=None,
        object_pairs_hook=None,
    )
    global _default_encoder
    _default_encoder = JSONEncoder(
       skipkeys=False,
       ensure_ascii=True,
       check_circular=True,
       allow_nan=True,
       indent=None,
       separators=None,
       encoding='utf-8',
       default=None,
   ) 
Example 10
Project: fund   Author: Frank-qlu   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 11
Project: fund   Author: Frank-qlu   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 12
Project: oscars2016   Author: 0x0ece   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 13
Project: oscars2016   Author: 0x0ece   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 14
Project: that-startpage-rocks   Author: the-duck   File: test_speedups.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 15
Project: that-startpage-rocks   Author: the-duck   File: test_speedups.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 16
Project: cohesive-networks-vns3-vpn-monitoring   Author: trek10inc   File: test_speedups.py    MIT License 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 17
Project: cohesive-networks-vns3-vpn-monitoring   Author: trek10inc   File: test_speedups.py    MIT License 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 18
Project: download-manager   Author: thispc   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _toggle_speedups(enabled):
    import simplejson.decoder as dec
    import simplejson.encoder as enc
    import simplejson.scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii or 
            enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner
    dec.make_scanner = scan.make_scanner
    global _default_decoder
    _default_decoder = JSONDecoder(
        encoding=None,
        object_hook=None,
        object_pairs_hook=None,
    )
    global _default_encoder
    _default_encoder = JSONEncoder(
       skipkeys=False,
       ensure_ascii=True,
       check_circular=True,
       allow_nan=True,
       indent=None,
       separators=None,
       encoding='utf-8',
       default=None,
   ) 
Example 19
Project: node-gn   Author: Shouqun   File: __init__.py    MIT License 5 votes vote down vote up
def _toggle_speedups(enabled):
    import simplejson.decoder as dec
    import simplejson.encoder as enc
    import simplejson.scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii or 
            enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner
    dec.make_scanner = scan.make_scanner
    global _default_decoder
    _default_decoder = JSONDecoder(
        encoding=None,
        object_hook=None,
        object_pairs_hook=None,
    )
    global _default_encoder
    _default_encoder = JSONEncoder(
       skipkeys=False,
       ensure_ascii=True,
       check_circular=True,
       allow_nan=True,
       indent=None,
       separators=None,
       encoding='utf-8',
       default=None,
   ) 
Example 20
Project: alfredToday   Author: jeeftor   File: test_speedups.py    MIT License 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 21
Project: alfredToday   Author: jeeftor   File: test_speedups.py    MIT License 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 22
Project: old-dotfiles   Author: hawkw   File: test_speedups.py    MIT License 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 23
Project: old-dotfiles   Author: hawkw   File: test_speedups.py    MIT License 5 votes vote down vote up
def test_make_encoder(self):
        if not has_speedups():
            return
        self.assertRaises(TypeError, encoder.c_make_encoder,
            None,
            "\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
            None) 
Example 24
Project: pureapp   Author: samisalkosuo   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 25
Project: pureapp   Author: samisalkosuo   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 26
Project: pureapp   Author: samisalkosuo   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 27
Project: pureapp   Author: samisalkosuo   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        ) 
Example 28
Project: CodeDepot   Author: CodedepotOSS   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _toggle_speedups(enabled):
    import simplejson.decoder as dec
    import simplejson.encoder as enc
    import simplejson.scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii or
            enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner
    dec.make_scanner = scan.make_scanner
    global _default_decoder
    _default_decoder = JSONDecoder(
        encoding=None,
        object_hook=None,
        object_pairs_hook=None,
    )
    global _default_encoder
    _default_encoder = JSONEncoder(
       skipkeys=False,
       ensure_ascii=True,
       check_circular=True,
       allow_nan=True,
       indent=None,
       separators=None,
       encoding='utf-8',
       default=None,
   ) 
Example 29
Project: syntheticmass   Author: synthetichealth   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def has_speedups():
    return encoder.c_make_encoder is not None 
Example 30
Project: syntheticmass   Author: synthetichealth   File: test_speedups.py    Apache License 2.0 5 votes vote down vote up
def test_make_encoder(self):
        self.assertRaises(
            TypeError,
            encoder.c_make_encoder,
            None,
            ("\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7"
             "\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
            None
        )