Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre python (publicaciones antiguas, página 90)

Olvidate del modo "incógnito", usá un browser descartable!

No es por­que lo ha­ya es­cri­to yo (bue­no, sí) pe­ro si ne­ce­si­tás un bro­w­ser "lim­pio" sin cookie­s, etc, pa­ra tes­tear al­go, po­drías en­con­trar ma­ne­ras peo­res que usar De­vi­cen­zo así:

rm -f ~/.config/ralsina/devicenzo.conf
curl https://devicenzo.googlecode.com/svn/trunk/devicenzo.py | python

La pri­me­ra lí­nea eli­mi­na to­da la con­fi­gu­ra­ció­n, cookie­s, etc que pue­das te­ne­r, y la se­gun­da des­car­ga la úl­ti­ma ver­sión (no te preo­cu­pes, tar­da dos se­gun­do­s) y la lan­za.

Y voi­lá, un bro­w­ser re­cién des­em­ba­la­do, ba­sa­do en we­bki­t, sin his­to­ria pre­via, ni cookie­s, ni con­fi­gu­ra­ció­n, y ra­zo­na­ble­men­te fea­tu­re-­com­ple­te.

Serbo-Croatian version of PyQt By Example!

A whi­le ago I got an email from An­ja Skr­ba asking me for per­mis­sion to trans­la­te Py­Qt by Exam­ple in­to Ser­bo­-­Croa­tian.

And he­re it is all ni­ce and trans­late­d. Lo­ts of thanks to An­ja for the hard wo­rk!

Nikola 5.4.3 released!

I am th­ri­lled to an­noun­ce the re­lea­se of ver­sion 5.4.3 of Niko­la a sta­tic web­si­te/­blog ge­ne­ra­to­r.

The chan­ge­log is pre­tty lon­g, mo­re in­for­ma­tion at the an­noun­ce­ment

Ha­ve fun!

Using rst2pdf in Different Ways

This was an idea by Di­nu Gher­man: you can use rs­t2­pdf as a flo­wa­ble ge­ne­ra­tor for re­por­tlab. Su­ppo­se you want to crea­te, in a re­por­tlab "s­to­r­y", a bun­ch of pa­ra­gra­phs, wi­th em­pha­sis, li­nks, etc, and perhaps a ta­ble.

Using res­truc­tu­red tex­t, it's so­me­thing like this:

This is a paragraph. It has a link: http://rst2pdf.ralsina.me and then some random text.

+-------------+---------------------------+
| A table     | With cells                |
|             |                           |
|             |                           |
|             |                           |
|             |                           |
+-------------+---------------------------+
| And inside                              |
| it some                                 |
| more text                               |
|                                         |
|                                         |
+-----------------------------------------+

* And a list
* Just to make it harder

  + with a nested item here

It is, of cour­se, per­fec­tly po­s­si­ble to ge­ne­ra­te a bun­ch of re­por­tlab (or ra­ther pla­ty­pus) flo­wa­bles to re­pre­sent all this. It wi­ll just mean so­me 75 li­nes of co­de. And if you chan­ge an­y­thin­g, then you ha­ve to edit co­de!

Or you can take ad­van­ta­ge of rs­t2­pdf and do this:

from docutils.core import publish_doctree
from rst2pdf.createpdf import RstToPdf
from reportlab.lib.units import cm
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus import Frame

rest_text = """
This is a paragraph. It has a link: http://rst2pdf.ralsina.me and then some random text.

+-------------+---------------------------+
| A table     | With cells                |
|             |                           |
|             |                           |
|             |                           |
|             |                           |
+-------------+---------------------------+
| And inside                              |
| it some                                 |
| more text                               |
|                                         |
|                                         |
+-----------------------------------------+

* And a list
* Just to make it harder

    + with a nested item here
"""
r2p = RstToPdf()
doctree = publish_doctree(rest_text)
story = r2p.gen_elements(doctree)
canv = Canvas("platypus-rest.pdf")
f = Frame(2 * cm, 2 * cm, 16 * cm, 18 * cm, showBoundary=True)
f.addFromList(story, canv)
canv.save()

This pro­du­ces this pdf. And of cour­se edi­ting it is ra­ther ea­sier than edi­ting co­de. Sin­ce you are not using rs­t2­pdf to do the fi­nal PDF ge­ne­ra­tio­n, you can use the­se flo­wa­bles in your own do­cu­men­ts.

The bad news

So­me things wi­ll not wo­rk, like hea­dings, sin­ce rs­t2­pdf crea­tes flo­wa­bles that do a ton of things like adding the­msel­ves on in­dexes and su­ch. If you want a hea­din­g-­like thing you can use cla­sses:

.. class:: heading1

This will look like a heading

This is a regular paragraph.

Other ran­dom res­truc­tu­red text fea­tu­res may or may not wo­rk, like footno­tes or ci­ta­tion­s.

The Password Is Password (follow the link to see what I mean)

I think this is a first in the world of stat­ic site gen­er­a­tors :-)

Now Niko­la sup­ports pass­word-pro­tect­ed pages. How does it work?

If you add a pass­word meta­da­ta field, then it will "Just Work". Like this:

I think this is a first in the world of stat­ic site gen­er­a­tors :-) And the re­sult is what you are see­ing now.

How is it im­ple­ment­ed? Niko­la will en­crypt the con­tent us­ing RC4, then wrap it in a <di­v>, and tack a form at the end that trig­gers Javascript code to de­crypt it, and show it.

Is it se­cure? Well, I am not a cryp­tog­ra­pher, so as­sume no. Specif­i­cal­ly, while RC4 is con­sid­ered se­cure, I am not dis­card­ing the be­gin­ning of they keystream, and the im­ple­men­ta­tions I am us­ing are not au­dit­ed.

So, don't use this for any­thing that could get you in trou­ble. Have fun!

UP­DATE Re­mem­ber when I asked "Is it se­cure?" well, re­al­ly, no it's not. It's not stupid in the sense that de­cod­ing what's writ­ten in the post will re­quire at least a mod­icum of ef­fort by who­ev­er is so in­ter­est­ed in read­ing what you are post­ing in your site, but peo­ple with cryp­to chops will crack it like a WEP-se­cured AP, mm­mmkay? It's al­so stupid­ly easy to brute­force this, so be smart about pass­word­s.

OTO­H, it's more se­cure than HTTP sim­ple au­th, since you can't sniff it (not that sim­ple auth is se­cure) and it can hide a piece of the page, which us­ing server-based auth can't.

I may do a more se­cure ver­sion even­tu­al­ly, but this is not it. There­fore, use for fun stuff, not to hide im­por­tan­t/il­le­gal stuff.


Contents © 2000-2023 Roberto Alsina