Skip to content

Commit

Permalink
docs: add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
AceofSpades5757 committed May 1, 2024
1 parent e84cc76 commit 3137c91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/clipboard/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Constants"""
UTF_ENCODING: str = "UTF-16"
HTML_ENCODING: str = "UTF-8"
7 changes: 6 additions & 1 deletion src/clipboard/formats.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Clipboard Formats"""
import ctypes
from enum import Enum
from enum import EnumMeta
Expand All @@ -10,6 +11,7 @@


class ExtendedEnum(EnumMeta):
"""Extended Enum Meta Class"""
def __contains__(cls, item: Any):
return any(
[
Expand All @@ -21,6 +23,7 @@ def __contains__(cls, item: Any):


class ClipboardFormat(Enum, metaclass=ExtendedEnum):
"""Clipboard Formats"""
# Constants
CF_TEXT = 1
CF_UNICODETEXT = 13
Expand All @@ -44,11 +47,13 @@ class ClipboardFormat(Enum, metaclass=ExtendedEnum):
@classmethod # type: ignore
@property
def values(cls):
"""Get the values of the enum."""
return [i.value for i in cls]

@classmethod # type: ignore
@property
def names(cls):
"""Get the names of the enum."""
return [i.name for i in cls]

def __str__(self):
Expand Down Expand Up @@ -76,7 +81,7 @@ def get_format_name(format_code: int) -> Optional[str]:
None if the format is not found.
"""
# Built-In
if format_code in ClipboardFormat.values: # type: ignore
if format_code in ClipboardFormat.values: # pylint: disable=unsupported-membership-test
return ClipboardFormat(format_code).name

buffer_size = 256
Expand Down
8 changes: 8 additions & 0 deletions src/clipboard/html_clipboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Code for handling HTML clipboard data."""
import re
from typing import List
from typing import Optional
Expand Down Expand Up @@ -51,6 +52,7 @@ def __init__(self, content: str = ""):
self.content: str = content

def generate(self) -> str:
"""Generate the HTML template."""
fragments: List[str] = (
self.fragments if self.fragments else [self.content]
)
Expand All @@ -67,6 +69,7 @@ def generate(self) -> str:
return result

def _generate_fragments(self, fragments: List) -> str:
"""Generate the HTML fragments."""
results: List[str] = []
for fragment in fragments:
results.append("<!--StartFragment-->")
Expand All @@ -79,13 +82,15 @@ def _generate_fragments(self, fragments: List) -> str:
return result

def _generate_html(self, string: str) -> str:
"""Generate the HTML document."""
lines = string.splitlines()
body = ["<body>"] + lines + ["</body>"]
html = ["<html>"] + body + ["</html>"]

return "\n".join(html)

def _generate_header(self, string: str) -> str:
"""Generate the header for the HTML document."""
lines = string.splitlines()

version = self.version
Expand All @@ -106,6 +111,7 @@ def _generate_header(self, string: str) -> str:
return "\n".join(lines)

def _add_byte_counts(self, content: str) -> str:
"""Add byte counts to the HTML content."""
# Check
current_values = self._get_byte_values(content)
if all((i is not None and i != -1) for i in current_values.values()):
Expand Down Expand Up @@ -147,6 +153,7 @@ def _add_byte_counts(self, content: str) -> str:
return self._add_byte_counts(result)

def _get_byte_values(self, content: str) -> dict:
"""Get the byte values from the HTML content."""
re_StartHTML = re.compile(r"StartHTML:(\d+)", flags=re.MULTILINE)
StartHTML = int(
re_StartHTML.findall(content)[0]
Expand Down Expand Up @@ -185,6 +192,7 @@ def _get_byte_values(self, content: str) -> dict:
}

def _update_byte_counts(self, content: B) -> B:
"""Update the byte counts in the HTML content."""
data: str
if isinstance(content, bytes):
data = content.decode(encoding=HTML_ENCODING)
Expand Down

0 comments on commit 3137c91

Please sign in to comment.