Rocksolid Light

groups  faq  privacy  How to post  login

Message-ID:  

He jests at scars who never felt a wound. -- Shakespeare, "Romeo and Juliet, II. 2"


rocksolid / de.comp.lang.python / Neuer Site-Generator, Erste Schritte

SubjectAuthor
o Neuer Site-Generator, Erste SchritteStefan Ram

1
Subject: Neuer Site-Generator, Erste Schritte
From: Stefan Ram
Newsgroups: de.comp.lang.python
Organization: Stefan Ram
Date: Sun, 28 Apr 2024 10:29 UTC
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: de.comp.lang.python
Subject: Neuer Site-Generator, Erste Schritte
Date: 28 Apr 2024 10:29:28 GMT
Organization: Stefan Ram
Lines: 85
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <site-20240428111453@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de qxiMyZEq5mXNW2y4PvQpjQmwfFmO+aSeB561jE5gqX7fGR
Cancel-Lock: sha1:ZXN/Iie76tEvUv2dn+NzQTm1wjE= sha256:CzCVD9XgsLiDPILlCefXA8T8ZSfU8QYB0hR1SxNFGAk=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: de-DE-1901
View all headers

Es soll ein HTML-Generator geschrieben werden. Die grundsätzliche
Idee dafür hatte ich unter derselben Betreffzeile schon in
"de.comm.infosystems.www.authoring.misc" beschrieben.

Hier nun die ersten beiden Schritte!

1. Schritt: Die erste Funktion

Ich gehe davon aus, daß die Entität zum Schreiben von HTML eine
Klasse sein sollte, und schreibe zunächst erst einmal nur die
Funktion zur Serialisierung des Textes eines Attributs.

HymarlOfPbml.py

import html

class HymarlWriter:
def attribute( self, text ):
return html.escape( text )

Damit habe ich schon ein lauffähiges Python-Skript, das hier ohne
Fehlermeldung ausgeführt werden kann!

2. Schritt: Der Test

Im Nachhinein betrachtet, hätte ich den Test zuerst schreiben
sollen. Nun ist es aber zu spät! Ich bitte einen AI Chatbot,
einen Test für das obige Skript zu schreiben, und kopiere
diesen in mein Skript hinein. Dies ist nötig, da ich selber
nie gelernt habe, wie man Unit-Tests in Python schreibt!

HymarlOfPbml.py

import unittest
import html

class HymarlWriter:
def attribute( self, text ):
return html.escape( text )

class TestHymarlWriter(unittest.TestCase):
def setUp(self):
self.writer = HymarlWriter()

# Checks that the `attribute()` function correctly handles a normal
# string without any special characters.
def test_attribute_with_normal_text( self ):
text = "This is a normal string."
expected = "This is a normal string."
self.assertEqual( self.writer.attribute( text ), expected )

# Checks that the `attribute()` function correctly escapes special
# characters like `&`, `<`, and `>`.
def test_attribute_with_special_characters( self ):
text = "This & that < more > text."
expected = "This &amp; that &lt; more &gt; text."
self.assertEqual( self.writer.attribute( text ), expected )

# Checks that the `attribute()` function correctly handles an empty
# string.
def test_attribute_with_empty_string( self ):
text = ""
expected = ""
self.assertEqual( self.writer.attribute( text ), expected )

if __name__ == '__main__':
unittest.main()

sys.stderr

....
----------------------------------------------------------------------
Ran 3 tests

OK

Zusammenfassung: Damit habe ich nun eine Klasse geschrieben, die
es erlaubt, einen Attributwert nach HTML/XML zu serialisieren.

Hier, was der Chatbot zu meinem Skript meint:

|Overall, this script is a simple and straightforward
|implementation of a common task in web development, and it
|could be a useful utility in a larger Python project that
|involves generating HTML output.


rocksolid / de.comp.lang.python / Neuer Site-Generator, Erste Schritte

1
server_pubkey.txt

rocksolid light 0.9.136
clearnet tor