From e8352dfe3da77944b59a64b1a579644c42c05851 Mon Sep 17 00:00:00 2001 From: Adam Bem Date: Thu, 26 Jan 2023 13:33:48 +0100 Subject: [PATCH] Housekeeping --- Backend-libXML/.gitignore | 3 +++ Backend-libXML/Parser.py | 21 +++++++++++++----- .../__pycache__/Parser.cpython-310.pyc | Bin 1653 -> 0 bytes .../__pycache__/server.cpython-310.pyc | Bin 1419 -> 0 bytes Backend-libXML/sample/xpath.json | 6 ----- Backend-libXML/sample/xpath/data.json | 6 +++++ Backend-libXML/sample/xpath/dataNS.json | 6 +++++ .../sample/{xpath.curl => xpath/non-ns.conf} | 2 +- Backend-libXML/sample/xpath/ns.conf | 5 +++++ Backend-libXML/sample/{ => xsd}/xsd.curl | 3 ++- Backend-libXML/sample/{ => xsd}/xsd.json | 0 Backend-libXML/sample/{ => xslt}/xslt.curl | 0 Backend-libXML/sample/{ => xslt}/xslt.json | 0 13 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 Backend-libXML/.gitignore delete mode 100644 Backend-libXML/__pycache__/Parser.cpython-310.pyc delete mode 100644 Backend-libXML/__pycache__/server.cpython-310.pyc delete mode 100644 Backend-libXML/sample/xpath.json create mode 100644 Backend-libXML/sample/xpath/data.json create mode 100644 Backend-libXML/sample/xpath/dataNS.json rename Backend-libXML/sample/{xpath.curl => xpath/non-ns.conf} (85%) create mode 100644 Backend-libXML/sample/xpath/ns.conf rename Backend-libXML/sample/{ => xsd}/xsd.curl (52%) rename Backend-libXML/sample/{ => xsd}/xsd.json (100%) rename Backend-libXML/sample/{ => xslt}/xslt.curl (100%) rename Backend-libXML/sample/{ => xslt}/xslt.json (100%) diff --git a/Backend-libXML/.gitignore b/Backend-libXML/.gitignore new file mode 100644 index 0000000..9ca9383 --- /dev/null +++ b/Backend-libXML/.gitignore @@ -0,0 +1,3 @@ +.idea +__pycache** +venv diff --git a/Backend-libXML/Parser.py b/Backend-libXML/Parser.py index ca60571..a76f67d 100644 --- a/Backend-libXML/Parser.py +++ b/Backend-libXML/Parser.py @@ -4,20 +4,24 @@ from lxml import etree def xpath(source: str, xpath: str) -> str: """ Method used to get nodes from XML string using XPath + :param source: XML string used for selection + :type source: str :param xpath: XPath query used for selection + :type xpath: str :return: Nodes selected using XPath + :rtype: str """ + + root = etree.XML(source) nsmap = root.nsmap # LXML doesn't accept namespace with None key, # so it need to be deleted if exists - try: + if None in nsmap: nsmap.pop(None) - except KeyError: - print(end="") - + result = root.xpath(xpath, namespaces=nsmap) result_string = "" for e in result: @@ -30,8 +34,11 @@ def xsd(source: str, xsd: str) -> bool: """ Method used to validate XML string against XSD schema :param source: XML string used for validation + :type source: str :param xsd: XSD schema to validate XML against + :type xsd: str :return: If the validation was successful or not + :rtype: bool """ xml_schema = etree.XMLSchema(etree.XML(xsd)) @@ -43,9 +50,13 @@ def xsd(source: str, xsd: str) -> bool: def xslt(source: str, xslt: str) -> str: """ Method used to transformate XML string using XSLT - :param source: Transformed XML string + + :param source: XML string to transform + :type source: str :param xslt: XSLT string used to transformate XML + :type xslt: str :return: Result of transformation + :rtype: str """ xslt_transform = etree.XSLT(etree.XML(xslt)) diff --git a/Backend-libXML/__pycache__/Parser.cpython-310.pyc b/Backend-libXML/__pycache__/Parser.cpython-310.pyc deleted file mode 100644 index a6014e16c40ec22553faf399efcce4c6c63a711d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1653 zcmaJ?KW`g16eo|o(^;{VOioiID2FaW(F*9+iQO^2e6VZ;XN1}F?hq%0+OM}?$f z%Q#KR>aS4PV?Rc>t{uy@L(#9$rG1YlDY9UM0?Fg!`~Q27GFw}10^^rQfAs%O3Hb{T zt0RNM*D&2vSQJsTASHc9DN%_|6obiiGRRb_*jxULMQRqQ9H=do0X2=(e960^a-e3a zeL%Xm{sFzDOGB!?)jDL(Ol)6=^lU8sFl1KyiLLqxa?M8z_8jK7Fx_idJh`MbxuUbA zPF^H4cHXMlB~$bY-29PL9Zo!-KA;4D9-L9^0&adH6+I;&k=3+jieDr%u98_=^T*`p z+q0}rJ$ccpF|_O=xy-MKYTYGYkXibwTc_Z9e*Sw~z<8ql&?qr+S_yB&iT0v0N;@&I zrW8j{c7^kHRGk0^u1EV2SQOkDODjv!M7(pI6LbxX6;2nr??tTXO=rGpDi|>E8Yn5U6_J$o@+R;nQOD9DM8TOY5}# zY&?yo&>8muEbUfC6W*blv_q5sI*ikt-lrVGKXd9@p`i%$L{n%V!v_``%%q0W!g7n> zSa_^XE?Ld4D3k>~|MRA@crA;Ol3uUEEKlU9a$X!AJQl7$)TLa7`F(XU*S205PC;2L zm0>krGds7}7+I9Y_XFXFdcg=9#i?|{P5OYp8%zoTWmp*>g}S`KegpD*5FNI+ATJ?b zm;r_eE+#s(&&uMsi3^fj77@l~xeNCenI6D&_{iL8wUc%d_?avGH53qmB?_Oz;e9C7 z>s~pPh$rN1Bfha$Yt|)(Q0^0$4*v`gi9E@nE%v&tzzakUJKlbTOKfWX+?XQbXHj%T9d@ckbVL4SY1E|9 SUr{(Ye6TmkHru}UVdsB)p|~{w diff --git a/Backend-libXML/__pycache__/server.cpython-310.pyc b/Backend-libXML/__pycache__/server.cpython-310.pyc deleted file mode 100644 index 6fdb3a0027d0f60b11cc74ddaea3f225ba6c6361..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1419 zcmb_cOK%e~5VpPc?&jH)XL*OmB?kxs2_aD-R0J1Z6-5HVAzEV7rtBkl9hyc7LMm4f zcP{ObpTpHxPMo=cc+5C$;ewzNyYe^V&*Pc#c;u{7DH8bJT>8*?7ZCChC%=CjCRbqO zZviBcG$sjcQHnYPowbpILe=b5@_|TuX2N&GFqwI zL%%ubMP|wJ`8x~u&?Hf2DU*2z_ilY~c7m0-3ghz(CB%?*xVBU* zBn#wy`L^XUGLa2>I_s!Bx4u?+KQ@-#xncd>M5dox@7mqF-79lbWXR8)J^#dV(@oTH zI_^FmB=Na=_FU;U>^O4S#wqkOr zmANQa*9INcGhNu> z+8FCS(RHx;aU<1&bCAnF zcB{tL)gi!U0rfNzyAZH+dN;xz0PBGty$`4R5oQn$05k%95cNX{ClL-K96>mWa15co z4aZSKJI9~cnhgac8k_%-DMv?tP4yH;{)bf2?mXJMRB_g*TJZ#*49$@D04&FT)cD{{ zD&vah>K3-!X$0-pwqDfhS)sGOQSNRg)pB{%apNz*8rg6*$z(rP@B+XSiZw2iGTc1& P0{mW;6=`)hjw<~L)`c#S diff --git a/Backend-libXML/sample/xpath.json b/Backend-libXML/sample/xpath.json deleted file mode 100644 index 70faa16..0000000 --- a/Backend-libXML/sample/xpath.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "data": "Hamlet2001-05-041falseMacbeth2000-12-131falseHarry Potter and the Sorcerer's Stone2005-04-292trueThe Long Walk2018-07-014trueMisery2018-01-314trueThink and Grow Rich2004-09-106trueThe Law of Success1982-05-096falsePatriot Games1995-10-215falseThe Sum of All Fears1992-09-195falseThe Alchemist2017-02-203falseHamlet1994-06-011falseMeasure for Measure1990-03-231falseHamlet1989-05-051trueHamlet1999-05-301trueThe Law of Success2004-11-266trueRomeo and Juliet1997-02-081trueThe Alchemist2009-08-213true", - "process": "/books/book[name = 'The Law of Success']", - "processor": "saxon", - "version": "2.0" -} diff --git a/Backend-libXML/sample/xpath/data.json b/Backend-libXML/sample/xpath/data.json new file mode 100644 index 0000000..2de1632 --- /dev/null +++ b/Backend-libXML/sample/xpath/data.json @@ -0,0 +1,6 @@ +{ + "data": "Hamlet2001-05-041falseMacbeth2000-12-131falseHarry Potter and the Sorcerer's Stone2005-04-292trueThe Long Walk2018-07-014trueMisery2018-01-314trueThink and Grow Rich2004-09-106trueThe Law of Success1982-05-096falsePatriot Games1995-10-215falseThe Sum of All Fears1992-09-195falseThe Alchemist2017-02-203falseHamlet1994-06-011falseMeasure for Measure1990-03-231falseHamlet1989-05-051trueHamlet1999-05-301trueThe Law of Success2004-11-266trueRomeo and Juliet1997-02-081trueThe Alchemist2009-08-213true", + "process": "/books/book[name = 'The Law of Success']", + "processor": "saxon", + "version": "2.0" +} diff --git a/Backend-libXML/sample/xpath/dataNS.json b/Backend-libXML/sample/xpath/dataNS.json new file mode 100644 index 0000000..ec5eb94 --- /dev/null +++ b/Backend-libXML/sample/xpath/dataNS.json @@ -0,0 +1,6 @@ +{ + "data": "Hamlet2001-05-041falseMacbeth2000-12-131falseHarry Potter and the Sorcerer's Stone2005-04-292trueThe Long Walk2018-07-014trueMisery2018-01-314trueThink and Grow Rich2004-09-106trueThe Law of Success1982-05-096falsePatriot Games1995-10-215falseThe Sum of All Fears1992-09-195falseThe Alchemist2017-02-203falseHamlet1994-06-011falseMeasure for Measure1990-03-231falseHamlet1989-05-051trueHamlet1999-05-301trueThe Law of Success2004-11-266trueRomeo and Juliet1997-02-081trueThe Alchemist2009-08-213true", + "process": "/b:books/b:book[b:name = 'The Law of Success']", + "processor": "saxon", + "version": "2.0" +} diff --git a/Backend-libXML/sample/xpath.curl b/Backend-libXML/sample/xpath/non-ns.conf similarity index 85% rename from Backend-libXML/sample/xpath.curl rename to Backend-libXML/sample/xpath/non-ns.conf index f72790a..064cfbf 100644 --- a/Backend-libXML/sample/xpath.curl +++ b/Backend-libXML/sample/xpath/non-ns.conf @@ -1,5 +1,5 @@ #url = "localhost:8081/xpathpost" url = "localhost:5000/xpath" request = "POST" -data = "@xpath.json" +data = "@data.json" header = "Content-Type: application/json" diff --git a/Backend-libXML/sample/xpath/ns.conf b/Backend-libXML/sample/xpath/ns.conf new file mode 100644 index 0000000..6f098cc --- /dev/null +++ b/Backend-libXML/sample/xpath/ns.conf @@ -0,0 +1,5 @@ +#url = "localhost:8081/xpathpost" +url = "localhost:5000/xpath" +request = "POST" +data = "@dataNS.json" +header = "Content-Type: application/json" diff --git a/Backend-libXML/sample/xsd.curl b/Backend-libXML/sample/xsd/xsd.curl similarity index 52% rename from Backend-libXML/sample/xsd.curl rename to Backend-libXML/sample/xsd/xsd.curl index 9c1ce6a..b9e65d1 100644 --- a/Backend-libXML/sample/xsd.curl +++ b/Backend-libXML/sample/xsd/xsd.curl @@ -1,4 +1,5 @@ -url = "http://localhost:8082/xsd" +#url = "http://localhost:8082/xsd" +url = "http://localhost:5000/xsd" data = "@xsd.json" header = "Content-Type: application/json" request = POST diff --git a/Backend-libXML/sample/xsd.json b/Backend-libXML/sample/xsd/xsd.json similarity index 100% rename from Backend-libXML/sample/xsd.json rename to Backend-libXML/sample/xsd/xsd.json diff --git a/Backend-libXML/sample/xslt.curl b/Backend-libXML/sample/xslt/xslt.curl similarity index 100% rename from Backend-libXML/sample/xslt.curl rename to Backend-libXML/sample/xslt/xslt.curl diff --git a/Backend-libXML/sample/xslt.json b/Backend-libXML/sample/xslt/xslt.json similarity index 100% rename from Backend-libXML/sample/xslt.json rename to Backend-libXML/sample/xslt/xslt.json