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


Python types.UnicodeType方法代碼示例

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


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

示例1: open

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def open(self, fullurl, data=None):
        # accept a URL or a Request object
        if isinstance(fullurl, (types.StringType, types.UnicodeType)):
            req = Request(fullurl, data)
        else:
            req = fullurl
            if data is not None:
                req.add_data(data)
        assert isinstance(req, Request) # really only care about interface

        result = self._call_chain(self.handle_open, 'default',
                                  'default_open', req)
        if result:
            return result

        type_ = req.get_type()
        result = self._call_chain(self.handle_open, type_, type_ + \
                                  '_open', req)
        if result:
            return result

        return self._call_chain(self.handle_open, 'unknown',
                                'unknown_open', req) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:25,代碼來源:urllib2.py

示例2: test_unicode

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def test_unicode(self):

        if not test_support.have_unicode: return

        # The StringIO module also supports concatenating Unicode
        # snippets to larger Unicode strings. This is tested by this
        # method. Note that cStringIO does not support this extension.

        f = self.MODULE.StringIO()
        f.write(self._line[:6])
        f.seek(3)
        f.write(unicode(self._line[20:26]))
        f.write(unicode(self._line[52]))
        s = f.getvalue()
        self.assertEqual(s, unicode('abcuvwxyz!'))
        self.assertEqual(type(s), types.UnicodeType) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_StringIO.py

示例3: runsource

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def runsource(self, source):
        "Extend base class method: Stuff the source in the line cache first"
        filename = self.stuffsource(source)
        self.more = 0
        self.save_warnings_filters = warnings.filters[:]
        warnings.filterwarnings(action="error", category=SyntaxWarning)
        if isinstance(source, types.UnicodeType):
            from idlelib import IOBinding
            try:
                source = source.encode(IOBinding.encoding)
            except UnicodeError:
                self.tkconsole.resetoutput()
                self.write("Unsupported characters in input\n")
                return
        try:
            # InteractiveInterpreter.runsource() calls its runcode() method,
            # which is overridden (see below)
            return InteractiveInterpreter.runsource(self, source, filename)
        finally:
            if self.save_warnings_filters is not None:
                warnings.filters[:] = self.save_warnings_filters
                self.save_warnings_filters = None 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:24,代碼來源:PyShell.py

示例4: writexml

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def writexml(self, stream, indent='', addindent='', newl='', strip=0,
                 nsprefixes={}, namespace=''):
        if self.raw:
            val = self.nodeValue
            if not isinstance(val, StringTypes):
                val = str(self.nodeValue)
        else:
            v = self.nodeValue
            if not isinstance(v, StringTypes):
                v = str(v)
            if strip:
                v = ' '.join(v.split())
            val = escape(v)
        if isinstance(val, UnicodeType):
            val = val.encode('utf8')
        stream.write(val) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:microdom.py

示例5: translate_to_dbus_type

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def translate_to_dbus_type(typeof, value):
    """
    Helper function to map values from their native Python types
    to Dbus types.

    :param type typeof: Target for type conversion e.g., 'dbus.Dictionary'
    :param value: Value to assign using type 'typeof'
    :return: 'value' converted to type 'typeof'
    :rtype: typeof
    """
    if ((isinstance(value, types.UnicodeType) or
         isinstance(value, str)) and typeof is not dbus.String):
        # FIXME: This is potentially dangerous since it evaluates
        # a string in-situ
        return typeof(eval(value))
    else:
        return typeof(value) 
開發者ID:liamw9534,項目名稱:bt-manager,代碼行數:19,代碼來源:interface.py

示例6: __init__

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def __init__(self, streamOrFile=None, parent=None):
        """
        Initializes an instance.

        @param streamOrFile: If specified, causes this instance to be loaded
        from the stream (by calling L{load}). If a string is provided, it is
        passed to L{streamOpener} to open a stream. Otherwise, the passed
        value is assumed to be a stream and used as is.
        @type streamOrFile: A readable stream (file-like object) or a name.
        @param parent: If specified, this becomes the parent of this instance
        in the configuration hierarchy.
        @type parent: a L{Container} instance.
        """
        Mapping.__init__(self, parent)
        object.__setattr__(self, 'reader', ConfigReader(self))
        object.__setattr__(self, 'namespaces', [Config.Namespace()])
        object.__setattr__(self, 'resolving', set())
        if streamOrFile is not None:
            if isinstance(streamOrFile, StringType) or isinstance(streamOrFile, UnicodeType):
                global streamOpener
                if streamOpener is None:
                    streamOpener = defaultStreamOpener
                streamOrFile = streamOpener(streamOrFile)
            load = object.__getattribute__(self, "load")
            load(streamOrFile) 
開發者ID:twitterdev,項目名稱:twitter-for-bigquery,代碼行數:27,代碼來源:config.py

示例7: simpleJustifyAlign

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def simpleJustifyAlign(line, currentLength, maxLength):
    "simple justification with only strings"

    strings = []
    for x in line[:-1]:
        if type(x) in (StringType, UnicodeType):
            strings.append(x)
    nspaces = len(strings)-1
    slack = maxLength-currentLength
    text = ' '.join(strings)
    if nspaces>0 and slack>0:
        wordspacing = slack/float(nspaces)
        result = [("wordSpacing", wordspacing), text, maxLength, ("wordSpacing", 0)]
    else:
        result = [text, currentLength, ("nextLine", 0)]
    nextlinemark = ("nextLine", 0)
    if line and line[-1]==nextlinemark:
        result.append( nextlinemark )
    return result 
