本文整理汇总了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)
示例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)
示例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
示例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)
示例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)
示例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)
示例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
示例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)
示例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
示例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)
示例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())
示例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
示例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)
示例14: compact_isstr
# 需要导入模块: import types [as 别名]
# 或者: from types import UnicodeType [as 别名]
def compact_isstr(s):
return isinstance(s, types.UnicodeType) or isinstance(s, str)
示例15: isbasestring
# 需要导入模块: import types [as 别名]
# 或者: from types import UnicodeType [as 别名]
def isbasestring(x):
return isinstance(x, (types.StringType, types.UnicodeType))