From 55946468fd3f5f24471613e22352595133701b60 Mon Sep 17 00:00:00 2001
From: "Thomas \"Cakeisalie5\" Touhey"
Date: Fri, 15 Mar 2019 22:06:01 +0100
Subject: [PATCH] Random things, still did not correct the issue.
---
Makefile | 11 ++--
Pipfile.lock | 90 +++++++++++++-------------
docs/tags.rst | 20 +++---
test/html.py | 1 +
textoutpc/_translate.py | 18 ++++--
textoutpc/builtin/_Video.py | 5 ++
textoutpc/color/_read.py | 123 ++++++++++++++++++++++++++++++++----
7 files changed, 195 insertions(+), 73 deletions(-)
diff --git a/Makefile b/Makefile
index 8bea6bd..598e30d 100755
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,16 @@
#!/usr/bin/make -f
- ST := pipenv run ./setup.py
+ PE := pipenv run
+ ST := $(PE) ./setup.py
DNAME := dist/$(shell $(ST) --name)-$(shell $(ST) --version).tar.gz
-prepare:
- @pipenv install --dev
-
test tests:
@$(ST) test
+prepare:
+ @pipenv install --dev
+update:
+ @pipenv update --dev
+
docs:
@$(ST) build_sphinx
diff --git a/Pipfile.lock b/Pipfile.lock
index 2176367..9f3e2a3 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -18,18 +18,18 @@
"default": {
"regex": {
"hashes": [
- "sha256:017bf6f893db109dc5f82b902019f6fe089e605af5e1f0f6f7271f936b411eb4",
- "sha256:0969fdb610435d7f49dc5518f7642d7b1319ef19f0c3f1bd4d972afbb9877aa7",
- "sha256:3679f269790c87bd04e003e60e098b1be5392f17c48d28c2a3b9d16b3dcbca2a",
- "sha256:37150aee3411f38d08733edb5f3faa656f96ddae00ee7713e01d7423f0f72815",
- "sha256:4a1a1d963f462c13722b34ef1f82c4707091b0a3fb9b5fd79b6670c38b734095",
- "sha256:5da76d468d048fb163bcaedd5c0832a3ab95da1034598a6c673bf999ae61f259",
- "sha256:72dda5123ee45cde10031576710ca0c4972757c94a60b75023a45d8069da34ca",
- "sha256:7f40b720b81f6614a34a8857d2417fbe619734629f9d0627e2cc9e493979401d",
- "sha256:a22a11e9dd6e46529dc4409bd6c449f3e7525aa4b0d5e9b23363302cfe4db8e4"
+ "sha256:0306149889c1a1bec362511f737bc446245ddfcdbe4b556abdfc506ed46dfa47",
+ "sha256:4b08704a5939c698d2d5950b5dc950597613216cc8c01048efc0da860a0c3db9",
+ "sha256:6ba0eb777ada6887062c2620e6d644b011078d5d3dc09119ae7107285f6f95e9",
+ "sha256:7789cc323948792c4c62b269a56f2f2f9bc77d44e54fd81e01b12a967dd7244c",
+ "sha256:825143aadca0da7d26eeaf2ab0f8bc33921a5642e570ded92dde08c5aaebc65f",
+ "sha256:8fbd057faab28ce552d89c46f7a968e950f07e80752dfb93891dd11c6b0ee3b4",
+ "sha256:a41aabb0b9072a14f1e2e554f959ed6439b83610ed656edace9096a0b27e378e",
+ "sha256:d8807231aed332a1d0456d2088967b87e8c664222bed8e566384ca0ec0b43bfd",
+ "sha256:dfd89b642fe71f4e8a9906455d4147d453061377b650e6233ddd9ea822971360"
],
"index": "pypi",
- "version": "==2019.2.7"
+ "version": "==2019.3.12"
}
},
"develop": {
@@ -49,10 +49,10 @@
},
"certifi": {
"hashes": [
- "sha256:47f9c83ef4c0c621eaef743f133f09fa8a74a9b75f037e8624f83bd1b6626cb7",
- "sha256:993f830721089fef441cdfeb4b2c8c9df86f0c63239f06bd025a76a7daddb033"
+ "sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
+ "sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae"
],
- "version": "==2018.11.29"
+ "version": "==2019.3.9"
},
"chardet": {
"hashes": [
@@ -99,36 +99,36 @@
},
"markupsafe": {
"hashes": [
- "sha256:048ef924c1623740e70204aa7143ec592504045ae4429b59c30054cb31e3c432",
- "sha256:130f844e7f5bdd8e9f3f42e7102ef1d49b2e6fdf0d7526df3f87281a532d8c8b",
- "sha256:19f637c2ac5ae9da8bfd98cef74d64b7e1bb8a63038a3505cd182c3fac5eb4d9",
- "sha256:1b8a7a87ad1b92bd887568ce54b23565f3fd7018c4180136e1cf412b405a47af",
- "sha256:1c25694ca680b6919de53a4bb3bdd0602beafc63ff001fea2f2fc16ec3a11834",
- "sha256:1f19ef5d3908110e1e891deefb5586aae1b49a7440db952454b4e281b41620cd",
- "sha256:1fa6058938190ebe8290e5cae6c351e14e7bb44505c4a7624555ce57fbbeba0d",
- "sha256:31cbb1359e8c25f9f48e156e59e2eaad51cd5242c05ed18a8de6dbe85184e4b7",
- "sha256:3e835d8841ae7863f64e40e19477f7eb398674da6a47f09871673742531e6f4b",
- "sha256:4e97332c9ce444b0c2c38dd22ddc61c743eb208d916e4265a2a3b575bdccb1d3",
- "sha256:525396ee324ee2da82919f2ee9c9e73b012f23e7640131dd1b53a90206a0f09c",
- "sha256:52b07fbc32032c21ad4ab060fec137b76eb804c4b9a1c7c7dc562549306afad2",
- "sha256:52ccb45e77a1085ec5461cde794e1aa037df79f473cbc69b974e73940655c8d7",
- "sha256:5c3fbebd7de20ce93103cb3183b47671f2885307df4a17a0ad56a1dd51273d36",
- "sha256:5e5851969aea17660e55f6a3be00037a25b96a9b44d2083651812c99d53b14d1",
- "sha256:5edfa27b2d3eefa2210fb2f5d539fbed81722b49f083b2c6566455eb7422fd7e",
- "sha256:7d263e5770efddf465a9e31b78362d84d015cc894ca2c131901a4445eaa61ee1",
- "sha256:83381342bfc22b3c8c06f2dd93a505413888694302de25add756254beee8449c",
- "sha256:857eebb2c1dc60e4219ec8e98dfa19553dae33608237e107db9c6078b1167856",
- "sha256:98e439297f78fca3a6169fd330fbe88d78b3bb72f967ad9961bcac0d7fdd1550",
- "sha256:bf54103892a83c64db58125b3f2a43df6d2cb2d28889f14c78519394feb41492",
- "sha256:d9ac82be533394d341b41d78aca7ed0e0f4ba5a2231602e2f05aa87f25c51672",
- "sha256:e982fe07ede9fada6ff6705af70514a52beb1b2c3d25d4e873e82114cf3c5401",
- "sha256:edce2ea7f3dfc981c4ddc97add8a61381d9642dc3273737e756517cc03e84dd6",
- "sha256:efdc45ef1afc238db84cb4963aa689c0408912a0239b0721cb172b4016eb31d6",
- "sha256:f137c02498f8b935892d5c0172560d7ab54bc45039de8805075e19079c639a9c",
- "sha256:f82e347a72f955b7017a39708a3667f106e6ad4d10b25f237396a7115d8ed5fd",
- "sha256:fb7c206e01ad85ce57feeaaa0bf784b97fa3cad0d4a5737bc5295785f5c613a1"
+ "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473",
+ "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161",
+ "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235",
+ "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5",
+ "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff",
+ "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b",
+ "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1",
+ "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e",
+ "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183",
+ "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66",
+ "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1",
+ "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1",
+ "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e",
+ "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b",
+ "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905",
+ "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735",
+ "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d",
+ "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e",
+ "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d",
+ "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c",
+ "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21",
+ "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2",
+ "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5",
+ "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b",
+ "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6",
+ "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f",
+ "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f",
+ "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"
],
- "version": "==1.1.0"
+ "version": "==1.1.1"
},
"packaging": {
"hashes": [
@@ -188,11 +188,11 @@
},
"sphinx": {
"hashes": [
- "sha256:b53904fa7cb4b06a39409a492b949193a1b68cc7241a1a8ce9974f86f0d24287",
- "sha256:c1c00fc4f6e8b101a0d037065043460dffc2d507257f2f11acaed71fd2b0c83c"
+ "sha256:9f3e17c64b34afc653d7c5ec95766e03043cc6d80b0de224f59b6b6e19d37c3c",
+ "sha256:c7658aab75c920288a8cf6f09f244c6cfdae30d82d803ac1634d9f223a80ca08"
],
"index": "pypi",
- "version": "==1.8.4"
+ "version": "==1.8.5"
},
"sphinxcontrib-websupport": {
"hashes": [
diff --git a/docs/tags.rst b/docs/tags.rst
index 4b29467..17a9d05 100644
--- a/docs/tags.rst
+++ b/docs/tags.rst
@@ -20,20 +20,22 @@ There are a few public members you can define as a tag:
- ``raw``: the tag's content shall not be interpreted, which is generally
only useful when the content is preprocessed (see below). The default
is ``False`` if there is no preprocess method, and `True` otherwise;
+- ``noinline``: for raw tags, forbid inline tags (declared outside of the
+ tag) within the tag (*only works with ``raw = True``*!);
- ``generic``: the tag can be ended using the generic tag ending mark ``[/]``.
It is defined as ``True`` by default for all tags;
- ``notempty``: ignore the tag when its content is empty. By default, this
value is `False`;
- ``superblock``: is a super-block (for blocks) which means it adds a block
- level, and adds a paragraph tag implicitely.
+ level, and adds a paragraph tag implicitely;
- ``inlined``: if is a block, transforms automatically the surrounding block
- into a superblock while it's there.
-- ``procvalue``: process the value as normal text before passing it.
+ into a superblock while it's there;
+- ``procvalue``: process the value as normal text before passing it;
- ``not_within_itself``: make that if a tag is opened within itself (depth
- included), the tag above and all tags below are closed first.
-- ``only_in``: allow the tag to only be beneath certain tags.
-- ``allowed_tags``: allowed tags right beneath the current one.
-- ``no_text``: disable raw text within the tag.
+ included), the tag above and all tags below are closed first;
+- ``only_in``: allow the tag to only be beneath certain tags;
+- ``allowed_tags``: allowed tags right beneath the current one;
+- ``no_text``: disable raw text within the tag;
- ``expect_child``: make that all content below (without depth) that isn't
within the specified tags is ignored.
@@ -42,9 +44,9 @@ with the alternate name ``[hai]``, I'd start off by writing:
.. code-block:: python
- from .__base__ import *
+ from textoutpc import InlineTag as _InlineTag
- class TextoutHelloTag(TextoutInlineTag):
+ class TextoutHelloTag(_InlineTag):
""" The [hello] tag, which does things.
Example uses:
diff --git a/test/html.py b/test/html.py
index 4a432a8..33f98b4 100755
--- a/test/html.py
+++ b/test/html.py
@@ -83,6 +83,7 @@ __test_cases = {
'color: rgba(1, 22, 242, 0.5)">a
',
'[color=rgba(1,22,242,0.500)]a': 'a
',
+ '[color=rbga(5, 7)]b': 'b
',
'[color=hsl(0, 1,50.0%)]r': 'r
',
# TODO: hls, hwb
diff --git a/textoutpc/_translate.py b/textoutpc/_translate.py
index 60ce90b..f3a9c50 100755
--- a/textoutpc/_translate.py
+++ b/textoutpc/_translate.py
@@ -36,7 +36,13 @@ class _TweaksDictionary:
return f"{self.__class__.__name__}({repr(self.__elts)})"
def __getitem__(self, key):
- return self.__elts[key]
+ return self.__elts[self.__normalize(key)]
+
+ def __getattr__(self, key):
+ try:
+ return self.__elts[self.__normalize(key)]
+ except:
+ raise AttributeError(key)
def __normalize(self, name):
return ''.join(c for c in name if c in _string.ascii_letters).lower()
@@ -118,6 +124,9 @@ class _TagData:
self.inlined = bool(tag.inlined) if self.super \
and hasattr(tag, 'inlined') and bool(tag.inlined) else False
+ self.noinline = bool(tag.noinline) if self.type == self.BLOCK \
+ and hasattr(tag, 'noinline') else False
+
# Content processing utilities.
# `last` is the content of the tag. A boolean indicates that we
# only want to know if the content is empty or not, and a string
@@ -143,7 +152,7 @@ class _TagData:
self.last = ""
def __repr__(self):
- return ''
+ return f'TagData(tag = {repr(self.tag)})'
# ---
# Translator main class.
@@ -633,8 +642,9 @@ class Translator:
# Then, put the tag beginnings.
to_begin = superblocks \
- + ([block_to_start] if block_to_start else []) \
- + inlines
+ + ([block_to_start] if block_to_start else [])
+ if all(not x.noinline for x in to_begin):
+ to_begin += inlines
for dat in to_begin:
if dat.started:
diff --git a/textoutpc/builtin/_Video.py b/textoutpc/builtin/_Video.py
index b20dc45..05b2f35 100755
--- a/textoutpc/builtin/_Video.py
+++ b/textoutpc/builtin/_Video.py
@@ -28,6 +28,7 @@ class VideoTag(_BlockTag):
aliases = ('[video]', '[video tiny]')
raw = True
+ noinline = True
def prepare(self, name, value):
""" Prepare the video tag. """
@@ -36,9 +37,13 @@ class VideoTag(_BlockTag):
'center': ('center', False),
'centre': ('center', False),
'left': ('left', False),
+ 'gauche': ('left', False),
'right': ('right', False),
+ 'droite': ('right', False),
'float': (None, True),
'floating': (None, True),
+ 'flotte': (None, True),
+ 'flottant': (None, True),
'float-left': ('left', True),
'float-center': ('center', True),
'float-centre': ('center', True),
diff --git a/textoutpc/color/_read.py b/textoutpc/color/_read.py
index 0c800ed..98e8e53 100755
--- a/textoutpc/color/_read.py
+++ b/textoutpc/color/_read.py
@@ -17,13 +17,94 @@ __all__ = ["get_color"]
_cr = _re.compile("""
rgba?\s*\(
- \s* (?P[0-9]{1,3}) \s* ([,\\s]
- \s* (?P[0-9]{1,3}) \s* ([,\\s]
- \s* (?P[0-9]{1,3}) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s/]
\s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
|(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
)?)?)?
\)|
+ rbga?\s*\(
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?)?)?
+ \)|
+ brga?\s*\(
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?)?)?
+ \)|
+ bgra?\s*\(
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?)?)?
+ \)|
+ grba?\s*\(
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?)?)?
+ \)|
+ gbra?\s*\(
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s]
+ \s* ((?P[0-9]{1,3})
+ |(?P ([0-9]+\.?|[0-9]*\.[0-9]+)) \s*%) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?)?)?
+ \)|
+ lab\s*\(
+ \s* (?P-?[0-9]{1,3}) \s* [,\\s]
+ \s* (?P-?[0-9]{1,3}) \s* [,\\s]
+ \s* (?P-?[0-9]{1,3}) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?
+ \)|
+ lch\s*\(
+ \s* (?P-?[0-9]{1,3}) \s* [,\\s]
+ \s* (?P-?[0-9]{1,3}) \s* [,\\s]
+ \s* (?P-? ([0-9]+\.?|[0-9]*\.[0-9]+) )
+ (?Pdeg|grad|rad|turn|) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?
+ \)|
+ gray\s*\(
+ \s* (?P-?[0-9]{1,3}) \s* ([,\\s/]
+ \s* ((?P ([0-9]+\.?|[0-9]*\.[0-9]+) ) \s*%
+ |(?P (0*[01]\.?|0*\.[0-9]+) )) \s*
+ )?
+ \)|
hsla?\s*\(
\s* (?P-? ([0-9]+\.?|[0-9]*\.[0-9]+) )
(?Pdeg|grad|rad|turn|) \s*[,\\s]
@@ -60,6 +141,8 @@ _cr = _re.compile("""
(?P [0-9a-z]+)
""", _re.VERBOSE | _re.I | _re.M)
+_rgb = ('rgb', 'rbg', 'brg', 'bgr', 'grb', 'gbr')
+
def get_color(value):
""" Get a color from a string.
Returns an (r, g, b, a) color.
@@ -107,10 +190,12 @@ def get_color(value):
hx = match['hex_digits'].lower()
# RGB and RGBA (3 and 4 char.) notations.
+
if len(hx) in (3, 4):
hx = hx[0:1] * 2 + hx[1:2] * 2 + hx[2:3] * 2 + hx[3:4] * 2
# Check if there is transparency or not.
+
if len(hx) % 3 != 0 and len(hx) % 4 == 0:
members = 4
@@ -148,17 +233,31 @@ def get_color(value):
else:
r, g, b, alpha = it
alpha /= 255.0
- elif match['rgb_r']:
+ elif any(match[key + '_r'] or match[key + '_r_per'] for key in _rgb):
# Extract the values.
- r = int(match['rgb_r'])
- g = int(match['rgb_g']) if match['rgb_g'] else 0
- b = int(match['rgb_b']) if match['rgb_b'] else 0
+ for key in _rgb:
+ if not match[key + '_r'] and not match[key + '_r_per']:
+ continue
- if match['rgb_a_per']:
- alpha = float(match['rgb_a_per']) / 100.0
- elif match['rgb_a_flt']:
- alpha = float(match['rgb_a_flt'])
+ r = match[f'{key}_r']
+ rp = match[f'{key}_r_per']
+ g = match[f'{key}_g']
+ gp = match[f'{key}_g_per']
+ b = match[f'{key}_b']
+ bp = match[f'{key}_b_per']
+ ap = match[f'{key}_a_per']
+ af = match[f'{key}_a_flt']
+ break
+
+ r = int(r) if r else int(int(rp) * 255 / 100)
+ g = int(g) if g else int(int(gp) * 255 / 100) if gp else 0
+ b = int(b) if b else int(int(bp) * 255 / 100) if bp else 0
+
+ if ap:
+ alpha = float(ap) / 100.0
+ elif af:
+ alpha = float(af)
elif match['hsl_hue'] or match['hls_hue']:
# Extract the values.
@@ -252,6 +351,8 @@ def get_color(value):
raise Exception
r, g, b = _hwb_to_rgb(hue, wht, blk)
r, g, b = map(lambda x: int(round(x * 255)), (r, g, b))
+ else:
+ raise ValueError("unsupported format yet")
if r < 0 or r > 255 or g < 0 or g > 255 or b < 0 or b > 255:
raise ValueError("invalid color string")