開發者ID:gltn,項目名稱:stdm,代碼行數:21,代碼來源:para.py

示例8: compile_ul

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def compile_ul(self, attdict, content, extra, program, tagname="ul"):
        # by transformation
        #print "compile", tagname, attdict
        atts = attdict.copy()
        bulletmaker = bulletMaker(tagname, atts, self.context)
        # now do each element as a separate paragraph
        for e in content:
            te = type(e)
            if te in (StringType, UnicodeType):
                if e.strip():
                    raise ValueError, "don't expect CDATA between list elements"
            elif te is TupleType:
                (tagname, attdict1, content1, extra) = e
                if tagname!="li":
                    raise ValueError, "don't expect %s inside list" % repr(tagname)
                newatts = atts.copy()
                if attdict1:
                    newatts.update(attdict1)
                bulletmaker.makeBullet(newatts)
                self.compile_para(newatts, content1, extra, program) 
開發者ID:gltn,項目名稱:stdm,代碼行數:22,代碼來源:para.py

示例9: getMessage

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def getMessage(self):
        """
        Return the message for this LogRecord.

        Return the message for this LogRecord after merging any user-supplied
        arguments with the message.
        """
        if not hasattr(types, "UnicodeType"): #if no unicode support...
            msg = str(self.msg)
        else:
            msg = self.msg
            if type(msg) not in (types.UnicodeType, types.StringType):
                try:
                    msg = str(self.msg)
                except UnicodeError:
                    msg = self.msg      #Defer encoding till later
        if self.args:
            msg = msg % self.args
        return msg 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:21,代碼來源:__init__.py

示例10: emit

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def emit(self, record):
        """
        Emit a record.

        If a formatter is specified, it is used to format the record.
        The record is then written to the stream with a trailing newline
        [N.B. this may be removed depending on feedback]. If exception
        information is present, it is formatted using
        traceback.print_exception and appended to the stream.
        """
        try:
            msg = self.format(record)
            fs = "%s\n"
            if not hasattr(types, "UnicodeType"): #if no unicode support...
                self.stream.write(fs % msg)
            else:
                try:
                    self.stream.write(fs % msg)
                except UnicodeError:
                    self.stream.write(fs % msg.encode("UTF-8"))
            self.flush()
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.handleError(record) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:27,代碼來源:__init__.py

示例11: normalize_encoding

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def normalize_encoding(encoding):

    """ Normalize an encoding name.

        Normalization works as follows: all non-alphanumeric
        characters except the dot used for Python package names are
        collapsed and replaced with a single underscore, e.g. '  -;#'
        becomes '_'. Leading and trailing underscores are removed.

        Note that encoding names should be ASCII only; if they do use
        non-ASCII characters, these must be Latin-1 compatible.

    """
    # Make sure we have an 8-bit string, because .translate() works
    # differently for Unicode strings.
    if hasattr(types, "UnicodeType") and type(encoding) is types.UnicodeType:
        # Note that .encode('latin-1') does *not* use the codec
        # registry, so this call doesn't recurse. (See unicodeobject.c
        # PyUnicode_AsEncodedString() for details)
        encoding = encoding.encode('latin-1')
    return '_'.join(encoding.translate(_norm_encoding_map).split()) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:23,代碼來源:__init__.py

示例12: renderContents

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def renderContents(self, showStructureIndent=None, needUnicode=None):
        """Renders the contents of this tag as a (possibly Unicode) 
        string."""
        s=[]
        for c in self:
            text = None
            if isinstance(c, NavigableUnicodeString) or type(c) == types.UnicodeType:
                text = unicode(c)
            elif isinstance(c, Tag):
                s.append(c.__str__(needUnicode, showStructureIndent))
            elif needUnicode:
                text = unicode(c)
            else:
                text = str(c)
            if text:
                if showStructureIndent != None:
                    if text[-1] == '\n':
                        text = text[:-1]
                s.append(text)
        return ''.join(s)    

    #Soup methods 
開發者ID:rajeshmajumdar,項目名稱:BruteXSS,代碼行數:24,代碼來源:_beautifulsoup.py

示例13: add_password

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def add_password(self, realm, uri, user, passwd):
        # uri could be a single URI or a sequence
        if isinstance(uri, (types.StringType, types.UnicodeType)):
            uri = [uri]
        uri = tuple(map(self.reduce_uri, uri))
        if not self.passwd.has_key(realm):
            self.passwd[realm] = {}
        self.passwd[realm][uri] = (user, passwd) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:urllib2.py

示例14: compact_isstr

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def compact_isstr(s):
        return isinstance(s, types.UnicodeType) or isinstance(s, str) 
開發者ID:ForgQi,項目名稱:bilibiliupload,代碼行數:4,代碼來源:compact.py

示例15: isbasestring

# 需要導入模塊: import types [as 別名]
# 或者: from types import UnicodeType [as 別名]
def isbasestring(x):
        return isinstance(x, (types.StringType, types.UnicodeType)) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:4,代碼來源:optparse.py


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