Opened 9 years ago
Closed 8 years ago
#12797 closed defect (fixed)
Invalid format string
Reported by: | anonymous | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Component: | MovieMacro |
Severity: | normal | Keywords: | |
Cc: | Trac Release: |
Description (last modified by )
I get the following error:
Error: Macro Movie(LarmaAv.webm) failed Invalid format string
Trying to play an attachment to a wiki with
[[Movie(LarmaAv.webm)]]
Attachments (1)
Change History (9)
comment:1 Changed 9 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 8 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:3 Changed 8 years ago by
This bug is caused by L161 of movie.py
The usage of strftime("%s") is platform dependent and seems to not work on windows.
Python doesn't actually support %s as an argument to strftime (if you check at http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior it's not in the list), the only reason it's working is because Python is passing the information to your system's strftime, which uses your local timezone.
comment:4 Changed 8 years ago by
You're right. Are you running Trac with the plugin on Windows? datetime.strftime()
with %s
doesn't work on Windows.
Another issue, resolution of datetime.now()
is 0.010s through 0.016s on Windows. If the Movie
macro is used more than once at a time, the same id might be generated by _generate_player_id
on Windows.
Could you please try the following patch?
-
moviemacro/trunk/movie/macro.py
diff --git a/moviemacro/trunk/movie/macro.py b/moviemacro/trunk/movie/macro.py index 2fe70a864..af9ab4070 100644
a b 5 5 Embeds various online movies. 6 6 """ 7 7 import mimetypes 8 from datetime import datetime9 8 from os.path import join as pathjoin 10 9 from urlparse import urlparse 11 10 … … from pkg_resources import resource_filename 13 12 from trac.core import TracError 14 13 from trac.core import implements 15 14 from trac.resource import Resource, get_resource_url 15 from trac.util import hex_entropy 16 16 from trac.util.html import html as tag 17 17 from trac.util.presentation import to_json 18 18 from trac.web.api import IRequestFilter … … class MovieMacro(WikiMacroBase): 157 157 # Private methods 158 158 159 159 def _generate_player_id(self): 160 now = datetime.now() 161 return 'player-%s-%s' % (now.strftime('%s'), now.microsecond) 160 return 'player-' + hex_entropy() 162 161 163 162 def _get_absolute_url(self, req, url): 164 163 """ Generate an absolute url from the url with the special schemes
comment:5 Changed 8 years ago by
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
Changed 8 years ago by
Attachment: | t12797.diff added |
---|
comment:6 Changed 8 years ago by
Owner: | changed from Tetsuya Morimoto to Jun Omae |
---|---|
Status: | reopened → accepted |
Proposed patch is t12797.diff. Unit tests pass with Trac 0.12, 1.0 and 1.2 on both Linux and Windows.
comment:7 Changed 8 years ago by
I noticed another issue, the macro is used backslash characters to create URL on Windows. The proposed patch is including for the issue.
I can't reproduce. If you wish to continue debugging, please make sure you have the latest version of the plugin installed, provide your Trac version and check the logs.