當前位置: 首頁>>代碼示例>>Python>>正文


Python builtins.unicode方法代碼示例

本文整理匯總了Python中past.builtins.unicode方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.unicode方法的具體用法?Python builtins.unicode怎麽用?Python builtins.unicode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在past.builtins的用法示例。


在下文中一共展示了builtins.unicode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_import_builtin_types

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def test_import_builtin_types(self):
        code = """
        s1 = 'abcd'
        s2 = u'abcd'
        b1 = b'abcd'
        b2 = s2.encode('utf-8')
        d1 = {}
        d2 = dict((i, i**2) for i in range(10))
        i1 = 1923482349324234L
        i2 = 1923482349324234
        """
        module = self.write_and_import(code, 'test_builtin_types')
        self.assertTrue(isinstance(module.s1, oldstr))
        self.assertTrue(isinstance(module.s2, unicode))
        self.assertTrue(isinstance(module.b1, oldstr)) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:17,代碼來源:test_translation.py

示例2: test_source_coding_utf8

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def test_source_coding_utf8(self):
        """
        Tests to ensure that the source coding line is not corrupted or
        removed. It must be left as the first line in the file (including
        before any __future__ imports). Also tests whether the unicode
        characters in this encoding are parsed correctly and left alone.
        """
        code = """
        # -*- coding: utf-8 -*-
        icons = [u"◐", u"◓", u"◑", u"◒"]
        """
        self.unchanged(code) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:14,代碼來源:test_futurize.py

示例3: test_literal_prefixes_are_not_stripped

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def test_literal_prefixes_are_not_stripped(self):
        """
        Tests to ensure that the u'' and b'' prefixes on unicode strings and
        byte strings are not removed by the futurize script.  Removing the
        prefixes on Py3.3+ is unnecessary and loses some information -- namely,
        that the strings have explicitly been marked as unicode or bytes,
        rather than just e.g. a guess by some automated tool about what they
        are.
        """
        code = '''
        s = u'unicode string'
        b = b'byte string'
        '''
        self.unchanged(code) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:16,代碼來源:test_futurize.py

示例4: test_Py2_StringIO_module

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def test_Py2_StringIO_module(self):
        """
        This requires that the argument to io.StringIO be made a
        unicode string explicitly if we're not using unicode_literals:

        Ideally, there would be a fixer for this. For now:

        TODO: add the Py3 equivalent for this to the docs. Also add back
        a test for the unicode_literals case.
        """
        before = """
        import cStringIO
        import StringIO
        s1 = cStringIO.StringIO('my string')
        s2 = StringIO.StringIO('my other string')
        assert isinstance(s1, cStringIO.InputType)
        """

        # There is no io.InputType in Python 3. futurize should change this to
        # something like this. But note that the input to io.StringIO
        # must be a unicode string on both Py2 and Py3.
        after = """
        import io
        import io
        s1 = io.StringIO(u'my string')
        s2 = io.StringIO(u'my other string')
        assert isinstance(s1, io.StringIO)
        """
        self.convert_check(before, after) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:31,代碼來源:test_futurize.py

示例5: test_open

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def test_open(self):
        """
        In conservative mode, futurize would not import io.open because
        this changes the default return type from bytes to text.
        """
        before = """
        filename = 'temp_file_open.test'
        contents = 'Temporary file contents. Delete me.'
        with open(filename, 'w') as f:
            f.write(contents)

        with open(filename, 'r') as f:
            data = f.read()
        assert isinstance(data, str)
        assert data == contents
        """
        after = """
        from past.builtins import open, str as oldbytes, unicode
        filename = oldbytes(b'temp_file_open.test')
        contents = oldbytes(b'Temporary file contents. Delete me.')
        with open(filename, oldbytes(b'w')) as f:
            f.write(contents)

        with open(filename, oldbytes(b'r')) as f:
            data = f.read()
        assert isinstance(data, oldbytes)
        assert data == contents
        assert isinstance(oldbytes(b'hello'), basestring)
        assert isinstance(unicode(u'hello'), basestring)
        assert isinstance(oldbytes(b'hello'), basestring)
        """
        self.convert_check(before, after, conservative=True) 
開發者ID:hughperkins,項目名稱:kgsgo-dataset-preprocessor,代碼行數:34,代碼來源:test_futurize.py

示例6: _can_handle_key

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def _can_handle_key(self, k):
        return isinstance(k, (str, unicode)) 
開發者ID:tilezen,項目名稱:mapbox-vector-tile,代碼行數:4,代碼來源:encoder.py

示例7: _can_handle_val

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def _can_handle_val(self, v):
        if isinstance(v, (str, unicode)):
            return True
        elif isinstance(v, bool):
            return True
        elif isinstance(v, (int, long)):
            return True
        elif isinstance(v, float):
            return True

        return False 
開發者ID:tilezen,項目名稱:mapbox-vector-tile,代碼行數:13,代碼來源:encoder.py

