Skip to content

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
Found via `codespell -L fo` and `typos --hidden --format brief`
  • Loading branch information
kianmeng authored and dlax committed Nov 19, 2024
1 parent ce9fc49 commit eaffb15
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Project name

There is a homonym project by @grayhemp since September 2013:
`PgToolkit <https://github.com/grayhemp/pgtoolkit>`__.
``grayhemp/PgToolkit`` is a single tool projet, thus *toolkit* is
``grayhemp/PgToolkit`` is a single tool project, thus *toolkit* is
misleading. Also, as of August 2018, it is inactive for 3 years.

There is no Python library named ``pgtoolkit``. There is no CLI program
Expand Down
6 changes: 3 additions & 3 deletions pgtoolkit/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def parse(fo: str | pathlib.Path | IO[str]) -> Configuration:
The parser tries to return Python object corresponding to value, based on
some heuristics. booleans, octal number, decimal integers and floating
point numbers are parsed. Multiplier units like kB or MB are applyied and
point numbers are parsed. Multiplier units like kB or MB are applied and
you get an int. Interval value like ``3s`` are returned as
:class:`datetime.timedelta`.
Expand Down Expand Up @@ -217,7 +217,7 @@ def notfound(
_timedelta_unit_map = [
("d", _day),
("h", _hour),
# The space before 'min' is intentionnal. I find '1 min' more readable
# The space before 'min' is intentional. I find '1 min' more readable
# than '1min'.
(" min", _minute),
("s", 1),
Expand Down Expand Up @@ -404,7 +404,7 @@ def add(
class Configuration:
r"""Holds a parsed configuration.
You can access parameter using attribute or dictionnary syntax.
You can access parameter using attribute or dictionary syntax.
>>> conf = parse(['port=5432\n', 'pg_stat_statement.min_duration = 3s\n'])
>>> conf.port
Expand Down
2 changes: 1 addition & 1 deletion pgtoolkit/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
going on in a cluster. :mod:`pgtoolkit.log` provides a parser to exploit
efficiently Postgres log records from Python.
Parsing logs is tricky because format varies accross configurations. Also
Parsing logs is tricky because format varies across configurations. Also
performance is important while logs can contain thousands of records.
Expand Down
26 changes: 13 additions & 13 deletions pgtoolkit/log/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ def parse_epoch(raw: str) -> datetime:


class UnknownData(Exception):
"""Represents unparseable data.
"""Represents unparsable data.
:class:`UnknownData` is throwable, you can raise it.
.. attribute:: lines
The list of unparseable strings.
The list of unparsable strings.
"""

# UnknownData object is an exception to be throwable.
Expand Down Expand Up @@ -207,7 +207,7 @@ class PrefixParser:
# https://www.postgresql.org/docs/current/static/runtime-config-logging.html#GUC-LOG-LINE-PREFIX

_datetime_pat = r"\d{4}-[01]\d-[0-3]\d [012]\d:[0-6]\d:[0-6]\d"
# Pattern map of Status informations.
# Pattern map of Status information.
_status_pat = dict(
# Application name
a=r"(?P<application>\[unknown\]|\w+)?",
Expand Down Expand Up @@ -279,15 +279,15 @@ def from_configuration(cls, log_line_prefix: str) -> PrefixParser:
:return: A :class:`PrefixParser` instance.
"""
optionnal: str | None
optional: str | None
try:
fixed, optionnal = cls._q_re.split(log_line_prefix)
fixed, optional = cls._q_re.split(log_line_prefix)
except ValueError:
fixed, optionnal = log_line_prefix, None
fixed, optional = log_line_prefix, None

pattern = cls.mkpattern(fixed)
if optionnal:
pattern += r"(?:" + cls.mkpattern(optionnal) + ")?"
if optional:
pattern += r"(?:" + cls.mkpattern(optional) + ")?"
return cls(re.compile(pattern), log_line_prefix)

def __init__(self, re_: Pattern[str], prefix_fmt: str | None = None) -> None:
Expand All @@ -313,7 +313,7 @@ def parse(self, prefix: str) -> MutableMapping[str, Any]:
if remote_host:
fields.setdefault("remote_host", remote_host)

# Ensure timestamp field is fed eiter by %m or %t.
# Ensure timestamp field is fed either by %m or %t.
timestamp_ms = fields.pop("timestamp_ms", None)
if timestamp_ms:
fields.setdefault("timestamp", timestamp_ms)
Expand All @@ -322,7 +322,7 @@ def parse(self, prefix: str) -> MutableMapping[str, Any]:

@classmethod
def cast_fields(cls, fields: MutableMapping[str, Any]) -> None:
# In-place cast of values in fields dictionnary.
# In-place cast of values in fields dictionary.

for k in fields:
v = fields[k]
Expand All @@ -345,11 +345,11 @@ class Record:
(see csvlog output to compare). Thus we can determine easily message type
as this stage. :mod:`pgtoolkit.log` does not rewrite message severity.
Once prefix, severity and message are splitted, the parser analyze prefix
Once prefix, severity and message are split, the parser analyze prefix
according to ``log_line_prefix`` parameter. Prefix can give a lot of
informations for filtering, but costs some CPU cycles to process.
information for filtering, but costs some CPU cycles to process.
Finally, the parser analyze the message to extract informations such as
Finally, the parser analyze the message to extract information such as
statement, hint, duration, execution plan, etc. depending on the message
type.
Expand Down
12 changes: 6 additions & 6 deletions pgtoolkit/pgpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
with open('.pgpass') as fo:
pgpass = parse(fo)
pgpass.lines.append(PassEntry(username='toto', password='confidentiel'))
pgpass.lines.append(PassEntry(username='toto', password='confidential'))
pgpass.sort()
with open('.pgpass', 'w') as fo:
pgpass.save(fo)
Expand All @@ -35,7 +35,7 @@
.. code:: python
pgpass = parse('.pgpass')
pgpass.lines.append(PassEntry(username='toto', password='confidentiel'))
pgpass.lines.append(PassEntry(username='toto', password='confidential'))
pgpass.sort()
pgpass.save()
Expand All @@ -44,7 +44,7 @@
.. code:: python
with edit('.pgpass') as pgpass:
pgpass.lines.append((PassEntry(username='toto', password='confidentiel'))
pgpass.lines.append((PassEntry(username='toto', password='confidential'))
passfile.sort()
Expand Down Expand Up @@ -268,7 +268,7 @@ def as_tuple(self) -> tuple[str, str, str, str, str]:

def sort_key(self) -> tuple[int, str, int | str, str, str]:
tpl = self.as_tuple()[:-1]
# Compute precision from * occurences.
# Compute precision from * occurrences.
precision = len([x for x in tpl if x == "*"])
# More specific entries comes first.
return (precision,) + tuple(chr(0xFF) if x == "*" else x for x in tpl) # type: ignore[return-value]
Expand Down Expand Up @@ -363,11 +363,11 @@ def parse(self, fo: Iterable[str]) -> None:
def sort(self) -> None:
"""Sort entries preserving comments.
libpq use the first entry from .pgpass matching connexion informations.
libpq use the first entry from .pgpass matching connection information.
Thus, less specific entries should be last in the file. This is the
purpose of :func:`sort` method.
About comments. Comments are supposed to bear with the entrie
About comments. Comments are supposed to bear with the entries
**below**. Thus comments block are sorted according to the first entry
below.
Expand Down
6 changes: 3 additions & 3 deletions pgtoolkit/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
-----------------
:mod:`pgtoolkit.service` is usable as a CLI script. It accepts a service file
path as first argument, read it, validate it and re-render it, loosing
path as first argument, read it, validate it and re-render it, losing
comments.
:class:`ServiceFile` is less strict than `libpq`. Spaces are accepted around
Expand Down Expand Up @@ -105,12 +105,12 @@ class Service(dict[str, Parameter]):
"""Service definition.
The :class:`Service` class represents a single service definition in a
Service file. It’s actually a dictionnary of its own parameters.
Service file. It’s actually a dictionary of its own parameters.
The ``name`` attributes is mapped to the section name of the service in the
Service file.
Each parameters can be accessed either as a dictionnary entry or as an
Each parameters can be accessed either as a dictionary entry or as an
attributes.
>>> myservice = Service('myservice', {'dbname': 'mydb'}, host='myhost')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def test_parser():
assert "*" == dict_["listen_addresses"]

with pytest.raises(AttributeError):
conf.inexistant
conf.inexistent

with pytest.raises(KeyError):
conf["inexistant"]
conf["inexistent"]

with pytest.raises(ValueError):
parse(["bad_line"])
Expand Down
22 changes: 11 additions & 11 deletions tests/test_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_entry():
def test_compare():
from pgtoolkit.pgpass import PassComment, PassEntry

a = PassEntry.parse(":*:*:*:confidentiel")
a = PassEntry.parse(":*:*:*:confidential")
b = PassEntry.parse("hostname:*:*:*:otherpassword")
c = PassEntry.parse("hostname:5442:*:username:otherpassword")
d = PassEntry("hostname", "5442", "*", "username", "otherpassword")
Expand Down Expand Up @@ -95,9 +95,9 @@ def test_parse_lines(tmp_path):

lines = [
"# Comment for h2",
"h2:*:*:postgres:confidentiel",
"# h1:*:*:postgres:confidentiel",
"h2:5432:*:postgres:confidentiel",
"h2:*:*:postgres:confidential",
"# h1:*:*:postgres:confidential",
"h2:5432:*:postgres:confidential",
]

pgpass = parse(lines)
Expand All @@ -120,10 +120,10 @@ def test_parse_lines(tmp_path):
with passfile.open("w") as fo:
pgpass.save(fo)
assert passfile.read_text().splitlines() == [
"h2:5432:*:postgres:confidentiel",
"# h1:*:*:postgres:confidentiel",
"h2:5432:*:postgres:confidential",
"# h1:*:*:postgres:confidential",
"# Comment for h2",
"h2:*:*:postgres:confidentiel",
"h2:*:*:postgres:confidential",
]

header = "#hostname:port:database:username:password"
Expand Down Expand Up @@ -218,11 +218,11 @@ def test_remove():

lines = [
"# Comment for h2",
"h2:*:*:postgres:confidentiel",
"# h1:*:*:postgres:confidentiel",
"h2:5432:*:postgres:confidentiel",
"h2:*:*:postgres:confidential",
"# h1:*:*:postgres:confidential",
"h2:5432:*:postgres:confidential",
"h2:5432:*:david:Som3Password",
"h2:5433:*:postgres:confidentiel",
"h2:5433:*:postgres:confidential",
]

pgpass = parse(lines)
Expand Down

0 comments on commit eaffb15

Please sign in to comment.