diff options
author | Guido Günther <agx@sigxcpu.org> | 2009-04-17 22:31:43 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2009-04-17 22:31:43 +0200 |
commit | d403e625bd085bbf701e648f1e808cd10caad802 (patch) | |
tree | ac9ac3004034bd7517975840e68924246363ecc2 | |
parent | 43d36676eb8312d12aa50f124fd5f49902db10dd (diff) |
Imported Upstream version 0.8.1c
-rw-r--r-- | LICENSE-2.0.txt | 202 | ||||
-rw-r--r-- | LICENSE.txt | 57 | ||||
-rw-r--r-- | PKG-INFO | 10 | ||||
-rwxr-xr-x | ez_setup/__init__.py | 12 | ||||
-rwxr-xr-x | setup.py | 18 | ||||
-rw-r--r-- | test_files/more_tests.txt | 8 | ||||
-rw-r--r-- | test_vobject.py | 9 | ||||
-rw-r--r-- | vobject.egg-info/PKG-INFO | 10 | ||||
-rw-r--r-- | vobject.egg-info/SOURCES.txt | 2 | ||||
-rw-r--r-- | vobject/base.py | 12 | ||||
-rw-r--r-- | vobject/change_tz.py | 19 | ||||
-rw-r--r-- | vobject/icalendar.py | 40 | ||||
-rw-r--r-- | vobject/vcard.py | 16 |
13 files changed, 313 insertions, 102 deletions
diff --git a/LICENSE-2.0.txt b/LICENSE-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index bbd7e18..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,57 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2004-2006 Jeffrey Harris. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * nor may "Apache" appear in their name, without prior written - * permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - * Portions of this software are based upon public domain software - * originally written at the National Center for Supercomputing Applications, - * University of Illinois, Urbana-Champaign. - */ - @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: vobject -Version: 0.7.1 +Version: 0.8.1c Summary: VObject: module for reading vCard and vCalendar files Home-page: http://vobject.skyhouseconsulting.com Author: Jeffrey Harris @@ -9,7 +9,7 @@ License: Apache Description: Description ----------- - Parses iCalendar and vCard files into Python data structures, decoding the relevant encodings. Also serializes vobject data structures to iCalendar, vCard, or (expirementally) hCalendar unicode strings. + Parses iCalendar and vCard files into Python data structures, decoding the relevant encodings. Also serializes vobject data structures to iCalendar, vCard, or (experimentally) hCalendar unicode strings. Requirements ------------ @@ -18,6 +18,12 @@ Description: Description Recent changes -------------- + - Make change_tz.py compatible with python 2.4, so the entire package stays compatible + - Fall back to default (the most recent standard) behavior if a VCARD + or VCALENDAR doesn't have a recognized VERSION + - Fixed a bad performance bug when parsing large text bodies, thanks to Morgen Sagen at Apple + - Changed license to Apache 2.0 from Apache 1.1 + - Worked around an issue with Apple Address Book's vcard PHOTO parser - Added change_tz module and script for quickly changing event timezones for an ics file. Requires PyICU. - Add support for BYMONTHDAY=-1 (days before the end of the month) when setting rrules diff --git a/ez_setup/__init__.py b/ez_setup/__init__.py index 89cf056..d24e845 100755 --- a/ez_setup/__init__.py +++ b/ez_setup/__init__.py @@ -14,7 +14,7 @@ the appropriate options to ``use_setuptools()``. This file can also be run as a script to install or upgrade setuptools. """ import sys -DEFAULT_VERSION = "0.6c8" +DEFAULT_VERSION = "0.6c9" DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] md5_data = { @@ -48,13 +48,18 @@ md5_data = { 'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902', 'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de', 'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b', + 'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03', + 'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a', + 'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6', + 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', } import sys, os +try: from hashlib import md5 +except ImportError: from md5 import md5 def _validate_md5(egg_name, data): if egg_name in md5_data: - from md5 import md5 digest = md5(data).hexdigest() if digest != md5_data[egg_name]: print >>sys.stderr, ( @@ -64,7 +69,6 @@ def _validate_md5(egg_name, data): sys.exit(2) return data - def use_setuptools( version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15 @@ -233,7 +237,6 @@ def update_md5(filenames): """Update our built-in md5 registry""" import re - from md5 import md5 for name in filenames: base = os.path.basename(name) @@ -270,3 +273,4 @@ if __name__=='__main__': + @@ -3,7 +3,7 @@ Description
-----------
-Parses iCalendar and vCard files into Python data structures, decoding the relevant encodings. Also serializes vobject data structures to iCalendar, vCard, or (expirementally) hCalendar unicode strings.
+Parses iCalendar and vCard files into Python data structures, decoding the relevant encodings. Also serializes vobject data structures to iCalendar, vCard, or (experimentally) hCalendar unicode strings.
Requirements
------------
@@ -12,6 +12,12 @@ Requires python 2.4 or later, dateutil (http://labix.org/python-dateutil) 1.1 or Recent changes
--------------
+ - Make change_tz.py compatible with python 2.4, so the entire package stays compatible
+ - Fall back to default (the most recent standard) behavior if a VCARD
+ or VCALENDAR doesn't have a recognized VERSION
+ - Fixed a bad performance bug when parsing large text bodies, thanks to Morgen Sagen at Apple
+ - Changed license to Apache 2.0 from Apache 1.1
+ - Worked around an issue with Apple Address Book's vcard PHOTO parser
- Added change_tz module and script for quickly changing event timezones for an
ics file. Requires PyICU.
- Add support for BYMONTHDAY=-1 (days before the end of the month) when setting rrules
@@ -24,12 +30,12 @@ Recent changes - Allow unicode names for TZIDs
- Worked around Lotus Notes use of underscores in names by just silently replacing
with dashes
- - When allowing quoted-printable data, honor CHARSET for each line, defaulting to
+ - When allowing quoted-printable data, honor CHARSET for each line, defaulting to
iso-8859-1
- Simplified directory layout, unit tests are now available via setup.py test
For older changes, see
- - http://vobject.skyhouseconsulting.com/history.html or
+ - http://vobject.skyhouseconsulting.com/history.html or
- http://websvn.osafoundation.org/listing.php?repname=vobject&path=/trunk/
"""
@@ -42,7 +48,7 @@ from setuptools import setup, find_packages doclines = __doc__.splitlines()
setup(name = "vobject",
- version = "0.7.1",
+ version = "0.8.1c",
author = "Jeffrey Harris",
author_email = "jeffrey@osafoundation.org",
license = "Apache",
@@ -53,8 +59,8 @@ setup(name = "vobject", include_package_data = True,
test_suite = "test_vobject",
- install_requires = ['python-dateutil >= 1.1'],
-
+ install_requires = ['python-dateutil >= 1.1'],
+
platforms = ["any"],
packages = find_packages(),
description = doclines[0],
diff --git a/test_files/more_tests.txt b/test_files/more_tests.txt index a19cac1..4102fcc 100644 --- a/test_files/more_tests.txt +++ b/test_files/more_tests.txt @@ -74,11 +74,13 @@ quoted-printable >>> vcf = 'BEGIN:VCARD\nVERSION:2.1\nN;ENCODING=QUOTED-PRINTABLE:;=E9\nFN;ENCODING=QUOTED-PRINTABLE:=E9\nTEL;HOME:0111111111\nEND:VCARD\n\n' >>> vcf = vobject.readOne(vcf) >>> vcf.n.value -u';\xe9' +<Name: ? > +>>> vcf.n.value.given +u'\xe9' >>> vcf.serialize() -'BEGIN:VCARD\r\nFN:\xc3\xa9\r\nN:;\xc3\xa9\r\nTEL:0111111111\r\nVERSION:2.1\r\nEND:VCARD\r\n' +'BEGIN:VCARD\r\nVERSION:2.1\r\nFN:\xc3\xa9\r\nN:;\xc3\xa9;;;\r\nTEL:0111111111\r\nEND:VCARD\r\n' >>> vcs = 'BEGIN:VCALENDAR\r\nPRODID:-//OpenSync//NONSGML OpenSync vformat 0.3//EN\r\nVERSION:1.0\r\nBEGIN:VEVENT\r\nDESCRIPTION;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:foo =C3=A5=0Abar =C3=A4=\r\n=0Abaz =C3=B6\r\nUID:20080406T152030Z-7822\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n' >>> vcs = vobject.readOne(vcs, allowQP = True) >>> vcs.serialize() -'BEGIN:VCALENDAR\r\nPRODID:-//OpenSync//NONSGML OpenSync vformat 0.3//EN\r\nVERSION:1.0\r\nBEGIN:VEVENT\r\nDESCRIPTION:foo \xc3\xa5\nbar \xc3\xa4\nbaz \xc3\xb6\r\nUID:20080406T152030Z-7822\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n' +'BEGIN:VCALENDAR\r\nVERSION:1.0\r\nPRODID:-//OpenSync//NONSGML OpenSync vformat 0.3//EN\r\nBEGIN:VEVENT\r\nUID:20080406T152030Z-7822\r\nDESCRIPTION:foo \xc3\xa5\\nbar \xc3\xa4\\nbaz \xc3\xb6\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n' diff --git a/test_vobject.py b/test_vobject.py index b0dfefa..9ee214a 100644 --- a/test_vobject.py +++ b/test_vobject.py @@ -730,6 +730,15 @@ __test__ = { "Test readOne" : CATEGORIES:Random category,Other category
""",
+ "Semi-colon separated multi-text serialization test:" :
+
+ """
+ >>> requestStatus = base.newFromBehavior('request-status')
+ >>> requestStatus.value = ['5.1', 'Service unavailable']
+ >>> print requestStatus.serialize().strip()
+ REQUEST-STATUS:5.1;Service unavailable
+ """,
+
"vCard groups test:" :
"""
diff --git a/vobject.egg-info/PKG-INFO b/vobject.egg-info/PKG-INFO index 2d7c261..a8007d7 100644 --- a/vobject.egg-info/PKG-INFO +++ b/vobject.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: vobject -Version: 0.7.1 +Version: 0.8.1c Summary: VObject: module for reading vCard and vCalendar files Home-page: http://vobject.skyhouseconsulting.com Author: Jeffrey Harris @@ -9,7 +9,7 @@ License: Apache Description: Description ----------- - Parses iCalendar and vCard files into Python data structures, decoding the relevant encodings. Also serializes vobject data structures to iCalendar, vCard, or (expirementally) hCalendar unicode strings. + Parses iCalendar and vCard files into Python data structures, decoding the relevant encodings. Also serializes vobject data structures to iCalendar, vCard, or (experimentally) hCalendar unicode strings. Requirements ------------ @@ -18,6 +18,12 @@ Description: Description Recent changes -------------- + - Make change_tz.py compatible with python 2.4, so the entire package stays compatible + - Fall back to default (the most recent standard) behavior if a VCARD + or VCALENDAR doesn't have a recognized VERSION + - Fixed a bad performance bug when parsing large text bodies, thanks to Morgen Sagen at Apple + - Changed license to Apache 2.0 from Apache 1.1 + - Worked around an issue with Apple Address Book's vcard PHOTO parser - Added change_tz module and script for quickly changing event timezones for an ics file. Requires PyICU. - Add support for BYMONTHDAY=-1 (days before the end of the month) when setting rrules diff --git a/vobject.egg-info/SOURCES.txt b/vobject.egg-info/SOURCES.txt index f92917f..43a217a 100644 --- a/vobject.egg-info/SOURCES.txt +++ b/vobject.egg-info/SOURCES.txt @@ -1,5 +1,5 @@ ACKNOWLEDGEMENTS.txt -LICENSE.txt +LICENSE-2.0.txt README.txt setup.py test_vobject.py diff --git a/vobject/base.py b/vobject/base.py index f641325..b56c36a 100644 --- a/vobject/base.py +++ b/vobject/base.py @@ -590,7 +590,7 @@ class Component(VBase): """Set behavior if one matches name, versionLine.value.""" v=getBehavior(self.name, versionLine.value) if v: self.setBehavior(v) - + def transformChildrenToNative(self): """Recursively replace children with their native representation.""" #sort to get dependency order right, like vtimezone before vevent @@ -1047,6 +1047,10 @@ def readComponents(streamOrString, validate=False, transform=True, component=stack.pop() if versionLine is not None: component.setBehaviorFromVersionLine(versionLine) + else: + behavior = getBehavior(component.name) + if behavior: + component.setBehavior(behavior) if validate: component.validate(raiseException=True) if transform: component.transformChildrenToNative() yield component #EXIT POINT @@ -1105,8 +1109,8 @@ def getBehavior(name, id=None): for n, behavior in __behaviorRegistry[name]: if n==id: return behavior - else: - return __behaviorRegistry[name][0][1] + + return __behaviorRegistry[name][0][1] return None def newFromBehavior(name, id=None): @@ -1132,4 +1136,4 @@ def backslashEscape(s): #------------------- Testing and running functions ----------------------------- if __name__ == '__main__': import tests - tests._test() + tests._test() diff --git a/vobject/change_tz.py b/vobject/change_tz.py index 1227676..4f9ae1e 100644 --- a/vobject/change_tz.py +++ b/vobject/change_tz.py @@ -1,13 +1,13 @@ """Translate an ics file's events to a different timezone.""" from optparse import OptionParser -import icalendar, base +from vobject import icalendar, base import sys try: import PyICU except: PyICU = None - + from datetime import datetime def change_tz(cal, new_timezone, default, utc_only=False, utc_tz=icalendar.utc): @@ -23,7 +23,7 @@ def change_tz(cal, new_timezone, default, utc_only=False, utc_tz=icalendar.utc): dt = dt.replace(tzinfo = default) node.value = dt.astimezone(new_timezone) -def main(): +def main(): options, args = get_options() if PyICU is None: print "Failure. change_tz requires PyICU, exiting" @@ -32,13 +32,20 @@ def main(): print tz_string elif args: utc_only = options.utc - print "Converting %s events" % "only UTC" if utc_only else "all" + if utc_only: + which = "only UTC" + else: + which = "all" + print "Converting %s events" % which ics_file = args[0] - timezone = PyICU.ICUtzinfo.getInstance(args[1]) if len(args) > 1 else PyICU.ICUtzinfo.default + if len(args) > 1: + timezone = PyICU.ICUtzinfo.getInstance(args[1]) + else: + timezone = PyICU.ICUtzinfo.default print "... Reading %s" % ics_file cal = base.readOne(file(ics_file)) change_tz(cal, timezone, PyICU.ICUtzinfo.default, utc_only) - + out_name = ics_file + '.converted' print "... Writing %s" % out_name out = file(out_name, 'wb') diff --git a/vobject/icalendar.py b/vobject/icalendar.py index 4c4f49b..4a1da7c 100644 --- a/vobject/icalendar.py +++ b/vobject/icalendar.py @@ -777,22 +777,27 @@ class MultiTextBehavior(behavior.Behavior): After transformation, value is a list of strings. """ + listSeparator = "," - @staticmethod - def decode(line): + @classmethod + def decode(cls, line): """Remove backslash escaping from line.value, then split on commas.""" if line.encoded: - line.value = stringToTextValues(line.value) + line.value = stringToTextValues(line.value, + listSeparator=cls.listSeparator) line.encoded=False - @staticmethod - def encode(line): + @classmethod + def encode(cls, line): """Backslash escape line.value.""" if not line.encoded: - line.value = ','.join(backslashEscape(val) for val in line.value) + line.value = cls.listSeparator.join(backslashEscape(val) for val in line.value) line.encoded=True +class SemicolonMultiTextBehavior(MultiTextBehavior): + listSeparator = ";" + #------------------------ Registered Behavior subclasses ----------------------- class VCalendar2_0(VCalendarComponentBehavior): """vCalendar 2.0 behavior. With added VAVAILABILITY support.""" @@ -1481,11 +1486,12 @@ registerBehavior(MultiDateBehavior, 'EXDATE') textList = ['CALSCALE', 'METHOD', 'PRODID', 'CLASS', 'COMMENT', 'DESCRIPTION', 'LOCATION', 'STATUS', 'SUMMARY', 'TRANSP', 'CONTACT', 'RELATED-TO', - 'UID', 'ACTION', 'REQUEST-STATUS', 'BUSYTYPE'] + 'UID', 'ACTION', 'BUSYTYPE'] map(lambda x: registerBehavior(TextBehavior, x), textList) multiTextList = ['CATEGORIES', 'RESOURCES'] map(lambda x: registerBehavior(MultiTextBehavior, x), multiTextList) +registerBehavior(SemicolonMultiTextBehavior, 'REQUEST-STATUS') #------------------------ Serializing helper functions ------------------------- @@ -1602,7 +1608,9 @@ def stringToDateTime(s, tzinfo=None): return datetime.datetime(year, month, day, hour, minute, second, 0, tzinfo) -escapableCharList = "\\;,Nn" +# DQUOTE included to work around iCal's penchant for backslash escaping it, +# although it isn't actually supposed to be escaped according to rfc2445 TEXT +escapableCharList = '\\;,Nn"' def stringToTextValues(s, listSeparator=',', charList=None, strict=False): """Returns list of strings.""" @@ -1624,7 +1632,7 @@ def stringToTextValues(s, listSeparator=',', charList=None, strict=False): charIterator = enumerate(s) state = "read normal" - current = "" + current = [] results = [] while True: @@ -1638,28 +1646,30 @@ def stringToTextValues(s, listSeparator=',', charList=None, strict=False): state = "read escaped char" elif char == listSeparator: state = "read normal" + current = "".join(current) results.append(current) - current = "" + current = [] elif char == "eof": state = "end" else: state = "read normal" - current = current + char + current.append(char) elif state == "read escaped char": if escapableChar(char): state = "read normal" if char in 'nN': - current = current + '\n' + current.append('\n') else: - current = current + char + current.append(char) else: state = "read normal" # leave unrecognized escaped characters for later passes - current = current + '\\' + char + current.append('\\' + char) elif state == "end": #an end state - if current != "" or len(results) == 0: + if len(current) or len(results) == 0: + current = "".join(current) results.append(current) return results diff --git a/vobject/vcard.py b/vobject/vcard.py index 01d1d42..068ce29 100644 --- a/vobject/vcard.py +++ b/vobject/vcard.py @@ -177,7 +177,10 @@ registerBehavior(FN) class Label(VCardTextBehavior): name = "Label" description = 'Formatted address' -registerBehavior(FN) +registerBehavior(Label) + +wacky_apple_photo_serialize = True +REALLY_LARGE = 1E50 class Photo(VCardTextBehavior): name = "Photo" @@ -185,7 +188,16 @@ class Photo(VCardTextBehavior): @classmethod def valueRepr( cls, line ): return " (BINARY PHOTO DATA at 0x%s) " % id( line.value ) - + + @classmethod + def serialize(cls, obj, buf, lineLength, validate): + """Apple's Address Book is *really* weird with images, it expects + base64 data to have very specific whitespace. It seems Address Book + can handle PHOTO if it's not wrapped, so don't wrap it.""" + if wacky_apple_photo_serialize: + lineLength = REALLY_LARGE + VCardTextBehavior.serialize(obj, buf, lineLength, validate) + registerBehavior(Photo) def toListOrString(string): |