python类UnicodeType()的实例源码

_beautifulsoup.py 文件源码 项目:addon 作者: alfa-addon 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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
_beautifulsoup.py 文件源码 项目:addon 作者: alfa-addon 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def endData(self):
        currentData = ''.join(self.currentData)
        if currentData:
            if not currentData.strip():
                if '\n' in currentData:
                    currentData = '\n'
                else:
                    currentData = ' '
            c = NavigableString
            if type(currentData) == types.UnicodeType:
                c = NavigableUnicodeString
            o = c(currentData)
            o.setup(self.currentTag, self.previous)
            if self.previous:
                self.previous.next = o
            self.previous = o
            self.currentTag.contents.append(o)
        self.currentData = []
_beautifulsoup.py 文件源码 项目:BruteXSS 作者: rajeshmajumdar 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
_beautifulsoup.py 文件源码 项目:BruteXSS 作者: rajeshmajumdar 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def endData(self):
        currentData = ''.join(self.currentData)
        if currentData:
            if not currentData.strip():
                if '\n' in currentData:
                    currentData = '\n'
                else:
                    currentData = ' '
            c = NavigableString
            if type(currentData) == types.UnicodeType:
                c = NavigableUnicodeString
            o = c(currentData)
            o.setup(self.currentTag, self.previous)
            if self.previous:
                self.previous.next = o
            self.previous = o
            self.currentTag.contents.append(o)
        self.currentData = []
autoxmltests.py 文件源码 项目:pisi 作者: examachine 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setUp(self):

        class OtherInfo:
            __metaclass__ = autoxml.autoxml
            t_BirthDate = [types.StringType, autoxml.mandatory]
            t_Interest = [types.StringType, autoxml.optional]
            t_CodesWith = [ [types.UnicodeType], autoxml.optional, 'CodesWith/Person']

        class A(xmlfile.XmlFile):
            __metaclass__ = autoxml.autoxml
            t_Name = [types.UnicodeType, autoxml.mandatory]
            t_Description = [autoxml.LocalText, autoxml.mandatory]
            t_Number = [types.IntType, autoxml.optional]
            t_Email = [types.StringType, autoxml.optional]
            a_href = [types.StringType, autoxml.mandatory]
            t_Projects = [ [types.StringType], autoxml.mandatory, 'Project']
            t_OtherInfo = [ OtherInfo, autoxml.optional ]
            s_Comment = [ autoxml.Text, autoxml.mandatory]

        self.A = A
optparse.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def isbasestring(x):
        return isinstance(x, (types.StringType, types.UnicodeType))
optparse.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def isbasestring(x):
        return isinstance(x, (types.StringType, types.UnicodeType))
microdom.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def writexml(self, stream, indent='', addindent='', newl='', strip=0,
                 nsprefixes={}, namespace=''):
        val=self.data
        if isinstance(val, UnicodeType):
            val=val.encode('utf8')
        stream.write("<!--%s-->" % val)
microdom.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def parseString(st, *args, **kw):
    if isinstance(st, UnicodeType):
        # this isn't particularly ideal, but it does work.
        return parse(StringIO(st.encode('UTF-16')), *args, **kw)
    return parse(StringIO(st), *args, **kw)
jelly.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _unjelly_unicode(self, exp):
        if UnicodeType:
            return unicode(exp[0], "UTF-8")
        else:
            return Unpersistable(exp[0])
shell.py 文件源码 项目:llk 作者: Tycx2ry 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def recode(self, utext):
        if type(utext) is types.UnicodeType:
            return utext.encode(self.options.charset, 'replace')
        return utext
sitemap_gen.py 文件源码 项目:pymotw3 作者: reingart 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _MungeLocationListIntoFiles(self, urllist):
    """Given a list of URLs, munge them into our self._pathlist property.
    We do this by assuming all the files live in the same directory as
    the first file in the existing pathlist.  That is, we assume a
    Sitemap index points to Sitemaps only in the same directory.  This
    is not true in general, but will be true for any output produced
    by this script.
    """
    assert self._pathlist
    path = self._pathlist[0]
    path = os.path.normpath(path)
    dir  = os.path.dirname(path)
    wide = False
    if type(path) == types.UnicodeType:
      wide = True

    for url in urllist:
      url = URL.Canonicalize(url)
      output.Log('Index points to Sitemap file at: %s' % url, 2)
      (scheme, netloc, path, query, frag) = urlparse.urlsplit(url)
      file = os.path.basename(path)
      file = urllib.unquote(file)
      if wide:
        file = encoder.WidenText(file)
      if dir:
        file = dir + os.sep + file
      if file:
        self._pathlist.append(file)
        output.Log('Will attempt to read Sitemap file: %s' % file, 1)
  #end def _MungeLocationListIntoFiles
androconf.py 文件源码 项目:ApkParser 作者: yigitozgumus 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def str2long(s):
    """Convert a string to a long integer."""
    if type(s) not in (types.StringType, types.UnicodeType):
        raise ValueError, 'the input must be a string'

    l = 0L
    for i in s:
        l <<= 8
        l |= ord(i)

    return l
shell.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def recode(self, utext):
        if type(utext) is types.UnicodeType:
            return utext.encode(self.options.charset, 'replace')
        return utext
core.py 文件源码 项目:SameKeyProxy 作者: xzhou 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, URI):
        _checkInit() # init required
        if type(URI) in (StringType,UnicodeType):
            URI=processStringURI(URI)
        self.URI = URI
        self.objectID = URI.objectID
        # Delay adapter binding to enable transporting of proxies.
        # We just create an adapter, and don't connect it...
        self.adapter = Pyro.protocol.getProtocolAdapter(self.URI.protocol)
        # ---- don't forget to register local vars with DynamicProxyWithAttrs, see below
common.py 文件源码 项目:tintri-python-sdk 作者: Tintri 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _process_result(self, method, url, response, request_class, response_class, query_params, path_params):
        cls = response_class and response_class or request_class
        if cls in [types.StringType, types.UnicodeType]: # if we expect string type result, no need for further processing
            return response.text
        else:
            # prepare context to hold url and data along with method to navigate pages
            context = { 'method': method, 'url': url, 'query_params': query_params, 'response_class': response_class, 'func': self._get_all, 'request_class': request_class, 'path_params': path_params, 'response_data': response.text }
            return self._json_object_to_object(json.loads(response.text), cls, context=context) # first load JSON to a Python list or dict
optparse.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def isbasestring(x):
        return isinstance(x, (types.StringType, types.UnicodeType))
xlog.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def unicode_line(self, line):
        try:
            if type(line) is types.UnicodeType:
                return line
            else:
                return unicode(line, errors='ignore')
        except Exception as e:
            print("unicode err:%r" % e)
            print("line can't decode:%s" % line)
            print("Except stack:%s" % traceback.format_exc())
            return ""
optparse.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def isbasestring(x):
        return isinstance(x, (types.StringType, types.UnicodeType))
xlog.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def unicode_line(self, line):
        try:
            if type(line) is types.UnicodeType:
                return line
            else:
                return unicode(line, errors='ignore')
        except Exception as e:
            print("unicode err:%r" % e)
            print("line can't decode:%s" % line)
            print("Except stack:%s" % traceback.format_exc())
            return ""


问题


面经


文章

微信
公众号

扫码关注公众号