diff options
author | mrDoctorWho <mrdoctorwho@gmail.com> | 2014-05-26 12:53:05 +0400 |
---|---|---|
committer | mrDoctorWho <mrdoctorwho@gmail.com> | 2014-05-26 12:53:05 +0400 |
commit | 58d81c8af25ca7e6d18f1a1894b019bd22ef1e0e (patch) | |
tree | e3f70f53d5733f6d8fd0124c5f309fe8f644e941 /library | |
parent | 6f88a7054f5a4e7c5c98c657cae1b564282b6f81 (diff) |
fixed: html-escape in attachments
fixed: groupchats are members-only again
fixed: ignore error-cods 1,9,100
added: xhtml-im in groupchats
added: groupchats deletion when user ungregistered
also: a little code cleanup
Diffstat (limited to 'library')
-rw-r--r-- | library/utils.py | 15 | ||||
-rw-r--r-- | library/vkapi.py | 12 | ||||
-rw-r--r-- | library/webtools.py | 35 |
3 files changed, 22 insertions, 40 deletions
diff --git a/library/utils.py b/library/utils.py new file mode 100644 index 0000000..3fe87e2 --- /dev/null +++ b/library/utils.py @@ -0,0 +1,15 @@ +# coding: utf-8 +# This file is a part of VK4XMPP transport +# © simpleApps, 2014. + +import xmpp + +def buildDataForm(form=None, type="submit", fields=[]): + form = form or xmpp.DataForm(type) + for key in fields: + field = form.setField(key["var"], key.get("value"), key.get("type")) + if key.get("payload"): + field.setPayload(key["payload"]) + if key.get("label"): + field.setLabel(key["label"]) + return form
\ No newline at end of file diff --git a/library/vkapi.py b/library/vkapi.py index 41be1e8..86902e1 100644 --- a/library/vkapi.py +++ b/library/vkapi.py @@ -115,13 +115,13 @@ class RequestProcessor(object): request = urllib2.Request(url, data, headers) return request - @attemptTo(5, tuple, urllib2.URLError, ssl.SSLError, socket.timeout) + @attemptTo(5, tuple, urllib2.URLError, ssl.SSLError, socket.timeout, httplib.BadStatusLine) def post(self, url, data="", urlencode=True): resp = self.open(self.request(url, data, urlencode=urlencode)) body = resp.read() return (body, resp) - @attemptTo(5, tuple, urllib2.URLError, ssl.SSLError, socket.timeout) + @attemptTo(5, tuple, urllib2.URLError, ssl.SSLError, socket.timeout, httplib.BadStatusLine) def get(self, url, query={}): if query: url += "?%s" % urllib.urlencode(query) @@ -246,7 +246,7 @@ class APIBinding: if (self.last.pop() - self.last.pop(0)) < 1.1: time.sleep(0.3) - response = self.RIP.post(url, values) # Next func should handle NetworkNotFound + response = self.RIP.post(url, values) if response and not nodecode: body, response = response if body: @@ -281,14 +281,14 @@ class APIBinding: raise VkApiError("Logged out") elif eCode == 7: # not allowed raise NotAllowed() - elif eCode == 9: # ???? - return {} elif eCode == 10: # internal server error raise InternalServerError() - if eCode == 14: # captcha + elif eCode == 14: # captcha if "captcha_sid" in error: self.captcha = {"sid": error["captcha_sid"], "img": error["captcha_img"]} raise CaptchaNeeded() + elif eCode in (1, 9, 100): ## 1 is an unknown error / 100 is wrong method or parameters loss + return {"error": eCode} raise VkApiError(body["error"]) def retry(self): diff --git a/library/webtools.py b/library/webtools.py index d4dc6e8..eb986b0 100644 --- a/library/webtools.py +++ b/library/webtools.py @@ -3,9 +3,7 @@ # BlackSmith-bot module. # © simpleApps, 21.05.2012. -import urllib, urllib2, re - -## HTML Unescape and <br> tag replace. +import re import htmlentitydefs edefs = dict() @@ -41,25 +39,6 @@ def uHTML(data): data = re.sub("</?br */?>", "\n", data) return data -# TODO: remove this function -def regexp(reg, string, findall = 1): - reg = re.compile(reg, re.IGNORECASE | re.DOTALL) - if findall: - reg = reg.findall(string) - else: - return reg.search(string) - return reg - -## Get HTML tag. -def getTagData(tag, data, close_tag = 0): - if not close_tag: - close_tag = tag - pattern = re.compile("<%(tag)s.*?>(.*?)</%(close_tag)s>" % vars(), flags = re.DOTALL | re.IGNORECASE) - tagData = pattern.search(data) - if tagData: - tagData = tagData.group(1) - return tagData or " " - def getTagArg(tag, argv, data, close_tag = 0): if not close_tag: close_tag = tag @@ -68,15 +47,3 @@ def getTagArg(tag, argv, data, close_tag = 0): if tagData: tagData = tagData.group(1) return tagData or " " - -def stripTags(data, subBy = str(), pattern = "<[^<>]+>"): - pattern = re.compile(pattern) - return pattern.sub(subBy, data) - -## Format size. -def byteFormat(size): - if size < 1024: return '%sb' % int(size) - for t in ('kB','MB','GB'): - size = size / 1024.0 - if size < 1024: break - return '%.2f%s' % (size,t) |