I have tried to use the re-write branch several times on a windows based computer and have been unable to get it to work. The current trunk works good and is fairly stable. I wish more was done with /trunk since the /rewrite is completely unusable for anyone who works on a non *nx OS. One thought would be to merge the two into one good system. Where we move all of the non-API based functions to a _old and check for either use_api or a mediawiki version and only support API access where possible. If/when new features become available via the API we can just move the current screen scrap method to and _old and forget about it. Until /rewrite and /trunk are swapped or they are merged development on /trunk should not stop.


John

On Sun, Apr 24, 2011 at 5:49 PM, Merlijn van Deen <valhallasw@arctus.nl> wrote:
Whoo! Great work :-) Tests always are good contributions :-)

On a sidenote - is there a reason you're implementing these in 'trunk' and not in 'rewrite'? Of course, these contributions are very welcome in the trunk, but I still think it would be good to push the rewrite branch.

Best regards,
Merlijn


On 24 April 2011 07:41, <jayvdb@svn.wikimedia.org> wrote:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9196

Revision: 9196
Author:   jayvdb
Date:     2011-04-24 05:40:59 +0000 (Sun, 24 Apr 2011)
Log Message:
-----------
Allow lists of Page and User objects to be interogated

Modified Paths:
--------------
   trunk/pywikipedia/query.py
   trunk/pywikipedia/tests/test_query.py

Modified: trunk/pywikipedia/query.py
===================================================================
--- trunk/pywikipedia/query.py  2011-04-24 04:23:12 UTC (rev 9195)
+++ trunk/pywikipedia/query.py  2011-04-24 05:40:59 UTC (rev 9196)
@@ -263,10 +263,21 @@

    encList = ''
    # items may not have one symbol - '|'
-    for l in list:
-        if type(l) == str and u'|' in l:
-            raise wikipedia.Error("item '%s' contains '|' symbol" % l )
-        encList += ToUtf8(l) + u'|'
+    for item in list:
+        if isinstance(item,basestring):
+            if u'|' in item:
+                raise wikipedia.Error(u"item '%s' contains '|' symbol" % item )
+            encList += ToUtf8(item) + u'|'
+        elif isinstance(item,wikipedia.Page):
+            encList += ToUtf8(item.title()) + u'|'
+        elif item.__class__.__name__ == 'User':
+            # delay loading this until it is needed
+            import userlib
+            encList += ToUtf8(item.name()) + u'|'
+        else:
+            raise wikipedia.Error(u'unknown item class %s' % item.__class__.__name__)
+
+    # strip trailing '|' before returning
    return encList[:-1]

 def ToUtf8(s):

Modified: trunk/pywikipedia/tests/test_query.py
===================================================================
--- trunk/pywikipedia/tests/test_query.py       2011-04-24 04:23:12 UTC (rev 9195)
+++ trunk/pywikipedia/tests/test_query.py       2011-04-24 05:40:59 UTC (rev 9196)
@@ -7,6 +7,8 @@
 import unittest
 import tests.test_pywiki

+import wikipedia as pywikibot
+import catlib, userlib
 import query


@@ -74,5 +76,72 @@
        ]}
        self.assertEqualQueryResult(params, expectedresult)

+    def test_titles_Page(self):
+        params = {
+            'action': 'query',
+            'list': 'users',
+            'usprop': ['registration'],
+            'ususers': [pywikibot.Page(self.site, u'Example'),
+                        pywikibot.Page(self.site, u'Example2')],
+        }
+        expectedresult = {u'users': [
+        {
+            u'userid': 215131,
+            u'name': u'Example',
+            u'registration': u'2005-03-19T00:17:19Z'
+        },
+        {
+            u'userid': 5176706,
+            u'name': u'Example2',
+            u'registration': u'2007-08-26T02:13:33Z'
+        },
+        ]}
+        self.assertEqualQueryResult(params, expectedresult)
+
+    def test_titles_User(self):
+        params = {
+            'action': 'query',
+            'list': 'users',
+            'usprop': ['registration'],
+            'ususers': [userlib.User(self.site, u'Example'),
+                        userlib.User(self.site, u'Example2')],
+        }
+        expectedresult = {u'users': [
+        {
+            u'userid': 215131,
+            u'name': u'Example',
+            u'registration': u'2005-03-19T00:17:19Z'
+        },
+        {
+            u'userid': 5176706,
+            u'name': u'Example2',
+            u'registration': u'2007-08-26T02:13:33Z'
+        },
+        ]}
+        self.assertEqualQueryResult(params, expectedresult)
+
+    def test_titles_Category(self):
+        params = {
+            'action': 'query',
+            'prop': 'revisions',
+            'rvprop': ['ids', 'timestamp', 'user'],
+            'rvdir': 'newer',
+            'rvlimit': 1,
+            'titles': [catlib.Category(self.site, u'Category:Categories')],
+        }
+        expectedresult = {u'pages': {u'794823':
+        {
+            u'ns': 14,
+            u'pageid': 794823,
+            u'revisions': [{
+                u'revid': 4494485,
+                u'user': u'SEWilco',
+                u'timestamp': u'2004-07-07T18:45:50Z',
+            }],
+            u'title': u'Category:Categories',
+        },
+        }}
+        self.assertEqualQueryResult(params, expectedresult)
+
 if __name__ == "__main__":
    unittest.main()


_______________________________________________
Pywikipedia-svn mailing list
Pywikipedia-svn@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn


_______________________________________________
Pywikipedia-l mailing list
Pywikipedia-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l