本文整理匯總了Python中bs4.UnicodeDammit.splitlines方法的典型用法代碼示例。如果您正苦於以下問題:Python UnicodeDammit.splitlines方法的具體用法?Python UnicodeDammit.splitlines怎麽用?Python UnicodeDammit.splitlines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bs4.UnicodeDammit
的用法示例。
在下文中一共展示了UnicodeDammit.splitlines方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _import
# 需要導入模塊: from bs4 import UnicodeDammit [as 別名]
# 或者: from bs4.UnicodeDammit import splitlines [as 別名]
def _import(self, message):
"""import <url> [<alias(es)>] - imports all aliases from the given address, or only the listed aliases"""
if len(message.ParameterList) < 2:
return IRCResponse(ResponseType.Say,
u"You didn't give a url to import from!",
message.ReplyTo)
if len(message.ParameterList) > 2:
onlyListed = True
importList = [alias.lower() for alias in message.ParameterList[2:]]
else:
onlyListed = False
url = message.ParameterList[1]
try:
page = self.bot.moduleHandler.runActionUntilValue('fetch-url', url)
except ValueError:
return IRCResponse(ResponseType.Say,
u"'{}' is not a valid URL".format(url),
message.ReplyTo)
if page is None:
return IRCResponse(ResponseType.Say,
u"Failed to open page at {}".format(url),
message.ReplyTo)
text = page.body
text = UnicodeDammit(text).unicode_markup
lines = text.splitlines()
numAliases = 0
numHelpTexts = 0
for lineNumber, line in enumerate(lines):
# Skip over blank lines
if line == u"":
continue
splitLine = line.split()
if splitLine[0].lower() != u"{}alias".format(self.bot.commandChar):
return IRCResponse(ResponseType.Say,
u"Line {} at {} does not begin with {}alias".format(lineNumber,
url,
self.bot.commandChar),
message.ReplyTo)
subCommand = splitLine[1].lower()
if subCommand not in [u"add", u"help"]:
return IRCResponse(ResponseType.Say,
u"Line {} at {} is not an add or help command".format(lineNumber, url),
message.ReplyTo)
aliasName = splitLine[2].lower()
aliasCommand = splitLine[3:]
aliasCommand[0] = aliasCommand[0].lower()
# Skip over aliases that weren't listed, if any were listed
if onlyListed and aliasName not in importList:
continue
if subCommand == u"add":
self._newAlias(aliasName, u" ".join(aliasCommand))
numAliases += 1
elif subCommand == u"help":
aliasHelp = u" ".join(splitLine[3:])
self._setAliasHelp(aliasName, aliasHelp)
numHelpTexts += 1
self._syncAliases()
return IRCResponse(ResponseType.Say,
u"Imported {} alias(es) and {} help string(s) from {}".format(numAliases,
numHelpTexts,
url),
message.ReplyTo)