コード例 #1
0
ファイル: property.py プロジェクト: lanhel/pyietflib
 def parse_value(self, value):
     self.date = parse_iso8601(value)[0]
コード例 #2
0
ファイル: test_vCard.py プロジェクト: Zearin/python-ietflib
    def test_rfc_author(self):
        """Test RFC 6350 author's vCard."""
        x = parse_vcard(
            encode_to_stream("""
BEGIN:VCARD
VERSION:4.0
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr,M.Sc.
BDAY:--0203
ANNIVERSARY:20090808T1430-0500
GENDER:M
LANG;PREF=1:fr
LANG;PREF=2:en
ORG;TYPE=work:Viagenie
ADR;TYPE=work:;Suite D2-630;2875 Laurier;
 Quebec;QC;G1V 2M2;Canada
TEL;VALUE=uri;TYPE="work,voice";PREF=1:tel:+1-418-656-9254;ext=102
TEL;VALUE=uri;TYPE="work,cell,voice,video,text":tel:+1-418-262-6501
EMAIL;TYPE=work:[email protected]
GEO;TYPE=work:geo:46.772673,-71.282945
KEY;TYPE=work;VALUE=uri:
 http://www.viagenie.ca/simon.perreault/simon.asc
TZ:-0500
URL;TYPE=home:http://nomis80.org
END:VCARD
"""))
        self.assertEquals("4.0", x.version)
        self.assertEquals(1, len(x["LANG"][0].parameters))

        self.assertEquals("Simon Perreault", x["FN"][0].value)
        self.assertEquals(0, len(x["FN"][0].parameters))

        self.assertEquals("Perreault;Simon;;;ing. jr,M.Sc.", x["N"][0].value)
        self.assertEquals(0, len(x["N"][0].parameters))

        self.assertEquals("--0203", x["BDAY"][0].value)
        self.assertEquals(
            iso8601.parse_iso8601("--0203")[0], x["BDAY"][0].date)
        self.assertEquals(0, len(x["BDAY"][0].parameters))

        self.assertEquals("20090808T1430-0500", x["ANNIVERSARY"][0].value)
        self.assertEquals(
            iso8601.parse_iso8601("20090808T1430-0500")[0],
            x["ANNIVERSARY"][0].date)
        self.assertEquals(0, len(x["ANNIVERSARY"][0].parameters))

        self.assertEquals("M", x["GENDER"][0].value)
        self.assertEquals(0, len(x["GENDER"][0].parameters))

        self.assertEquals("fr", x["LANG"][0].value)
        self.assertEquals(1, len(x["LANG"][0].parameters))
        self.assertEquals("PREF", x["LANG"][0].parameters[0].name)
        self.assertEquals(1, x["LANG"][0].parameters[0].value)

        self.assertEquals("en", x["LANG"][1].value)
        self.assertEquals(1, len(x["LANG"][1].parameters))
        self.assertEquals("PREF", x["LANG"][1].parameters[0].name)
        self.assertEquals(2, x["LANG"][1].parameters[0].value)

        self.assertEquals("Viagenie", x["ORG"][0].value)
        self.assertEquals(1, len(x["ORG"][0].parameters))
        self.assertEquals("TYPE", x["ORG"][0].parameters[0].name)
        self.assertEquals(["work"], x["ORG"][0].parameters[0].value)

        self.assertEquals(
            ";Suite D2-630;2875 Laurier;Quebec;QC;G1V 2M2;Canada",
            x["ADR"][0].value)
        self.assertEquals(1, len(x["ADR"][0].parameters))
        self.assertEquals("TYPE", x["ADR"][0].parameters[0].name)
        self.assertEquals(["work"], x["ADR"][0].parameters[0].value)

        self.assertEquals("tel:+1-418-656-9254;ext=102", x["TEL"][0].value)
        #TODO
        #self.assertEquals(rfc3966.TelURI("tel:+1-418-656-9254;ext=102"), x["TEL"][0].uri)
        self.assertEquals(3, len(x["TEL"][0].parameters))
        self.assertEquals("VALUE", x["TEL"][0].parameters[0].name)
        self.assertEquals("uri", x["TEL"][0].parameters[0].value)
        self.assertEquals("TYPE", x["TEL"][0].parameters[1].name)
        self.assertEquals(["work", "voice"], x["TEL"][0].parameters[1].value)

        self.assertEquals("tel:+1-418-262-6501", x["TEL"][1].value)
        #TODO
        #sself.assertEquals(rfc3966.TelURI("tel:+1-418-262-6501"), x["TEL"][1].uri)
        self.assertEquals(2, len(x["TEL"][1].parameters))
        self.assertEquals("VALUE", x["TEL"][1].parameters[0].name)
        self.assertEquals("uri", x["TEL"][1].parameters[0].value)
        self.assertEquals("TYPE", x["TEL"][1].parameters[1].name)
        self.assertEquals(["work", "cell", "voice", "video", "text"],
                          x["TEL"][1].parameters[1].value)

        self.assertEquals("*****@*****.**", x["EMAIL"][0].value)
        #TODO
        #sself.assertEquals(rfc6068.MailtoURI("mailto:[email protected]"), x["EMAIL"][0].uri)
        self.assertEquals(1, len(x["EMAIL"][0].parameters))
        self.assertEquals("TYPE", x["EMAIL"][0].parameters[0].name)
        self.assertEquals(["work"], x["EMAIL"][0].parameters[0].value)

        self.assertEquals("geo:46.772673,-71.282945", x["GEO"][0].value)
        #TODO
        #sself.assertEquals(rfc5870.GeoURI("geo:46.772673,-71.282945"), x["GEO"][0].uri)
        self.assertEquals(1, len(x["GEO"][0].parameters))
        self.assertEquals("TYPE", x["GEO"][0].parameters[0].name)
        self.assertEquals(["work"], x["GEO"][0].parameters[0].value)

        self.assertEquals("http://www.viagenie.ca/simon.perreault/simon.asc",
                          x["KEY"][0].value)
        #TODO
        #sself.assertEquals(rfc2616.HttpURL("http://www.viagenie.ca/simon.perreault/simon.asc"), x["KEY"][0].url)
        self.assertEquals(2, len(x["KEY"][0].parameters))
        self.assertEquals("TYPE", x["KEY"][0].parameters[0].name)
        self.assertEquals(["work"], x["KEY"][0].parameters[0].value)

        self.assertEquals("-0500", x["TZ"][0].value)

        self.assertEquals("http://nomis80.org", x["URL"][0].value)
        #TODO
        #sself.assertEquals(rfc2616.HttpURL("http://nomis80.org"), x["URL"][0].url)
        self.assertEquals(1, len(x["URL"][0].parameters))
        self.assertEquals("TYPE", x["URL"][0].parameters[0].name)
        self.assertEquals(["home"], x["URL"][0].parameters[0].value)
