conduit r1585 - in trunk: . conduit/modules test/python-tests test/python-tests/data
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1585 - in trunk: . conduit/modules test/python-tests test/python-tests/data
- Date: Wed, 23 Jul 2008 05:26:18 +0000 (UTC)
Author: jstowers
Date: Wed Jul 23 05:26:18 2008
New Revision: 1585
URL: http://svn.gnome.org/viewvc/conduit?rev=1585&view=rev
Log:
* conduit/modules/ConverterModule.py:
* test/python-tests/TestCoreConvert.py:
* test/python-tests/TestCoreDatatypes.py:
* test/python-tests/common.py:
* test/python-tests/data/bookmark.txt: Add converter and tests
for bookmark datatype.
Added:
trunk/test/python-tests/data/bookmark.txt
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/conduit/modules/ConverterModule.py
trunk/test/python-tests/TestCoreConvert.py
trunk/test/python-tests/TestCoreDatatypes.py
trunk/test/python-tests/common.py
Modified: trunk/conduit/modules/ConverterModule.py
==============================================================================
--- trunk/conduit/modules/ConverterModule.py (original)
+++ trunk/conduit/modules/ConverterModule.py Wed Jul 23 05:26:18 2008
@@ -11,6 +11,7 @@
import conduit.datatypes.File as File
import conduit.datatypes.Note as Note
import conduit.datatypes.Setting as Setting
+import conduit.datatypes.Bookmark as Bookmark
MODULES = {
"EmailConverter" : { "type": "converter" },
@@ -18,7 +19,8 @@
"ContactConverter" : { "type": "converter" },
"EventConverter" : { "type": "converter" },
"FileConverter" : { "type": "converter" },
- "SettingConverter" : { "type": "converter" }
+ "SettingConverter" : { "type": "converter" },
+ "BookmarkConverter" : { "type": "converter" },
}
class EmailConverter(TypeConverter.Converter):
@@ -241,7 +243,62 @@
)
return setting
+class BookmarkConverter(TypeConverter.Converter):
+ def __init__(self):
+ self.conversions = {
+ "bookmark,text" : self.bookmark_to_text,
+ "bookmark,file" : self.bookmark_to_file,
+ "text,bookmark" : self.text_to_bookmark,
+ "file,bookmark" : self.file_to_bookmark
+ }
+ #recognizes key value in text strings
+ self.regex = re.compile(r"^title:(.+)\nuri:(.*)$")
+
+ def _to_text(self, bookmark):
+ return "title:%s\nuri:%s" % (bookmark.title, bookmark.uri)
+
+ def _to_key_value(self, txt):
+ m = self.regex.match(txt)
+ if m != None and len(m.groups()) == 2:
+ return m.group(1),m.group(2)
+ else:
+ return None,None
+ def bookmark_to_text(self, bookmark):
+ t = Text.Text(
+ text=self._to_text(bookmark)
+ )
+ return t
+
+ def text_to_bookmark(self, text):
+ bookmark = None
+ k,v = self._to_key_value(text.get_string())
+ if k != None and v != None:
+ bookmark = Bookmark.Bookmark(
+ title=k,
+ uri=v
+ )
+ return bookmark
+
+ def bookmark_to_file(self, bookmark):
+ f = File.TempFile(
+ self._to_text(bookmark)
+ )
+ f.force_new_filename(bookmark.title.replace("/","_"))
+ f.force_new_file_extension(".txt")
+ return f
+
+ def file_to_bookmark(self, f):
+ bookmark = None
+ if f.get_mimetype().startswith("text"):
+ txt = f.get_contents_as_text()
+ k,v = self._to_key_value(txt)
+ if k != None and v != None:
+ bookmark = Bookmark.Bookmark(
+ title=k,
+ uri=v
+ )
+ return bookmark
Modified: trunk/test/python-tests/TestCoreConvert.py
==============================================================================
--- trunk/test/python-tests/TestCoreConvert.py (original)
+++ trunk/test/python-tests/TestCoreConvert.py Wed Jul 23 05:26:18 2008
@@ -46,6 +46,7 @@
TYPES = {
"file" : (new_file, { "event":"1.ical",
"setting":"setting.txt",
+ "bookmark":"bookmark.txt",
"contact":"1.vcard",
"file/photo":"1.png" }),
# "file/audio" : (new_audio, { }),
@@ -59,8 +60,10 @@
"contact":read_data_file_from_data_dir("1.ical"),
"email":read_data_file_from_data_dir("1.email"),
"setting":"key:/foo/bar\nvalue:baz",
+ "bookmark":"title:/foo/bar\nuri:baz",
"*":Utils.random_string() }),
- "setting" : (new_setting, { })
+ "setting" : (new_setting, { }),
+ "bookmark" : (new_bookmark, { }),
}
#Draw a table of the available conversions.
Modified: trunk/test/python-tests/TestCoreDatatypes.py
==============================================================================
--- trunk/test/python-tests/TestCoreDatatypes.py (original)
+++ trunk/test/python-tests/TestCoreDatatypes.py Wed Jul 23 05:26:18 2008
@@ -18,6 +18,7 @@
"setting" : new_setting,
"test" : new_test_datatype,
"photo" : new_photo,
+ "bookmark" : new_bookmark
}
for t,func in TYPES.items():
Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py (original)
+++ trunk/test/python-tests/common.py Wed Jul 23 05:26:18 2008
@@ -26,7 +26,7 @@
import conduit.Conduit as Conduit
import conduit.SyncSet as SyncSet
import conduit.MappingDB as MappingDB
-from conduit.datatypes import File, Note, Setting, Contact, Email, Text, Video, Photo, Audio, Event
+from conduit.datatypes import File, Note, Setting, Contact, Email, Text, Video, Photo, Audio, Event, Bookmark
from conduit.modules import TestModule
# set up expected paths & variables
@@ -253,6 +253,17 @@
s.set_open_URI(None)
return s
+def new_bookmark(data):
+ if data == None:
+ data = Utils.random_string()
+ b = Bookmark.Bookmark(
+ title=data,
+ uri="http://www.%s.com" % Utils.random_string()
+ )
+ b.set_UID(Utils.random_string())
+ b.set_open_URI(b.get_uri())
+ return b
+
def new_test_datatype(data):
if data == None:
data = Utils.random_string(length=1)
Added: trunk/test/python-tests/data/bookmark.txt
==============================================================================
--- (empty file)
+++ trunk/test/python-tests/data/bookmark.txt Wed Jul 23 05:26:18 2008
@@ -0,0 +1,2 @@
+title:great site!
+uri:http://www.test.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]