mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 04:02:32 +01:00
[formatter] support filesystem paths for \fM
This commit is contained in:
parent
9789ebac52
commit
1a4d4a799b
@ -272,9 +272,10 @@ Starting a format string with '\f<Type> ' allows to set a different format strin
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code>M</code></td>
|
||||
<td> Name of a Python module followed by one of its functions.
|
||||
This function gets called with the current metadata dict as
|
||||
argument and should return a string.</td>
|
||||
<td>Path or name of a Python module
|
||||
followed by the name of one of its functions.
|
||||
This function gets called with the current metadata dict as
|
||||
argument and should return a string.</td>
|
||||
<td><code>\fM my_module:generate_text</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -218,7 +218,7 @@ class ModuleFormatter():
|
||||
|
||||
def __init__(self, function_spec, default=NONE, fmt=None):
|
||||
module_name, _, function_name = function_spec.partition(":")
|
||||
module = __import__(module_name)
|
||||
module = util.import_file(module_name)
|
||||
self.format_map = getattr(module, function_name)
|
||||
|
||||
|
||||
|
@ -374,7 +374,7 @@ def noarg():
|
||||
try:
|
||||
fmt1 = formatter.parse("\fM testmod:gentext")
|
||||
fmt2 = formatter.parse("\fM testmod:lengths")
|
||||
fmt3 = formatter.parse("\fM testmod:noarg")
|
||||
fmt0 = formatter.parse("\fM testmod:noarg")
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
formatter.parse("\fM testmod:missing")
|
||||
@ -383,11 +383,17 @@ def noarg():
|
||||
finally:
|
||||
sys.path.pop(0)
|
||||
|
||||
fmt3 = formatter.parse("\fM " + path + ":gentext")
|
||||
fmt4 = formatter.parse("\fM " + path + ":lengths")
|
||||
|
||||
self.assertEqual(fmt1.format_map(self.kwdict), "'Title' by Name")
|
||||
self.assertEqual(fmt2.format_map(self.kwdict), "89")
|
||||
|
||||
self.assertEqual(fmt3.format_map(self.kwdict), "'Title' by Name")
|
||||
self.assertEqual(fmt4.format_map(self.kwdict), "89")
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
self.assertEqual(fmt3.format_map(self.kwdict), "")
|
||||
self.assertEqual(fmt0.format_map(self.kwdict), "")
|
||||
|
||||
def _run_test(self, format_string, result, default=None, fmt=format):
|
||||
fmt = formatter.parse(format_string, default, fmt)
|
||||
|
Loading…
Reference in New Issue
Block a user