コード例 #3
0
ファイル: property.py プロジェクト: Zearin/python-ietflib
 def parse_value(self, value):
     self.date = parse_iso8601(value)[0]
コード例 #4
0
ファイル: test_vCard.py プロジェクト: Zearin/python-ietflib
    def test_rfc_author(self):
        """Test RFC 6350 author's vCard."""
        x = parse_vcard(encode_to_stream("""
BEGIN:VCARD
VERSION:4.0
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr,M.Sc.
BDAY:--0203
ANNIVERSARY:20090808T1430-0500
GENDER:M
LANG;PREF=1:fr
LANG;PREF=2:en
ORG;TYPE=work:Viagenie
ADR;TYPE=work:;Suite D2-630;2875 Laurier;
 Quebec;QC;G1V 2M2;Canada
TEL;VALUE=uri;TYPE="work,voice";PREF=1:tel:+1-418-656-9254;ext=102
TEL;VALUE=uri;TYPE="work,cell,voice,video,text":tel:+1-418-262-6501
EMAIL;TYPE=work:[email protected]
GEO;TYPE=work:geo:46.772673,-71.282945
KEY;TYPE=work;VALUE=uri:
 http://www.viagenie.ca/simon.perreault/simon.asc
TZ:-0500
URL;TYPE=home:http://nomis80.org
END:VCARD
"""))
        self.assertEquals("4.0", x.version)
        self.assertEquals(1, len(x["LANG"][0].parameters))
        
        self.assertEquals("Simon Perreault", x["FN"][0].value)
        self.assertEquals(0, len(x["FN"][0].parameters))
        
        self.assertEquals("Perreault;Simon;;;ing. jr,M.Sc.", x["N"][0].value)
        self.assertEquals(0, len(x["N"][0].parameters))
        
        self.assertEquals("--0203", x["BDAY"][0].value)
        self.assertEquals(iso8601.parse_iso8601("--0203")[0], x["BDAY"][0].date)
        self.assertEquals(0, len(x["BDAY"][0].parameters))
        
        self.assertEquals("20090808T1430-0500", x["ANNIVERSARY"][0].value)
        self.assertEquals(iso8601.parse_iso8601("20090808T1430-0500")[0], x["ANNIVERSARY"][0].date)
        self.assertEquals(0, len(x["ANNIVERSARY"][0].parameters))
        
        self.assertEquals("M", x["GENDER"][0].value)
        self.assertEquals(0, len(x["GENDER"][0].parameters))
        
        self.assertEquals("fr", x["LANG"][0].value)
        self.assertEquals(1, len(x["LANG"][0].parameters))
        self.assertEquals("PREF", x["LANG"][0].parameters[0].name)
        self.assertEquals(1, x["LANG"][0].parameters[0].value)
        
        self.assertEquals("en", x["LANG"][1].value)
        self.assertEquals(1, len(x["LANG"][1].parameters))
        self.assertEquals("PREF", x["LANG"][1].parameters[0].name)
        self.assertEquals(2, x["LANG"][1].parameters[0].value)
        
        self.assertEquals("Viagenie", x["ORG"][0].value)
        self.assertEquals(1, len(x["ORG"][0].parameters))
        self.assertEquals("TYPE", x["ORG"][0].parameters[0].name)
        self.assertEquals(["work"], x["ORG"][0].parameters[0].value)
        
        self.assertEquals(";Suite D2-630;2875 Laurier;Quebec;QC;G1V 2M2;Canada", x["ADR"][0].value)
        self.assertEquals(1, len(x["ADR"][0].parameters))
        self.assertEquals("TYPE", x["ADR"][0].parameters[0].name)
        self.assertEquals(["work"], x["ADR"][0].parameters[0].value)
        
        self.assertEquals("tel:+1-418-656-9254;ext=102", x["TEL"][0].value)
        #TODO
        #self.assertEquals(rfc3966.TelURI("tel:+1-418-656-9254;ext=102"), x["TEL"][0].uri)
        self.assertEquals(3, len(x["TEL"][0].parameters))
        self.assertEquals("VALUE", x["TEL"][0].parameters[0].name)
        self.assertEquals("uri", x["TEL"][0].parameters[0].value)
        self.assertEquals("TYPE", x["TEL"][0].parameters[1].name)
        self.assertEquals(["work","voice"], x["TEL"][0].parameters[1].value)
        
        self.assertEquals("tel:+1-418-262-6501", x["TEL"][1].value)
        #TODO
        #sself.assertEquals(rfc3966.TelURI("tel:+1-418-262-6501"), x["TEL"][1].uri)
        self.assertEquals(2, len(x["TEL"][1].parameters))
        self.assertEquals("VALUE", x["TEL"][1].parameters[0].name)
        self.assertEquals("uri", x["TEL"][1].parameters[0].value)
        self.assertEquals("TYPE", x["TEL"][1].parameters[1].name)
        self.assertEquals(["work","cell","voice","video","text"], x["TEL"][1].parameters[1].value)
        
        self.assertEquals("*****@*****.**", x["EMAIL"][0].value)
        #TODO
        #sself.assertEquals(rfc6068.MailtoURI("mailto:[email protected]"), x["EMAIL"][0].uri)
        self.assertEquals(1, len(x["EMAIL"][0].parameters))
        self.assertEquals("TYPE", x["EMAIL"][0].parameters[0].name)
        self.assertEquals(["work"], x["EMAIL"][0].parameters[0].value)
        
        self.assertEquals("geo:46.772673,-71.282945", x["GEO"][0].value)
        #TODO
        #sself.assertEquals(rfc5870.GeoURI("geo:46.772673,-71.282945"), x["GEO"][0].uri)
        self.assertEquals(1, len(x["GEO"][0].parameters))
        self.assertEquals("TYPE", x["GEO"][0].parameters[0].name)
        self.assertEquals(["work"], x["GEO"][0].parameters[0].value)
        
        self.assertEquals("http://www.viagenie.ca/simon.perreault/simon.asc", x["KEY"][0].value)
        #TODO
        #sself.assertEquals(rfc2616.HttpURL("http://www.viagenie.ca/simon.perreault/simon.asc"), x["KEY"][0].url)
        self.assertEquals(2, len(x["KEY"][0].parameters))
        self.assertEquals("TYPE", x["KEY"][0].parameters[0].name)
        self.assertEquals(["work"], x["KEY"][0].parameters[0].value)
        
        self.assertEquals("-0500", x["TZ"][0].value)
        
        self.assertEquals("http://nomis80.org", x["URL"][0].value)
        #TODO
        #sself.assertEquals(rfc2616.HttpURL("http://nomis80.org"), x["URL"][0].url)
        self.assertEquals(1, len(x["URL"][0].parameters))
        self.assertEquals("TYPE", x["URL"][0].parameters[0].name)
        self.assertEquals(["home"], x["URL"][0].parameters[0].value)