本文整理汇总了Python中kol.util.Report类的典型用法代码示例。如果您正苦于以下问题:Python Report类的具体用法?Python Report怎么用?Python Report使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Report类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseResponse
def parseResponse(self):
ignorePattern = PatternManager.getOrCompilePattern("traderIgnoringUs")
if ignorePattern.search(self.responseText):
raise Error.Error("That player has you on his/her ignore list.", Error.USER_IS_IGNORING)
roninPattern = PatternManager.getOrCompilePattern("traderIsInRoninHC")
if roninPattern.search(self.responseText):
raise Error.Error("That player is in Ronin or HC and cannot receive trade offers.", Error.USER_IN_HARDCORE_RONIN)
itemsPattern = PatternManager.getOrCompilePattern("traderHasNotEnoughItems")
if itemsPattern.search(self.responseText):
raise Error.Error("You don't have enough of one or more of the items you're trying to trade.", Error.NOT_ENOUGH_ITEMS)
meatPattern = PatternManager.getOrCompilePattern("traderHasNotEnoughMeat")
if meatPattern.search(self.responseText):
raise Error.Error("You don't have as much meat as you're trying to trade.", Error.NOT_ENOUGH_MEAT)
chatBannedPattern = PatternManager.getOrCompilePattern("traderBannedFromChat")
if chatBannedPattern.search(self.responseText):
raise Error.Error("You are banned from chat and consequently cannot trade.", Error.BANNED_FROM_CHAT)
successPattern = PatternManager.getOrCompilePattern("tradeSentSuccessfully")
if successPattern.search(self.responseText):
Report.trace("request", "Trade offer sent successfully.")
else:
raise Error.Error("Other error sending trade offer.", Error.ERROR)
示例2: discoverMissingItems
def discoverMissingItems(session):
global __isLoaded
if not __isLoaded:
loadItemsFromFile()
newInformation = False
from kol.request.InventoryRequest import InventoryRequest
from kol.request.ItemInformationRequest import ItemInformationRequest
invRequest = InventoryRequest(session)
invRequest.ignoreItemDatabase = True
invData = invRequest.doRequest()
for item in invData["items"]:
if item["id"] not in __itemsById:
try:
itemRequest = ItemInformationRequest(session, item["id"])
itemData = itemRequest.doRequest()
item = itemData["item"]
addItem(item)
Report.trace("itemdatabase", "Discovered new item: %s" % item["name"])
context = { "item" : item }
FilterManager.executeFiltersForEvent("discoveredNewItem", context, session=session, item=item)
newInformation = True
except:
pass
if newInformation or not __isLoaded:
saveItemsToFile()
__isLoaded = True
示例3: do_GET
def do_GET(self):
if not self.path.count('/newchatmessages.php?') and not self.path.count('/submitnewchat.php?'):
Report.debug("relay", "GET: %s" % self.path)
relayServer = self.server.relayServer
# Check to see if we should terminate the RelayServer.
if self.path == '/terminate':
relayServer.haltEvent.set()
self.wfile.write('Server Stopping...')
return
# Redirect empty URL to main.html.
if self.path == '/':
self.path = '/main.html'
# Execute the server request.
dReq = DynamicRequest(relayServer.session, self.path[1:])
dReq.doRequest()
# The following line is for the sake of some js scripts (mainly chat).
page = dReq.responseText.replace("window.location.hostname", 'window.location.hostname+":"+window.location.port')
# Add server shutdown in compact mode.
if self.path == '/topmenu.php':
page = page.replace('<option value="logout.php">Log Out</option>','<option value="terminate">Stop Server</option>')
self.wfile.write(page)
示例4: botProcessChat
def botProcessChat(context, **kwargs):
returnCode = FilterManager.CONTINUE
chat = kwargs["chat"]
if chat["type"] == "private":
if BotUtils.canUserPerformAction(chat["userId"], "execute", kwargs["bot"]):
doAction = False
executeAll = False
wordList = chat["text"].split()
if len(wordList) > 0:
if wordList[0].lower() == "execute":
doAction = True
elif wordList[0].lower() == "executeall":
doAction = True
executeAll = True
if doAction:
returnCode = FilterManager.FINISHED
del wordList[0]
command = " ".join(wordList)
if executeAll:
for bot in BotManager._bots:
if bot.session != None and bot.session.isConnected and hasattr(bot.session, "chatManager"):
try:
bot.sendChatMessage(command)
except AttributeError, inst:
Report.error("chat", "Could not execute command: %s" % command, inst)
else:
kwargs["bot"].sendChatMessage(command)
示例5: parseResponse
def parseResponse(self):
items = []
itemMatchPattern = PatternManager.getOrCompilePattern('mallItemSearchResult')
itemDetailsPattern = PatternManager.getOrCompilePattern('mallItemSearchDetails')
for itemMatch in itemMatchPattern.finditer(self.responseText):
matchText = itemMatch.group(1)
match = itemDetailsPattern.search(matchText)
itemId = int(match.group('itemId'))
try:
item = ItemDatabase.getItemFromId(itemId)
item["price"] = int(match.group('price').replace(',', ''))
item["storeId"] = int(match.group('storeId'))
item["storeName"] = match.group('storeName').replace('<br>', ' ')
item["quantity"] = int(match.group('quantity').replace(',', ''))
limit = match.group('limit').replace(',', '')
if len(limit) > 0:
limit = int(limit)
item["limit"] = limit
if matchText.find('limited"') >= 0:
item["hitLimit"] = True
items.append(item)
except Error.Error, inst:
if inst.code == Error.ITEM_NOT_FOUND:
Report.info("itemdatabase", "Unrecognized item found in mall search: %s" % itemId, inst)
else:
raise inst
示例6: uneffect
def uneffect(bot, id):
r = UneffectRequest(bot.session, id)
try:
r.doRequest()
resp = "Effect successfully removed!"
except Error:
resp = "Unable to remove effect for unknown reason."
Report.info("bot", resp)
示例7: parseResponse
def parseResponse(self):
# First parse for errors
notEnoughPattern = PatternManager.getOrCompilePattern("dontHaveThatManyInStore")
if notEnoughPattern.search(self.responseText):
raise Error.Error("You either don't have that item, or not enough", Error.ITEM_NOT_FOUND)
# Check if responseText matches the success pattern. If not, raise error.
itemTakenSuccessfully = PatternManager.getOrCompilePattern("itemTakenSuccessfully")
if itemTakenSuccessfully.search(self.responseText):
Report.trace('request', 'Item appears to have been taken')
else:
raise Error.Error("Something went wrong with the taking of the item.", Error.ITEM_NOT_FOUND)
示例8: parseResponse
def parseResponse(self):
# Get the timestamp we should send to the server next time we make a request.
lastSeenPattern = PatternManager.getOrCompilePattern("chatLastSeen")
match = lastSeenPattern.search(self.responseText)
self.responseData["lastSeen"] = match.group(1)
# Parse the chat messages.
text = self.responseText[:self.responseText.find('<!--lastseen')]
self.responseData["chatMessages"] = ChatUtils.parseMessages(self.responseText, True)
# Trace out unknown messages.
for chat in self.responseData["chatMessages"]:
if chat["type"] == "unknown":
Report.trace("chat", "Unable to parse chat message: %s" % chat)
示例9: doRequest
def doRequest(self):
"""
Performs the request. This method will ensure that nightly maintenance is not occuring.
In addition, this method will throw a NOT_LOGGED_IN error if the session thinks it is
logged in when it actually isn't. All specific KoL requests should inherit from this class.
"""
Report.debug("request", "Requesting %s" % self.url)
self.response = self.session.opener.open(self.url, self.requestData)
self.responseText = self.response.text
Report.debug("request", "Received response: %s" % self.url)
Report.debug("request", "Response Text: %s" % self.responseText)
if self.response.url.find("/maint.php") >= 0:
self.session.isConnected = False
raise Error.Error("Nightly maintenance in progress.", Error.NIGHTLY_MAINTENANCE)
if self.response.url.find("/login.php") >= 0:
if self.session.isConnected:
self.session.isConnected = False
raise Error.Error("You are no longer connected to the server.", Error.NOT_LOGGED_IN)
# Allow for classes that extend GenericRequest to parse all of the data someone
# would need from the response and then to place this data in self.responseData.
self.responseData = {}
if self.skipParseResponse == False and hasattr(self, "parseResponse"):
self.parseResponse()
if len(self.responseData) > 0:
Report.debug("request", "Parsed response data: %s" % self.responseData)
return self.responseData
示例10: doRequest
def doRequest(self):
"""
Performs the request. This method will ensure that nightly maintenance is not occuring.
In addition, this method will throw a NotLoggedInError if the session thinks it is logged
in when it actually isn't. All specific KoL requests should inherit from this class.
"""
Report.debug("request", "Requesting %s" % self.url)
self.response = self.session.opener.open(self.url, urllib.urlencode(self.requestData))
self.responseText = self.response.read()
Report.debug("request", "Received response: %s" % self.url)
Report.debug("request", "Response Text: %s" % self.responseText)
if self.response.geturl().find("/maint.php") >= 0:
self.session.isConnected = False
raise NightlyMaintenanceError("Nightly maintenance in progress.")
if self.response.geturl().find("/login.php") >= 0:
if self.session.isConnected:
self.session.isConnected = False
raise NotLoggedInError("You are no longer connected to the server.")
# Allow for classes that extend GenericRequest to parse all of the data someone
# would need from the response and then to place this data in self.responseData.
self.responseData = {}
if self.skipParseResponse == False and "parseResponse" in self.__class__.__dict__:
self.parseResponse()
if len(self.responseData) > 0:
Report.debug("request", "Parsed response data: %s" % self.responseData)
return self.responseData
示例11: run
def run(self):
Report.trace('relay', 'Starting RelayServer on port %s...' % self.port)
started = False
numTries = 0
while not started:
try:
server = HTTPServer(('', self.port), RelayRequestHandler)
started = True
except socket.error, inst:
numTries += 1
if numTries == 10:
raise inst
Report.trace('relay', 'Could not listen on port %s. Trying %s instead.' % (self.port, self.port + 1))
self.port += 1
示例12: couldNotFindItem
def couldNotFindItem(context, **kwargs):
if "session" not in kwargs:
return
session = kwargs["session"]
item = None
r = ClosetContentsRequest(session)
r.skipParseResponse = True
r.doRequest()
if "descId" in kwargs:
descId = kwargs["descId"]
pattern = re.compile("<option value='([0-9]+)' descid='%s'>([^<>]*) \([0-9]+\)<\/option>" % descId)
match = pattern.search(r.responseText)
if match:
item = {"id":int(match.group(1)), "descId":descId, "name":match.group(2)}
else:
raise ItemNotFoundError("Could not find item associated with description ID '%s'." % descId)
elif "itemId" in kwargs:
itemId = kwargs["itemId"]
pattern = re.compile("<option value='%s' descid='([0-9]+)'>([^<>]*) \([0-9]+\)<\/option>" % itemId)
match = pattern.search(r.responseText)
if match:
item = {"id":itemId, "descId":int(match.group(1)), "name":match.group(2)}
else:
raise ItemNotFoundError("Could not find item associated with ID '%s'." % itemId)
elif "itemName" in kwargs:
itemName = kwargs["itemName"]
pattern = re.compile("<option value='([0-9]+)' descid='([0-9]+)'>%s \([0-9]+\)<\/option>" % itemName)
match = pattern.search(r.responseText)
if match:
item = {"id":int(match.group(1)), "descId":int(match.group(2)), "name":itemName}
else:
raise ItemNotFoundError("Could not find item with name '%s'." % itemName)
if item != None:
r = ItemDescriptionRequest(session, item["descId"])
itemInfo = r.doRequest()
for k,v in itemInfo.iteritems():
item[k] = v
Report.trace("itemdatabase", "Discovered new item: %s" % item)
context["item"] = item
FilterManager.executeFiltersForEvent("discoveredNewItem", session=session, item=item)
示例13: parseResponse
def parseResponse(self):
noMeatPattern = PatternManager.getOrCompilePattern('traderHasNotEnoughMeat')
if noMeatPattern.search(self.responseText):
raise Error.Error("You don't have as much meat as you're promising.", Error.NOT_ENOUGH_MEAT)
noItemsPattern = PatternManager.getOrCompilePattern('traderHasNotEnoughItems')
if noItemsPattern.search(self.responseText):
raise Error.Error("You don't have as many items as you're promising.", Error.NOT_ENOUGH_ITEMS)
#Not testing for an offer being cancelled due to a bug in KoL - space reserved
successPattern = PatternManager.getOrCompilePattern('tradeResponseSentSuccessfully')
if successPattern.search(self.responseText):
Report.trace("request", "Response to trade " + str(self.requestData['whichoffer']) + ' sent successfully.')
else:
raise Error.Error("Unknown error sending response to trade " + str(self.requestData['whichoffer']), Error.REQUEST_GENERIC)
示例14: parseResponse
def parseResponse(self):
# First parse for errors
notEnoughPattern = PatternManager.getOrCompilePattern("dontHaveEnoughOfItem")
if notEnoughPattern.search(self.responseText):
raise Error.Error("You don't have that many of that item.", Error.ITEM_NOT_FOUND)
dontHaveItemPattern = PatternManager.getOrCompilePattern("dontHaveThatItem")
if dontHaveItemPattern.search(self.responseText):
raise Error.Error("You don't have that item.", Error.ITEM_NOT_FOUND)
# Check if responseText matches the success pattern. If not, raise error.
itemAddedSuccessfully = PatternManager.getOrCompilePattern("itemAddedSuccessfully")
if itemAddedSuccessfully.search(self.responseText):
Report.trace('request', 'Item appears to have been added')
else:
raise Error.Error("Something went wrong with the adding.", Error.ITEM_NOT_FOUND)
示例15: parseResponse
def parseResponse(self):
hardcoreRoninPattern = PatternManager.getOrCompilePattern('userInHardcoreRonin')
ignoringPattern = PatternManager.getOrCompilePattern('userIgnoringUs')
notEnoughItemsPattern = PatternManager.getOrCompilePattern('notEnoughItemsToSend')
sentMessagePattern = PatternManager.getOrCompilePattern('messageSent')
if hardcoreRoninPattern.search(self.responseText):
raise Error.Error("Unable to send items or meat. User is in hardcore or ronin.", Error.USER_IN_HARDCORE_RONIN)
elif ignoringPattern.search(self.responseText):
raise Error.Error("Unable to send message. User is ignoring us.", Error.USER_IS_IGNORING)
elif notEnoughItemsPattern.search(self.responseText):
raise Error.Error("You don't have enough of one of the items you're trying to send.", Error.ITEM_NOT_FOUND)
elif sentMessagePattern.search(self.responseText) == None:
Report.alert("system", "Received unknown response when attempting to send a message.")
Report.alert("system", self.responseText)
raise Error.Error("Unknown error", Error.REQUEST_FATAL)