webcode-tk 0.7.0__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webcode-tk
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary:
5
5
  Home-page: https://github.com/HundredVisionsGuy/webcode-tk
6
6
  License: MIT
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.8
15
15
  Classifier: Programming Language :: Python :: 3.9
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
18
19
  Requires-Dist: MechanicalSoup (>=1.1.0,<2.0.0)
19
20
  Requires-Dist: bs4 (>=0.0.1,<0.0.2)
20
21
  Requires-Dist: file-clerk (>=1.0.9,<2.0.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "webcode-tk"
3
- version = "0.7.0"
3
+ version = "0.7.1"
4
4
  description = ""
5
5
  authors = ["hundredvisionsguy <cwinikka@gmail.com>"]
6
6
  keywords = ["html", "validation", "css", ]
@@ -15,4 +15,4 @@ Modules exported by this package:
15
15
  - `validator`: sends HTML or CSS code to the W3C Validator to check
16
16
  for errors.
17
17
  """
18
- __version__ = "0.7.0"
18
+ __version__ = "0.7.1"
@@ -12,7 +12,6 @@ basic_color_keywords = {
12
12
  "black": "#000000",
13
13
  "silverk": "#C0C0C0",
14
14
  "grayk": "#808080",
15
- "greyk": "#808080",
16
15
  "whitek": "#FFFFFF",
17
16
  "maroon": "#800000",
18
17
  "red": "#FF0000",
@@ -54,7 +53,6 @@ extended_color_keywords = [
54
53
  "darkcyan - #008B8B - rgb(0, 139, 139) - Shades",
55
54
  "darkgoldenrod - #B8860B - rgb(184, 134, 11) - Shades",
56
55
  "darkgray - #A9A9A9 - rgb(169, 169, 169) - Shades",
57
- "darkgrey - #A9A9A9 - rgb(169, 169, 169) - Shades",
58
56
  "darkgreen - #006400 - rgb(0, 100, 0) - Shades",
59
57
  "darkkhaki - #BDB76B - rgb(189, 183, 107) - Shades",
60
58
  "darkmagenta - #8B008B - rgb(139, 0, 139) - Shades",
@@ -66,13 +64,11 @@ extended_color_keywords = [
66
64
  "darkseagreen - #8FBC8F - rgb(143, 188, 143) - Shades",
67
65
  "darkslateblue - #483D8B - rgb(72, 61, 139) - Shades",
68
66
  "darkslategray - #2F4F4F - rgb(47, 79, 79) - Shades",
69
- "darkslategrey - #2F4F4F - rgb(47, 79, 79) - Shades",
70
67
  "darkturquoise - #00CED1 - rgb(0, 206, 209) - Shades",
71
68
  "darkviolet - #9400D3 - rgb(148, 0, 211) - Shades",
72
69
  "deeppink - #FF1493 - rgb(255, 20, 147) - Shades",
73
70
  "deepskyblue - #00BFFF - rgb(0, 191, 255) - Shades",
74
71
  "dimgray - #696969 - rgb(0, 191, 255) - Shades",
75
- "dimgrey - #696969 - rgb(0, 191, 255) - Shades",
76
72
  "dodgerblue - #1E90FF - rgb(30, 144, 255) - Shades",
77
73
  "firebrick - #B22222 - rgb(178, 34, 34) - Shades",
78
74
  "floralwhite - #FFFAF0 - rgb(255, 250, 240) - Shades",
@@ -83,7 +79,6 @@ extended_color_keywords = [
83
79
  "gold - #FFD700 - rgb(255, 215, 0) - Shades",
84
80
  "goldenrod - #DAA520 - rgb(218, 165, 32) - Shades",
85
81
  "gray - #7F7F7F - rgb(127, 127, 127) - Shades",
86
- "grey - #7F7F7F - rgb(127, 127, 127) - Shades",
87
82
  "green - #008000 - rgb(0, 128, 0) - Shades",
88
83
  "greenyellow - #ADFF2F - rgb(173, 255, 47) - Shades",
89
84
  "honeydew - #F0FFF0 - rgb(240, 255, 240) - Shades",
@@ -107,7 +102,6 @@ extended_color_keywords = [
107
102
  "lightseagreen - #20B2AA - rgb(32, 178, 170) - Shades",
108
103
  "lightskyblue - #87CEFA - rgb(135, 206, 250) - Shades",
109
104
  "lightslategray - #778899 - rgb(119, 136, 153) - Shades",
110
- "lightslategrey - #778899 - rgb(119, 136, 153) - Shades",
111
105
  "lightsteelblue - #B0C4DE - rgb(176, 196, 222) - Shades",
112
106
  "lightyellow - #FFFFE0 - rgb(255, 255, 224) - Shades",
113
107
  "lime - #00FF00 - rgb(0, 255, 0) - Shades",
@@ -162,7 +156,6 @@ extended_color_keywords = [
162
156
  "skyblue - #87CEEB - rgb(135, 206, 235) - Shades",
163
157
  "slateblue - #6A5ACD - rgb(106, 90, 205) - Shades",
164
158
  "slategray - #708090 - rgb(112, 128, 144) - Shades",
165
- "slategrey - #708090 - rgb(112, 128, 144) - Shades",
166
159
  "snow - #FFFAFA - rgb(255, 250, 250) - Shades",
167
160
  "springgreen - #00FF7F - rgb(0, 255, 127) - Shades",
168
161
  "steelblue - #4682B4 - rgb(70, 130, 180) - Shades",
@@ -452,11 +452,25 @@ def is_color_value(val: str) -> bool:
452
452
  is_valid = True
453
453
  elif is_rgb(val):
454
454
  is_valid = True
455
+ elif is_keyword(val):
456
+ is_valid = True
455
457
  else:
456
458
  is_valid = False
457
459
  return is_valid
458
460
 
459
461
 
462
+ def is_keyword(val: str) -> bool:
463
+ """checks to see if a value is a color keyword or not
464
+
465
+ Args:
466
+ val: the CSS value in question.
467
+
468
+ Returns:
469
+ is_keyword: if the value is a color keyword or not."""
470
+ is_keyword = val in color_keywords.get_all_keywords()
471
+ return is_keyword
472
+
473
+
460
474
  def get_relative_luminance(val: int) -> float:
461
475
  """Returns the relative brightness of a color channel normalized
462
476
  to 0 for black and 1 for all white.
@@ -508,11 +508,13 @@ class Declaration:
508
508
  self.property = ""
509
509
  self.value = ""
510
510
  self.invalid_message = ""
511
+ self.is_color = False
511
512
  # validate before trying to set the declaration.
512
513
  try:
513
514
  self.validate_declaration()
514
515
  self.is_valid = True
515
516
  self.set_declaration()
517
+ self.is_color_property()
516
518
  except ValueError as e:
517
519
  self.is_valid = False
518
520
  self.invalid_message = str(e)
@@ -632,6 +634,12 @@ class Declaration:
632
634
  declaration = self.property + ": " + self.value
633
635
  return declaration
634
636
 
637
+ def is_color_property(self):
638
+ value = self.value
639
+ if value[-1] == ";":
640
+ value = value[:-1]
641
+ self.is_color = color_tools.is_color_value(value)
642
+
635
643
 
636
644
  def restore_braces(split: list) -> list:
637
645
  """restore the missing braces removed by the .split() method
@@ -1230,7 +1238,7 @@ def get_colors_from_gradient(gradient: str) -> list:
1230
1238
 
1231
1239
 
1232
1240
  def get_color_codes_of_type(color_type: str, gradient: str) -> list:
1233
- """returns all color codes of a particular type (hsl, rgb, etc.)
1241
+ """returns all color codes of a particular type from a gradient
1234
1242
 
1235
1243
  Args:
1236
1244
  color_type: the type of color code it might be (hex, rgb, hsl,
@@ -1537,6 +1545,96 @@ def adjust_overrides(file_path: str, rules: dict) -> dict:
1537
1545
  return adjusted_rule
1538
1546
 
1539
1547
 
1548
+ def get_all_color_rules(stylesheet: Stylesheet) -> list:
1549
+ """Gets all color-based rules from a stylesheet.
1550
+
1551
+ Args:
1552
+ stylesheet: Stylesheet object.
1553
+
1554
+ Returns:
1555
+ rules: a list of color-based rules"""
1556
+ rules = []
1557
+ for ruleset in stylesheet.rulesets:
1558
+ declaration_block = ruleset.declaration_block
1559
+ declarations = declaration_block.declarations
1560
+ for declaration in declarations:
1561
+ property = declaration.property
1562
+ if property == "color" or "background" in property:
1563
+ selector = ruleset.selector
1564
+ value = declaration.value
1565
+ if property == "background":
1566
+ background_color = get_background_color(declaration)
1567
+ if not background_color:
1568
+ continue
1569
+ else:
1570
+ value = background_color
1571
+ rules.append((selector, property, value))
1572
+ return rules
1573
+
1574
+
1575
+ def get_background_color(declaration: Declaration) -> Union[str, None]:
1576
+ """Returns a color value from a declaration with a property of background
1577
+
1578
+ Args:
1579
+ declaration: the declaration we want to test.
1580
+
1581
+ Returns:
1582
+ color_value: either a valid color value, None, or gradient - if it's a
1583
+ gradient"""
1584
+ color_value = None
1585
+ is_rgb = color_tools.is_rgb(declaration.value)
1586
+ if is_rgb:
1587
+ return declaration.value
1588
+ values = declaration.value.split()
1589
+ for val in values:
1590
+ color = color_tools.is_color_value(val)
1591
+ if color:
1592
+ color_value = val
1593
+ break
1594
+ is_keyword = val in color_tools.color_keywords.get_all_keywords()
1595
+ if is_keyword:
1596
+ color_value = val
1597
+ break
1598
+ gradient = is_gradient(val)
1599
+ if gradient:
1600
+ color_value = "gradient"
1601
+ break
1602
+ return color_value
1603
+
1604
+
1605
+ def condense_the_rules(rules):
1606
+ condensed = []
1607
+ for rule in rules:
1608
+ file, sel, prop, val = rule
1609
+ color = {}
1610
+ background = {}
1611
+ declaration = get_bg_or_color(prop)
1612
+ if declaration.get("type") == "color":
1613
+ color = declaration
1614
+ elif declaration.get("type") == "background":
1615
+ background = declaration
1616
+ if not condensed:
1617
+ condensed.append([file, sel, color, background, val])
1618
+ else:
1619
+ for rule in condensed:
1620
+ cur_file, cur_sel, cur_col, cur_bg_col, cur_val = rule
1621
+ if file == cur_file and sel == cur_sel:
1622
+ # add the property that is missing (if it is missing)
1623
+ print("It's time to work.")
1624
+ return condensed
1625
+
1626
+
1627
+ def get_bg_or_color(prop):
1628
+ declaration = {"type": {}, "declaration": {}}
1629
+ if prop == "color":
1630
+ declaration["type"] = "color"
1631
+ declaration["declaration"] = {"color": prop}
1632
+ if "background" in prop:
1633
+ declaration["type"] = "background"
1634
+ declaration["declaration"] = {"background": prop}
1635
+ return declaration
1636
+
1637
+
1540
1638
  if __name__ == "__main__":
1541
1639
  insane_gradient = """
1542
1640
  -moz-radial-gradient(0% 200%, ellipse cover,
File without changes
File without changes