def fill_paste(self, paste): """ Get as much as information possible from the paste page """ try: return self.paste.stay_or_go(id=paste.id).fill_paste(paste) except BrowserHTTPNotFound: raise PasteNotFound()
def fill_paste(self, paste): """ Get as much as information possible from the paste page """ try: self.location(paste.page_url, no_login=True) return self.page.fill_paste(paste) except BrowserHTTPNotFound: raise PasteNotFound()
def get_contents(self, _id): """ Get the contents from the raw URL This is the fastest and safest method if you only want the content. Returns unicode. """ try: return self.raw.open(id=_id).text except BrowserHTTPNotFound: raise PasteNotFound()
def get_contents(self, _id): """ Get the contents from the raw URL This is the fastest and safest method if you only want the content. Returns unicode. """ try: return self.readurl('http://%s/raw.php?i=%s' % (self.DOMAIN, _id), if_fail='raise').decode(self.ENCODING) except BrowserHTTPNotFound: raise PasteNotFound()
def get_contents(self, _id): """ Get the contents from the raw URL This is the fastest and safest method if you only want the content. Returns unicode. """ try: # despite what the HTTP header says, it is iso8859 return self.raw.open(id=_id).content.decode('iso8859-15') except BrowserHTTPNotFound: raise PasteNotFound()
def fill_paste(self, paste): root = self.document.getroot() try: # there is no 404, try to detect if there really is a content self.parser.select(root, 'id("content")/div[@class="syntax"]//ol', 1, 'xpath') except BrokenPageError: raise PasteNotFound() header = self.parser.select(root, 'id("content")/h3', 1, 'xpath') matches = re.match(r'Posted by (?P<author>.+) on (?P<date>.+) \(', header.text) paste.title = matches.groupdict().get('author') paste.contents = self.parser.select(root, '//textarea[@id="code"]', 1, 'xpath').text return paste
def parse(self, el): # there is no 404, try to detect if there really is a content if len(el.xpath('id("content")/div[@class="syntax"]//ol')) != 1: raise PasteNotFound()
def validate(self, obj): if obj.contents == u'%s not found.' % obj.id: raise PasteNotFound() return True