mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-21 18:22:30 +01:00
[formatter] implement 'L' conversion
This commit is contained in:
parent
b44f0cdab0
commit
68bff76d90
@ -76,6 +76,12 @@ Conversion specifiers allow to *convert* the value to a different form or type.
|
||||
<td><code>{tags!j}</code></td>
|
||||
<td><code>["sun", "tree", "water"]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code>L</code></td>
|
||||
<td>Return the <a href="https://docs.python.org/3/library/functions.html#len" rel="nofollow">length</a> of a value</td>
|
||||
<td><code>{foo!L}</code></td>
|
||||
<td><code>7</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code>t</code></td>
|
||||
<td>Trim a string, i.e. remove leading and trailing whitespace characters</td>
|
||||
@ -84,13 +90,13 @@ Conversion specifiers allow to *convert* the value to a different form or type.
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code>T</code></td>
|
||||
<td>Convert a <code>datetime</code> object to a unix timestamp</td>
|
||||
<td>Convert a <code>datetime</code> object to a Unix timestamp</td>
|
||||
<td><code>{date!T}</code></td>
|
||||
<td><code>1262304000</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code>d</code></td>
|
||||
<td>Convert a unix timestamp to a <code>datetime</code> object</td>
|
||||
<td>Convert a Unix timestamp to a <code>datetime</code> object</td>
|
||||
<td><code>{created!d}</code></td>
|
||||
<td><code>2010-01-01 00:00:00</code></td>
|
||||
</tr>
|
||||
|
@ -485,6 +485,7 @@ _CONVERSIONS = {
|
||||
"C": string.capwords,
|
||||
"j": util.json_dumps,
|
||||
"t": str.strip,
|
||||
"L": len,
|
||||
"T": util.datetime_to_timestamp_string,
|
||||
"d": text.parse_timestamp,
|
||||
"U": text.unescape,
|
||||
|
@ -67,6 +67,9 @@ class TestFormatter(unittest.TestCase):
|
||||
self._run_test("{l!j}", '["a", "b", "c"]')
|
||||
self._run_test("{dt!j}", '"2010-01-01 00:00:00"')
|
||||
self._run_test("{a!g}", "hello-world")
|
||||
self._run_test("{a!L}", 11)
|
||||
self._run_test("{l!L}", 3)
|
||||
self._run_test("{d!L}", 3)
|
||||
|
||||
with self.assertRaises(KeyError):
|
||||
self._run_test("{a!q}", "hello world")
|
||||
|
Loading…
Reference in New Issue
Block a user