File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515_NTP_DELTA = (_SYSTEM_EPOCH - _NTP_EPOCH ).days * 24 * 3600
1616
1717
18+ class NtpError (Exception ):
19+ """Base class for ntp module errors."""
20+
21+
1822def ntp_to_system_time (date ):
1923 """Convert a NTP time to system time.
2024
@@ -28,6 +32,9 @@ def system_time_to_ntp(date):
2832
2933 System time is reprensented by seconds since the epoch in UTC.
3034 """
31- ntp = date + _NTP_DELTA
35+ try :
36+ ntp = date + _NTP_DELTA
37+ except TypeError as ve :
38+ raise NtpError ('Invalud date: {}' .format (ve ))
3239 num_secs , fraction = str (ntp ).split ('.' )
3340 return struct .pack ('>I' , int (num_secs )) + struct .pack ('>I' , int (fraction ))
Original file line number Diff line number Diff line change @@ -237,4 +237,7 @@ def write_date(system_time):
237237 if system_time == IMMEDIATELY :
238238 return ntp .IMMEDIATELY
239239
240- return ntp .system_time_to_ntp (system_time )
240+ try :
241+ return ntp .system_time_to_ntp (system_time )
242+ except ntp .NtpError as ntpe :
243+ raise BuildError (ntpe )
Original file line number Diff line number Diff line change 6767 b"\x00 \x00 \x00 \x20 "
6868 b"/SYNC\x00 \x00 \x00 \x00 " )
6969
70+ _DGRAM_UNKNOWN_TYPE = (
71+ b"#bundle\x00 "
72+ b"\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x01 "
73+ b"\x00 \x00 \x00 \x10 "
74+ b"iamnotaslash" )
75+
7076
7177class TestOscBundle (unittest .TestCase ):
7278
@@ -117,5 +123,8 @@ def test_raises_on_invalid_datagram(self):
117123 self .assertRaises (
118124 osc_bundle .ParseError , osc_bundle .OscBundle , _DGRAM_INVALID_INDEX )
119125
126+ def test_unknown_type (self ):
127+ bundle = osc_bundle .OscBundle (_DGRAM_UNKNOWN_TYPE )
128+
120129if __name__ == "__main__" :
121130 unittest .main ()
Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ def test_raises_on_build(self):
1616 bundle .add_content (None )
1717 self .assertRaises (osc_bundle_builder .BuildError , bundle .build )
1818
19+ def test_raises_on_invalid_timestamp (self ):
20+ bundle = osc_bundle_builder .OscBundleBuilder ("I am not a timestamp" )
21+ self .assertRaises (osc_bundle_builder .BuildError , bundle .build )
22+
1923 def test_build_complex_bundle (self ):
2024 bundle = osc_bundle_builder .OscBundleBuilder (
2125 osc_bundle_builder .IMMEDIATELY )
You can’t perform that action at this time.
0 commit comments