Skip to content

Commit

Permalink
Uri + OSDU json serialization
Browse files Browse the repository at this point in the history
* bugfix for date

* exception will not be raise for a notFound CRS during mesh reading. 

* An error is now printed for UnknownProperty exception during xml parsing (case of xsi:type filled without namespace specified)

* epc improvement, bugfix in mesh reading

*  new tests

* adding uri class

* json serialization/deserialization for OSDU official version

* using logging
  • Loading branch information
valentin-gauthier-geosiris authored Jun 14, 2024
1 parent f66a0e1 commit 7b01a78
Show file tree
Hide file tree
Showing 29 changed files with 3,767 additions and 963 deletions.
16 changes: 8 additions & 8 deletions energyml-utils/docs/src/energyml/utils/manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>
import re
from typing import List, Union, Any

REGEX_ENERGYML_MODULE_NAME = r&#34;energyml\.(?P&lt;pkg&gt;.*)\.v(?P&lt;version&gt;(?P&lt;versionNumber&gt;\d+(_\d+)*)(_dev(?P&lt;versionDev&gt;.*))?)\..*&#34;
REGEX_PROJECT_VERSION = r&#34;(?P&lt;n0&gt;[\d]+)(.(?P&lt;n1&gt;[\d]+)(.(?P&lt;n2&gt;[\d]+))?)?&#34;
RGX_ENERGYML_MODULE_NAME = r&#34;energyml\.(?P&lt;pkg&gt;.*)\.v(?P&lt;version&gt;(?P&lt;versionNumber&gt;\d+(_\d+)*)(_dev(?P&lt;versionDev&gt;.*))?)\..*&#34;
RGX_PROJECT_VERSION = r&#34;(?P&lt;n0&gt;[\d]+)(.(?P&lt;n1&gt;[\d]+)(.(?P&lt;n2&gt;[\d]+))?)?&#34;

