Ralf, thank you for feedback. It is not so urgent.

1. done
2. done
3. No I can't, I removed x[nN] flags from regexp
4. done
5. done

2010/10/19 Ralf Schmitt <[email protected]>

> Zakhar Zibarov <[email protected]> writes:
>
> > Can anybody review this patch and apply it to main repo?
>
> [looks like this is urgent for you. please give us a bit more time for
> your next patch]
>
> Here's my code review:
>
> 1. can you get rid of whitespace changes to unrelated lines in your
> patch?
>
> 2. Can you fix the following issue (i.e. please attach your patch, do no
> send it inline or copy&paste it).
> ,----
> | [py27] [git:master] ~/code/ % patch -p1 <patch
> | patching file mwlib/templ/magic_time.py
> | patch: **** malformed patch at line 63:
> datetime.datetime.now().replace(hour=int(datestring[:2]),
> `----
>
> 3. the testcases only cover xr, the regular expression seems to imply that
> xn and xN also have a special meaning. Can you add testcases for those?
>
> 4. Can you add testcases for the xr"foobar" case.
>
> 5. Can you get rid of the catch all "except:"
>
> Thanks for your help,
> - Ralf
>
> --
> You received this message because you are subscribed to the Google Groups
> "mwlib" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected] <mwlib%[email protected]>.
> For more options, visit this group at
> http://groups.google.com/group/mwlib?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"mwlib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mwlib?hl=en.

diff --git a/mwlib/templ/magic_time.py b/mwlib/templ/magic_time.py
index 69c461c..c1d4d09 100644
--- a/mwlib/templ/magic_time.py
+++ b/mwlib/templ/magic_time.py
@@ -2,6 +2,7 @@ import sys
 import datetime
 import re
 import calendar
+import roman
 from timelib import strtodatetime as parsedate
 
 from mwlib.strftime import strftime
@@ -12,7 +13,7 @@ def ampm(date):
     else:
         return "pm"
 
-rx = re.compile('"[^"]*"|\\\\.|.')
+rx = re.compile('"[^"]*"|xr|\\\\.|.')
 codemap = dict(
     y = '%y',
     Y = '%Y',
@@ -41,11 +42,13 @@ codemap = dict(
     c = "%Y-%m-%dT%H:%M:%S+00:00",
     r = "%a, %d %b %Y %H:%M:%S +0000",
     t = lambda d: str(calendar.monthrange(d.year, d.month)[1]),
+    xr = ("process_next", lambda n: roman.toRoman(int(n))),
     )
 
 
 def formatdate(format, date):
     split = rx.findall(format)
+    process_next = None
 
     tmp = []
     for x in split:
@@ -58,11 +61,22 @@ def formatdate(format, date):
             else:
                 tmp.append(x)
         else:
+            if isinstance(f, tuple):
+                process_next = f[1]
+                continue
+
             if isinstance(f, basestring):
-                tmp.append(strftime(date, f))
+                res = strftime(date, f)
             else:
-                tmp.append(f(date))
+                res = f(date)
 
+            if process_next:
+                try:
+                    res = process_next(res)
+                except ValueError:
+                    pass
+                process_next = None
+            tmp.append(res)
 
     tmp = u"".join(tmp).strip()
     return tmp
diff --git a/setup.py b/setup.py
index 0f89fbd..9a48283 100755
--- a/setup.py
+++ b/setup.py
@@ -64,7 +64,7 @@ def main():
     if os.path.exists(distutils.util.convert_path('Makefile')):
         build_deps()   # this is a hg checkout.
 
-    install_requires=["pyparsing>=1.4.11", "odfpy>=0.9, <0.10", "flup>=1.0", "twisted>=8.2", "lockfile>=0.8", "timelib>=0.2", "WebOb>=0.9", "pyPdf>=1.12"]
+    install_requires=["pyparsing>=1.4.11", "odfpy>=0.9, <0.10", "flup>=1.0", "twisted>=8.2", "lockfile>=0.8", "timelib>=0.2", "WebOb>=0.9", "pyPdf>=1.12", "roman"]
     if sys.version_info[:2] < (2,5):
         install_requires.append("wsgiref>=0.1.2")
         install_requires.append("elementtree>=1.2.6")
diff --git a/tests/test_expander_time.py b/tests/test_expander_time.py
index 60d7d9f..0e2fbe4 100755
--- a/tests/test_expander_time.py
+++ b/tests/test_expander_time.py
@@ -72,6 +72,9 @@ def test_codes():
 
     yield e, "r", "Sat, 09 Feb 2008 10:55:17 +0000"
     
+    yield e, "xrY", "MMVIII"
+    yield e, "xrU", "XVI", "1970-1-1 + 16 second"
+    yield e, 'xr"foobar"', "foobar"
 
 
 def test_examples():

Reply via email to