def get64(url): """ Method returning base64 image data instead of URL """ if url.startswith("http"): image = BytesIO.StringIO(urllib.urlopen(url).read()) return 'data:image/jpg;base64,' + base64.b64encode(image.read()) return url
def startTest(self, test): TestResult.startTest(self, test) # just one buffer for both stdout and stderr self.outputBuffer = StringIO.StringIO() stdout_redirector.fp = self.outputBuffer stderr_redirector.fp = self.outputBuffer self.stdout0 = sys.stdout self.stderr0 = sys.stderr sys.stdout = stdout_redirector sys.stderr = stderr_redirector
def generate_pdf(template_name, file_object=None, context=None, link_callback=fetch_resources): # pragma: no cover """ Uses the xhtml2pdf library to render a PDF to the passed file_object, from the given template name. This returns the passed-in file object, filled with the actual PDF data. In case the passed in file object is none, it will return a StringIO instance. """ if not file_object: file_object = StringIO.StringIO() if not context: context = {} tmpl = get_template(template_name) generate_pdf_template_object(tmpl, file_object, context, link_callback=link_callback) return file_object
def from_gbt(cls, retval, coinbase, extra_length=0, transactions=None, pos=False): """ Creates a block template object from a get block template call and a coinbase transaction object. extra_length needs to be the length of padding that was added for extranonces (both 1 and 2 if added). Transactions should be a list of Transaction objects that will be put into the block. """ if transactions is None: transactions = [] coinbase1, coinbase2 = coinbase.assemble(split=True) inst = cls(pos=pos) inst.hashprev = unhexlify(reverse_hash(retval['previousblockhash'])) inst.ntime = retval['curtime'] inst.bits = unhexlify(retval['bits']) inst.version = retval['version'] inst.total_value = retval['coinbasevalue'] # Darkcoin inst.masternode_payments = retval.get('masternode_payments') for vote in retval.get('votes', []): v = CMasterNodeVote() v.deserialize(StringIO.StringIO(unhexlify(vote))) inst.vmn.append(v) # chop the padding off the coinbase1 for extranonces to be put if extra_length > 0: inst.coinbase1 = coinbase1[:-1 * extra_length] else: inst.coinbase1 = coinbase1 inst.coinbase2 = coinbase2 inst.transactions = transactions return inst