ENERGYML_MODULES_NAMES = [&#34;eml&#34;, &#34;prodml&#34;, &#34;witsml&#34;, &#34;resqml&#34;]

Expand Down Expand Up @@ -196,7 +196,7 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>

def get_class_pkg(cls):
try:
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(cls.__module__)
return m.group(&#34;pkg&#34;)
except AttributeError as e:
Expand All @@ -210,7 +210,7 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>
else, the original version is returned.
Example : reshapeVersion(&#34;v2.0.1&#34;, 2) ==&gt; &#34;2.0&#34; and reshapeVersion(&#34;version2.0.1.3.2.5&#34;, 4) ==&gt; &#34;version2.0.1.3.2.5&#34;
&#34;&#34;&#34;
p = re.compile(REGEX_PROJECT_VERSION)
p = re.compile(RGX_PROJECT_VERSION)
m = p.search(version)
if m is not None:
n0 = m.group(&#34;n0&#34;)
Expand All @@ -233,7 +233,7 @@ <h1 class="title">Module <code>src.energyml.utils.manager</code></h1>
def get_class_pkg_version(
cls, print_dev_version: bool = True, nb_max_version_digits: int = 2
):
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(
cls.__module__ if isinstance(cls, type) else type(cls).__module__
)
Expand Down Expand Up @@ -364,7 +364,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</summary>
<pre><code class="python">def get_class_pkg(cls):
try:
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(cls.__module__)
return m.group(&#34;pkg&#34;)
except AttributeError as e:
Expand All @@ -384,7 +384,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<pre><code class="python">def get_class_pkg_version(
cls, print_dev_version: bool = True, nb_max_version_digits: int = 2
):
p = re.compile(REGEX_ENERGYML_MODULE_NAME)
p = re.compile(RGX_ENERGYML_MODULE_NAME)
m = p.search(
cls.__module__ if isinstance(cls, type) else type(cls).__module__
)
Expand Down Expand Up @@ -554,7 +554,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
else, the original version is returned.
Example : reshapeVersion(&#34;v2.0.1&#34;, 2) ==&gt; &#34;2.0&#34; and reshapeVersion(&#34;version2.0.1.3.2.5&#34;, 4) ==&gt; &#34;version2.0.1.3.2.5&#34;
&#34;&#34;&#34;
p = re.compile(REGEX_PROJECT_VERSION)
p = re.compile(RGX_PROJECT_VERSION)
m = p.search(version)
if m is not None:
n0 = m.group(&#34;n0&#34;)
Expand Down
56 changes: 28 additions & 28 deletions energyml-utils/docs/src/energyml/utils/xml.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,46 @@ <h1 class="title">Module <code>src.energyml.utils.xml</code></h1>
dict of all energyml namespace packages
&#34;&#34;&#34; # pylint: disable=W0105

REGEX_UUID_NO_GRP = (
RGX_UUID_NO_GRP = (
r&#34;[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}&#34;
)
REGEX_UUID = r&#34;(?P&lt;uuid&gt;&#34; + REGEX_UUID_NO_GRP + &#34;)&#34;
REGEX_DOMAIN_VERSION = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNum&gt;([\d]+[\._])*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;
REGEX_DOMAIN_VERSION_FLAT = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNumFlat&gt;([\d]+)*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;
RGX_UUID = r&#34;(?P&lt;uuid&gt;&#34; + RGX_UUID_NO_GRP + &#34;)&#34;
RGX_DOMAIN_VERSION = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNum&gt;([\d]+[\._])*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;
RGX_DOMAIN_VERSION_FLAT = r&#34;(?P&lt;domainVersion&gt;(?P&lt;versionNumFlat&gt;([\d]+)*\d)\s*(?P&lt;dev&gt;dev\s*(?P&lt;devNum&gt;[\d]+))?)&#34;


# ContentType
REGEX_MIME_TYPE_MEDIA = r&#34;(?P&lt;media&gt;application|audio|font|example|image|message|model|multipart|text|video)&#34;
REGEX_CT_ENERGYML_DOMAIN = r&#34;(?P&lt;energymlDomain&gt;x-(?P&lt;domain&gt;[\w]+)\+xml)&#34;
REGEX_CT_XML_DOMAIN = r&#34;(?P&lt;xmlRawDomain&gt;(x\-)?(?P&lt;xmlDomain&gt;.+)\+xml)&#34;
REGEX_CT_TOKEN_VERSION = r&#34;version=&#34; + REGEX_DOMAIN_VERSION
REGEX_CT_TOKEN_TYPE = r&#34;type=(?P&lt;type&gt;[\w\_]+)&#34;

REGEX_CONTENT_TYPE = (
REGEX_MIME_TYPE_MEDIA + &#34;/&#34;
+ &#34;(?P&lt;rawDomain&gt;(&#34; + REGEX_CT_ENERGYML_DOMAIN + &#34;)|(&#34; + REGEX_CT_XML_DOMAIN + r&#34;)|([\w-]+\.?)+)&#34;
+ &#34;(;((&#34; + REGEX_CT_TOKEN_VERSION + &#34;)|(&#34; + REGEX_CT_TOKEN_TYPE + &#34;)))*&#34;
RGX_MIME_TYPE_MEDIA = r&#34;(?P&lt;media&gt;application|audio|font|example|image|message|model|multipart|text|video)&#34;
RGX_CT_ENERGYML_DOMAIN = r&#34;(?P&lt;energymlDomain&gt;x-(?P&lt;domain&gt;[\w]+)\+xml)&#34;
RGX_CT_XML_DOMAIN = r&#34;(?P&lt;xmlRawDomain&gt;(x\-)?(?P&lt;xmlDomain&gt;.+)\+xml)&#34;
RGX_CT_TOKEN_VERSION = r&#34;version=&#34; + RGX_DOMAIN_VERSION
RGX_CT_TOKEN_TYPE = r&#34;type=(?P&lt;type&gt;[\w\_]+)&#34;

RGX_CONTENT_TYPE = (
RGX_MIME_TYPE_MEDIA + &#34;/&#34;
+ &#34;(?P&lt;rawDomain&gt;(&#34; + RGX_CT_ENERGYML_DOMAIN + &#34;)|(&#34; + RGX_CT_XML_DOMAIN + r&#34;)|([\w-]+\.?)+)&#34;
+ &#34;(;((&#34; + RGX_CT_TOKEN_VERSION + &#34;)|(&#34; + RGX_CT_TOKEN_TYPE + &#34;)))*&#34;
)
REGEX_QUALIFIED_TYPE = (
r&#34;(?P&lt;domain&gt;[a-zA-Z]+)&#34; + REGEX_DOMAIN_VERSION_FLAT + r&#34;\.(?P&lt;type&gt;[\w_]+)&#34;
RGX_QUALIFIED_TYPE = (
r&#34;(?P&lt;domain&gt;[a-zA-Z]+)&#34; + RGX_DOMAIN_VERSION_FLAT + r&#34;\.(?P&lt;type&gt;[\w_]+)&#34;
)
# =========

REGEX_SCHEMA_VERSION = (
RGX_SCHEMA_VERSION = (
r&#34;(?P&lt;name&gt;[eE]ml|[cC]ommon|[rR]esqml|[wW]itsml|[pP]rodml)?\s*v?&#34;
+ REGEX_DOMAIN_VERSION
+ RGX_DOMAIN_VERSION
+ r&#34;\s*$&#34;
)

REGEX_ENERGYML_FILE_NAME_OLD = r&#34;(?P&lt;type&gt;[\w]+)_&#34; + REGEX_UUID_NO_GRP + r&#34;\.xml$&#34;
REGEX_ENERGYML_FILE_NAME_NEW = (
REGEX_UUID_NO_GRP + r&#34;\.(?P&lt;objectVersion&gt;\d+(\.\d+)*)\.xml$&#34;
RGX_ENERGYML_FILE_NAME_OLD = r&#34;(?P&lt;type&gt;[\w]+)_&#34; + RGX_UUID_NO_GRP + r&#34;\.xml$&#34;
RGX_ENERGYML_FILE_NAME_NEW = (
RGX_UUID_NO_GRP + r&#34;\.(?P&lt;objectVersion&gt;\d+(\.\d+)*)\.xml$&#34;
)
REGEX_ENERGYML_FILE_NAME = (
rf&#34;^(.*/)?({REGEX_ENERGYML_FILE_NAME_OLD})|({REGEX_ENERGYML_FILE_NAME_NEW})&#34;
RGX_ENERGYML_FILE_NAME = (
rf&#34;^(.*/)?({RGX_ENERGYML_FILE_NAME_OLD})|({RGX_ENERGYML_FILE_NAME_NEW})&#34;
)

REGEX_XML_HEADER = r&#34;^\s*\&lt;\?xml\s+((encoding\s*=\s*\&#34;(?P&lt;encoding&gt;[^\&#34;]+)\&#34;|version\s*=\s*\&#34;(?P&lt;version&gt;[^\&#34;]+)\&#34;|standalone\s*=\s*\&#34;(?P&lt;standalone&gt;[^\&#34;]+)\&#34;)\s+)+&#34;
RGX_XML_HEADER = r&#34;^\s*\&lt;\?xml\s+((encoding\s*=\s*\&#34;(?P&lt;encoding&gt;[^\&#34;]+)\&#34;|version\s*=\s*\&#34;(?P&lt;version&gt;[^\&#34;]+)\&#34;|standalone\s*=\s*\&#34;(?P&lt;standalone&gt;[^\&#34;]+)\&#34;)\s+)+&#34;


def get_pkg_from_namespace(namespace: str) -&gt; Optional[str]:
Expand Down Expand Up @@ -138,7 +138,7 @@ <h1 class="title">Module <code>src.energyml.utils.xml</code></h1>

def get_xml_encoding(xml_content: str) -&gt; Optional[str]:
try:
m = re.search(REGEX_XML_HEADER, xml_content)
m = re.search(RGX_XML_HEADER, xml_content)
return m.group(&#34;encoding&#34;)
except AttributeError:
return &#34;utf-8&#34;
Expand Down Expand Up @@ -207,7 +207,7 @@ <h1 class="title">Module <code>src.energyml.utils.xml</code></h1>


def parse_content_type(ct: str):
return re.search(REGEX_CONTENT_TYPE, ct)</code></pre>
return re.search(RGX_CONTENT_TYPE, ct)</code></pre>
</details>
</section>
<section>
Expand Down Expand Up @@ -402,7 +402,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</summary>
<pre><code class="python">def get_xml_encoding(xml_content: str) -&gt; Optional[str]:
try:
m = re.search(REGEX_XML_HEADER, xml_content)
m = re.search(RGX_XML_HEADER, xml_content)
return m.group(&#34;encoding&#34;)
except AttributeError:
return &#34;utf-8&#34;</code></pre>
Expand Down Expand Up @@ -432,7 +432,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">def parse_content_type(ct: str):
return re.search(REGEX_CONTENT_TYPE, ct)</code></pre>
return re.search(RGX_CONTENT_TYPE, ct)</code></pre>
</details>
</dd>
<dt id="src.energyml.utils.xml.search_element_has_child_xpath"><code class="name flex">
Expand Down
Loading

0 comments on commit 7b01a78

Please sign in to comment.