forked from dhondta/python-codext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy.py
More file actions
executable file
·36 lines (26 loc) · 1.33 KB
/
Copy pathdummy.py
File metadata and controls
executable file
·36 lines (26 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: UTF-8 -*-
"""Dummy Codecs - simple string manipulations.
These are dummy codecs for manipulating strings, for use with other codecs in encoding/decoding chains.
These codecs:
- en/decodes strings from str to str
- en/decodes strings from bytes to bytes
- decodes file content to str (read)
- encodes file content from str to bytes (write)
"""
from ..__common__ import add
capitalize = lambda i, e="strict": (i.capitalize(), len(i))
uncapitalize = lambda i, e="strict": (i[0].lower() + i[1:] if len(i) > 0 else "", len(i))
add("capitalize", capitalize, uncapitalize)
reverse = lambda i, e="strict": (i[::-1], len(i))
add("reverse", reverse, reverse)
word_reverse = lambda i, e="strict": (" ".join(w[::-1] for w in i.split()), len(i))
add("reverse-words", word_reverse, word_reverse, r"^reverse[-_]words$")
swapcase = lambda i, e="strict": (i.swapcase(), len(i))
add("swapcase", swapcase, swapcase, r"^swap(?:case)?$")
title = lambda i, e="strict": (i.title(), len(i))
untitle = lambda i, e="strict": (" ".join(w[0].lower() + w[1:] if len(w) > 0 else "" for w in i.split()), len(i))
add("title", title, untitle)
lowercase = lambda i, e="strict": (i.lower(), len(i))
uppercase = lambda i, e="strict": (i.upper(), len(i))
add("uppercase", uppercase, lowercase, r"^upper(?:case)?$")
add("lowercase", lowercase, uppercase, r"^lower(?:case)?$")