def ping(self, pingUrl, id, url, title, blogName, excerpt): u"""ping(string, string, string, string, string, string) -> ZTrackbackPingResponse Pings the track back and returns ZTrackbackPingResponse""" #$NON-NLS-1$ if getNoneString(pingUrl) is None: return ZTrackbackPingResponse(False, u"Trackback ping url is required.") #$NON-NLS-1$ if getNoneString(id) is None: return ZTrackbackPingResponse(False, u"Trackback Originating Resource ID is required.") #$NON-NLS-1$ if getNoneString(url) is None: return ZTrackbackPingResponse(False, u"Trackback post url is required.") #$NON-NLS-1$ title = convertToUtf8( getSafeString(title) ) blogName = convertToUtf8( getSafeString(blogName)) excerpt = convertToUtf8( getSafeString(excerpt)) postData = { u'id': id, #$NON-NLS-1$ u'url': url, #$NON-NLS-1$ u'title': title, #$NON-NLS-1$ u'blog_name': blogName, #$NON-NLS-1$ u'excerpt': excerpt #$NON-NLS-1$ } htmlResult = self._sendHttpPostData(pingUrl, postData) resp = self._parseResponse(htmlResult) return resp
def ping(self, pingUrl, id, url, title, blogName, excerpt): u"""ping(string, string, string, string, string, string) -> ZTrackbackPingResponse Pings the track back and returns ZTrackbackPingResponse""" #$NON-NLS-1$ if getNoneString(pingUrl) is None: return ZTrackbackPingResponse( False, u"Trackback ping url is required.") #$NON-NLS-1$ if getNoneString(id) is None: return ZTrackbackPingResponse( False, u"Trackback Originating Resource ID is required." ) #$NON-NLS-1$ if getNoneString(url) is None: return ZTrackbackPingResponse( False, u"Trackback post url is required.") #$NON-NLS-1$ title = convertToUtf8(getSafeString(title)) blogName = convertToUtf8(getSafeString(blogName)) excerpt = convertToUtf8(getSafeString(excerpt)) postData = { u'id': id, #$NON-NLS-1$ u'url': url, #$NON-NLS-1$ u'title': title, #$NON-NLS-1$ u'blog_name': blogName, #$NON-NLS-1$ u'excerpt': excerpt #$NON-NLS-1$ } htmlResult = self._sendHttpPostData(pingUrl, postData) resp = self._parseResponse(htmlResult) return resp
def toUtf8(s): if s is not None and isinstance(s, basestring): return convertToUtf8(s) else: try: return convertToUtf8(unicode(s)) except: try: return str(s) except: return s
def toUtf8(s): if s is not None and isinstance(s,basestring): return convertToUtf8(s) else: try: return convertToUtf8(unicode(s)) except: try: return str(s) except: return s
def handleRequest(self, httpResp, url, username, password): #@UnusedVariable rVal = {} userPass = u"%s:%s" % (username, password) #$NON-NLS-1$ userPass = convertToUtf8(userPass) auth = u'BASIC %s' % base64.encodestring(userPass) #$NON-NLS-1$ rVal[u"Authorization"] = auth.rstrip() #$NON-NLS-1$ return rVal
def _loadStringFromFile(self, html): # MSHTML control requires a <head> and <title> element title = getNoneString(extractTitle(html)) if not title or html.find(u"<html") == -1: #$NON-NLS-1$ # case where only the body content is given or the content did not have non-empty <head> and <title> elems. # try and create wrapper around the body. Eg: <html><head><title>ZoundryDocument</title></head><body> CONTENT </body> </html> html = wrapHtmlBody(html, u"ZoundryDocument") #$NON-NLS-1$ # note: \r\n must be replace with \n. Otherwise, in <pre> blocks, the \r' will show up as an extra line. html = html.replace(u"\r\n", u"\n") #$NON-NLS-1$ #$NON-NLS-2$ # For the test-harness to work, hard code temp dir tmpDir = u"c:/temp" #$NON-NLS-1$ if getApplicationModel(): userProfile = getApplicationModel().getUserProfile() tmpDir = userProfile.getTempDirectory() d = str(time.time()) fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.xhtml" % d) #$NON-NLS-1$ tmpFile = codecs.open(fname, u"w") #$NON-NLS-1$ try: # write the utf-8 byte order marker for wintel platforms. tmpFile.write(codecs.BOM_UTF8) tmpFile.write(convertToUtf8(html)) tmpFile.close() self._loadFile(fname) finally: tmpFile.close()
def _loadStringFromFile(self, html): # MSHTML control requires a <head> and <title> element title = getNoneString( extractTitle(html) ) if not title or html.find(u"<html") == -1: #$NON-NLS-1$ # case where only the body content is given or the content did not have non-empty <head> and <title> elems. # try and create wrapper around the body. Eg: <html><head><title>ZoundryDocument</title></head><body> CONTENT </body> </html> html = wrapHtmlBody(html, u"ZoundryDocument") #$NON-NLS-1$ # note: \r\n must be replace with \n. Otherwise, in <pre> blocks, the \r' will show up as an extra line. html = html.replace(u"\r\n", u"\n") #$NON-NLS-1$ #$NON-NLS-2$ # For the test-harness to work, hard code temp dir tmpDir = u"c:/temp" #$NON-NLS-1$ if getApplicationModel(): userProfile = getApplicationModel().getUserProfile() tmpDir = userProfile.getTempDirectory() d = str(time.time()) fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.xhtml" % d) #$NON-NLS-1$ tmpFile = codecs.open(fname, u"w") #$NON-NLS-1$ try: # write the utf-8 byte order marker for wintel platforms. tmpFile.write(codecs.BOM_UTF8) tmpFile.write( convertToUtf8(html) ) tmpFile.close() self._loadFile(fname) finally: tmpFile.close()
def handleRequest(self, httpResp, url, username, password): #@UnusedVariable rVal = {} userPass = u"%s:%s" % (username, password) #$NON-NLS-1$ userPass = convertToUtf8(userPass) auth = u'BASIC %s' % base64.encodestring(userPass) #$NON-NLS-1$ rVal[u"Authorization"] = auth.rstrip() #$NON-NLS-1$ return rVal
def _internalRunTidy(htmlSrc, options=XHTML_OPTIONS): # Runs tidy and returns tuple (html, errorList) unsupportedOptions = ["raw", "output_error", "show_warnings"] try: # remove unsupported options. if options: options['tidy_mark'] = 0 for s in unsupportedOptions: if options.has_key(s): del options[s] except: pass lineOffset = 0 if htmlSrc: # escape illegal entities. E.g. convert &##! to &##! try: htmlSrc = ILLEGAL_ENTITY_RE.sub(u"&\g<2>", htmlSrc) #$NON-NLS-1$ except: pass if not hasBody(htmlSrc): # wrap content inside a <html><head/><body> [CONTENT] </body></html> htmlSrc = XHTML_TEMPLATE % htmlSrc lineOffset = XHTML_TEMPLATE_LINE_OFFSET tidySrc = convertToUtf8(htmlSrc) tidyRet = tidy.parseString(tidySrc, **options) errList = [] severities = dict(W=ZTidyError.WARN, E=ZTidyError.ERROR, C=ZTidyError.OTHER) for err in tidyRet.get_errors(): te = ZTidyError() if err.line is not None: te.line = err.line - lineOffset if err.col is not None: te.col = err.col if err.message is not None: te.message = err.message te.severity = ZTidyError.NONE if severities.has_key(err.severity): te.severity = severities[err.severity] errList.append(te) outHtml = str(tidyRet) return (convertToUnicode(outHtml), errList)
def _internalRunTidy(htmlSrc, options = XHTML_OPTIONS): # Runs tidy and returns tuple (html, errorList) unsupportedOptions = ["raw", "output_error", "show_warnings"] try: # remove unsupported options. if options: options['tidy_mark'] = 0 for s in unsupportedOptions: if options.has_key(s): del options[s] except: pass lineOffset = 0 if htmlSrc: # escape illegal entities. E.g. convert &##! to &##! try: htmlSrc = ILLEGAL_ENTITY_RE.sub(u"&\g<2>", htmlSrc) #$NON-NLS-1$ except: pass if not hasBody(htmlSrc): # wrap content inside a <html><head/><body> [CONTENT] </body></html> htmlSrc = XHTML_TEMPLATE % htmlSrc lineOffset = XHTML_TEMPLATE_LINE_OFFSET tidySrc = convertToUtf8(htmlSrc) tidyRet = tidy.parseString(tidySrc, **options) errList = [] severities = dict(W=ZTidyError.WARN, E=ZTidyError.ERROR, C=ZTidyError.OTHER) for err in tidyRet.get_errors(): te = ZTidyError() if err.line is not None: te.line = err.line - lineOffset if err.col is not None: te.col = err.col if err.message is not None: te.message = err.message te.severity = ZTidyError.NONE if severities.has_key(err.severity): te.severity = severities[err.severity] errList.append(te) outHtml = str(tidyRet) return (convertToUnicode(outHtml), errList)
def _loadStringFromFile(self, html): # MSHTML control requires a <head> and <title> element title = getNoneString(extractTitle(html)) if not title or html.find(u"<html") == -1: #$NON-NLS-1$ # case where only the body content is given or the content did not have non-empty <head> and <title> elems. # try and create wrapper around the body. Eg: <html><head><title>ZoundryDocument</title></head><body> CONTENT </body> </html> html = wrapHtmlBody(html, u"ZoundryDocument") #$NON-NLS-1$ # note: \r\n must be replace with \n. Otherwise, in <pre> blocks, the \r' will show up as an extra line. html = html.replace(u"\r\n", u"\n") #$NON-NLS-1$ #$NON-NLS-2$ # For the test-harness to work, hard code temp dir tmpDir = u"c:/temp" #$NON-NLS-1$ if getApplicationModel(): userProfile = getApplicationModel().getUserProfile() tmpDir = userProfile.getTempDirectory() d = str(time.time()) # For Microsoft Internet Explorer Version 9 (and above?) the file extension for the temporary file must have # a ".html" (previously a ".xhtml") extension in order for the blog post to load successfully into the ActiveX # mshtml IHtmlDocument. Otherwise, the blog posts will appear to be mal-formatted during previews and fail to # load correctly during editing. # # Chuah TC 23 December 2013 # #fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.xhtml" % d) #$NON-NLS-1$ fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.html" % d) #$NON-NLS-1$ tmpFile = codecs.open(fname, u"w") #$NON-NLS-1$ try: # write the utf-8 byte order marker for wintel platforms. tmpFile.write(codecs.BOM_UTF8) tmpFile.write(convertToUtf8(html)) tmpFile.close() self._loadFile(fname) finally: tmpFile.close()
def createConnection(self): return sqlite.connect(convertToUtf8(self.pathToDBFile))
def createConnection(self): return sqlite.connect(convertToUtf8(self.pathToDBFile))