Python codecs.utf_8_encode() Examples

The following are 30 code examples of codecs.utf_8_encode(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module codecs , or try the search function .
Example #1
Source File: utf_8_sig.py    From scylla with Apache License 2.0 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #2
Source File: utf_8.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0] 
Example #3
Source File: utf_8_sig.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0], len(input)) 
Example #4
Source File: utf_8_sig.py    From python2017 with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        if self.first:
            self.first = 0
            return codecs.BOM_UTF8 + \
                   codecs.utf_8_encode(input, self.errors)[0]
        else:
            return codecs.utf_8_encode(input, self.errors)[0] 
Example #5
Source File: utf_8_sig.py    From python2017 with MIT License 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #6
Source File: utf_8_sig.py    From python2017 with MIT License 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0],
            len(input)) 
Example #7
Source File: utf_8_sig.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0], len(input)) 
Example #8
Source File: utf_8.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0] 
Example #9
Source File: utf_8_sig.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #10
Source File: utf_8_sig.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        if self.first:
            self.first = 0
            return codecs.BOM_UTF8 + codecs.utf_8_encode(input, self.errors)[0]
        else:
            return codecs.utf_8_encode(input, self.errors)[0] 
Example #11
Source File: utf_8_sig.py    From ImageFusion with MIT License 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #12
Source File: utf_8_sig.py    From telegram-robot-rss with Mozilla Public License 2.0 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #13
Source File: utf_8_sig.py    From telegram-robot-rss with Mozilla Public License 2.0 5 votes vote down vote up
def encode(self, input, final=False):
        if self.first:
            self.first = 0
            return codecs.BOM_UTF8 + codecs.utf_8_encode(input, self.errors)[0]
        else:
            return codecs.utf_8_encode(input, self.errors)[0] 
Example #14
Source File: utf_8_sig.py    From telegram-robot-rss with Mozilla Public License 2.0 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0], len(input)) 
Example #15
Source File: utf_8.py    From scylla with Apache License 2.0 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0] 
Example #16
Source File: utf_8.py    From telegram-robot-rss with Mozilla Public License 2.0 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0] 
Example #17
Source File: utf_8_sig.py    From scylla with Apache License 2.0 5 votes vote down vote up
def encode(self, input, final=False):
        if self.first:
            self.first = 0
            return codecs.BOM_UTF8 + \
                   codecs.utf_8_encode(input, self.errors)[0]
        else:
            return codecs.utf_8_encode(input, self.errors)[0] 
Example #18
Source File: utf_8_sig.py    From scylla with Apache License 2.0 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0],
            len(input)) 
Example #19
Source File: utf_8.py    From Imogen with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0] 
Example #20
Source File: utf_8_sig.py    From Imogen with MIT License 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #21
Source File: utf_8_sig.py    From Imogen with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        if self.first:
            self.first = 0
            return codecs.BOM_UTF8 + \
                   codecs.utf_8_encode(input, self.errors)[0]
        else:
            return codecs.utf_8_encode(input, self.errors)[0] 
Example #22
Source File: utf_8_sig.py    From Imogen with MIT License 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0],
            len(input)) 
Example #23
Source File: test_client.py    From naz with MIT License 5 votes vote down vote up
def test_custom_encodings(self):
        """
        tests that any of the encodings allowed by SMPP spec[1] can be used.
        1. https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/state.py#L328
        2. Also see section 5.2.19 of SMPP spec
        """

        class ExampleCodec(codecs.Codec):
            # All the methods have to be staticmethods because they are passed to `codecs.CodecInfo`
            @staticmethod
            def encode(input, errors="strict"):
                return codecs.utf_8_encode(input, errors)

            @staticmethod
            def decode(input, errors="strict"):
                return codecs.utf_8_decode(input, errors)

        for encoding in ["gsm0338", "ucs2", "ascii", "latin_1", "iso2022jp", "iso8859_5"]:
            naz.Client(
                smsc_host="127.0.0.1",
                smsc_port=2775,
                system_id="smppclient1",
                password=os.getenv("password", "password"),
                broker=self.broker,
                logger=naz.log.SimpleLogger(
                    "TestClient", level="DEBUG", handler=naz.log.BreachHandler(capacity=10)
                ),
                socket_timeout=self.socket_timeout,
                custom_codecs={
                    encoding: codecs.CodecInfo(
                        name=encoding, encode=ExampleCodec.encode, decode=ExampleCodec.decode,
                    ),
                },
            ) 
Example #24
Source File: test_codec.py    From naz with MIT License 5 votes vote down vote up
def test_codec_overriding(self):
        """
        tests that users can be able to override an inbuilt codec
        with their own implementation.
        """

        class OverridingCodec(codecs.Codec):
            # All the methods have to be staticmethods because they are passed to `codecs.CodecInfo`
            @staticmethod
            def encode(input, errors="strict"):
                return codecs.utf_8_encode(input, errors)

            @staticmethod
            def decode(input, errors="strict"):
                return codecs.utf_8_decode(input, errors)

        custom_codecs = {
            "gsm0338": codecs.CodecInfo(
                name="gsm0338", encode=OverridingCodec.encode, decode=OverridingCodec.decode,
            ),
        }

        # register, this will override inbuilt `gsm0338` codec with a custom one.
        naz.codec.register_codecs(custom_codecs)

        new_codec = codecs.lookup("gsm0338")
        self.assertNotEqual(new_codec.encode, naz.codec.GSM7BitCodec.encode)
        self.assertNotEqual(new_codec.decode, naz.codec.GSM7BitCodec.decode)
        self.assertEqual(new_codec.encode, OverridingCodec.encode)
        self.assertEqual(new_codec.decode, OverridingCodec.decode) 
Example #25
Source File: test_codec.py    From naz with MIT License 5 votes vote down vote up
def test_registration_of_custom_codecs(self):
        _sheng_encoding = "kenyan_sheng"
        with self.assertRaises(LookupError):
            codecs.lookup(_sheng_encoding)

        class KenyanShengCodec(codecs.Codec):
            # All the methods have to be staticmethods because they are passed to `codecs.CodecInfo`
            @staticmethod
            def encode(input, errors="strict"):
                return codecs.utf_8_encode(input, errors)

            @staticmethod
            def decode(input, errors="strict"):
                return codecs.utf_8_decode(input, errors)

        custom_codecs = {
            _sheng_encoding: codecs.CodecInfo(
                name=_sheng_encoding,
                encode=KenyanShengCodec.encode,
                decode=KenyanShengCodec.decode,
            ),
        }

        # register
        naz.codec.register_codecs(custom_codecs)

        codec = codecs.lookup(_sheng_encoding)
        self.assertEqual(codec.name, _sheng_encoding) 
Example #26
Source File: utf_8.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0] 
Example #27
Source File: utf_8_sig.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def encode(self, input, errors='strict'):
        self.encode = codecs.utf_8_encode
        return encode(input, errors) 
Example #28
Source File: utf_8_sig.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def encode(self, input, final=False):
        if self.first:
            self.first = 0
            return codecs.BOM_UTF8 + \
                   codecs.utf_8_encode(input, self.errors)[0]
        else:
            return codecs.utf_8_encode(input, self.errors)[0] 
Example #29
Source File: utf_8_sig.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def encode(input, errors='strict'):
    return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0],
            len(input)) 
Example #30
Source File: utf_8.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def encode(self, input, final=False):
        return codecs.utf_8_encode(input, self.errors)[0]