示例8: _handle_attr

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def _handle_attr(self, layer, feature, props):
        for k, v in props.items():
            if self._can_handle_attr(k, v):
                if not PY3 and isinstance(k, str):
                    k = k.decode('utf-8')

                if k not in self.seen_keys_idx:
                    layer.keys.append(k)
                    self.seen_keys_idx[k] = self.key_idx
                    self.key_idx += 1

                feature.tags.append(self.seen_keys_idx[k])

                if isinstance(v, bool):
                    values_idx = self.seen_values_bool_idx
                else:
                    values_idx = self.seen_values_idx

                if v not in values_idx:
                    values_idx[v] = self.val_idx
                    self.val_idx += 1

                    val = layer.values.add()
                    if isinstance(v, bool):
                        val.bool_value = v
                    elif isinstance(v, str):
                        if PY3:
                            val.string_value = v
                        else:
                            val.string_value = unicode(v, 'utf-8')
                    elif isinstance(v, unicode):
                        val.string_value = v
                    elif isinstance(v, (int, long)):
                        val.int_value = v
                    elif isinstance(v, float):
                        val.double_value = v

                feature.tags.append(values_idx[v]) 
開發者ID:tilezen,項目名稱:mapbox-vector-tile,代碼行數:40,代碼來源:encoder.py

示例9: _handle_attr

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def _handle_attr(self, layer, feature, props):
        for k, v in props.items():
            if self._can_handle_attr(k, v):
                if not PY3 and isinstance(k, str):
                    k = k.decode('utf-8')

                if k not in self.seen_keys_idx:
                    layer.keys.append(k)
                    self.seen_keys_idx[k] = self.key_idx
                    self.key_idx += 1

                feature.tags.append(self.seen_keys_idx[k])

                if v not in self.seen_values_idx:
                    self.seen_values_idx[v] = self.val_idx
                    self.val_idx += 1

                    val = layer.values.add()
                    if isinstance(v, bool):
                        val.bool_value = v
                    elif isinstance(v, str):
                        if PY3:
                            val.string_value = v
                        else:
                            val.string_value = unicode(v, 'utf-8')
                    elif isinstance(v, unicode):
                        val.string_value = v
                    elif isinstance(v, (int, long)):
                        val.int_value = v
                    elif isinstance(v, float):
                        val.double_value = v

                feature.tags.append(self.seen_values_idx[v]) 
開發者ID:enricofer,項目名稱:go2mapillary,代碼行數:35,代碼來源:encoder.py

示例10: received_message

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def received_message(self, message):
        if message.is_text:
            self.runtime.events.put((self.handler.onWSMessage, (self.ws, unicode(message)), {}))
        else:
            self.runtime.events.put((self.handler.onWSBinary, (self.ws, Buffer(message.data)), {})) 
開發者ID:datawire,項目名稱:quark,代碼行數:7,代碼來源:quark_threaded_runtime.py

示例11: parseLevel

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def parseLevel(lvl):
    if isinstance(lvl, (str,unicode)):
        lvl = str(lvl).lower()
    return levelNames.get(lvl, logging.INFO) 
開發者ID:datawire,項目名稱:quark,代碼行數:6,代碼來源:quark_runtime_logging.py

示例12: getType

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def getType(self):
        if isinstance(self.value, dict):
            return 'object'
        elif isinstance(self.value, (list, tuple)):
            return 'list'
        elif isinstance(self.value, (str, unicode)):
            return 'string'
        elif isinstance(self.value, (int,float,long)):
            return 'number'
        elif isinstance(self.value, bool):
            return 'bool'
        elif self.value is None:
            return 'null'
        else:
            raise TypeError("Unknown JSONObject type " + str(type(self.value))) 
開發者ID:datawire,項目名稱:quark,代碼行數:17,代碼來源:quark_runtime.py

示例13: toBase64

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def toBase64(self, buffer, offset, length):
        return unicode(base64.b64encode(buffer.data[offset:offset+length]), "ascii") 
開發者ID:datawire,項目名稱:quark,代碼行數:4,代碼來源:quark_runtime.py

示例14: toVariantArray

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def toVariantArray(lst):
        va = amplpython.VariantArray(len(lst))
        for i in range(len(lst)):
            if isinstance(lst[i], unicode):
                va[i] = amplpython.Variant(str(lst[i]))
                # FIXME: This is just a workaround for issue amplapi#332
                # The real fix requires a new release of amplapi
            else:
                va[i] = amplpython.Variant(lst[i])
        return va 
開發者ID:ampl,項目名稱:amplpy,代碼行數:12,代碼來源:utils.py

示例15: test_generating_cubefile_works

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import unicode [as 別名]
def test_generating_cubefile_works(wfn_viewer):
    wfn_viewer.numpoints = 64
    grid, values = wfn_viewer._calc_orb_grid(wfn_viewer.mol.wfn.orbitals.canonical[1])
    cb = wfn_viewer._grid_to_cube(grid, values)
    assert isinstance(cb, unicode) 
開發者ID:Autodesk,項目名稱:notebook-molecular-visualization,代碼行數:7,代碼來源:test_nbmolviz.py


注:本文中的past.builtins.unicode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。