当前位置: 首页>>代码示例>>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;未经允许,请勿转载。