diff options
author | Ivan Alejandro <ivanalejandro0@yahoo.com.ar> | 2013-06-21 17:38:03 -0300 |
---|---|---|
committer | Ivan Alejandro <ivanalejandro0@yahoo.com.ar> | 2013-06-21 17:38:03 -0300 |
commit | 4c54df049b3ef23b29c1e4e2c42201012843c8a1 (patch) | |
tree | 768316a819873e4d2be0410970d9b3a89acabe6d /src | |
parent | 1f9acbe3366d08c280b9076274f612efabde3870 (diff) |
Allow to create the class using a specific offset.
This is useful for testing purposes, so we can be consistent with the
distance calculation.
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/services/eip/eipconfig.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/leap/services/eip/eipconfig.py b/src/leap/services/eip/eipconfig.py index ff98bf55..e79314ce 100644 --- a/src/leap/services/eip/eipconfig.py +++ b/src/leap/services/eip/eipconfig.py @@ -39,17 +39,21 @@ class VPNGatewaySelector(object): VPN Gateway selector. """ - def __init__(self, eipconfig): + def __init__(self, eipconfig, tz_offset=None): ''' Constructor for VPNGatewaySelector. :param eipconfig: a valid EIP Configuration. :type eipconfig: EIPConfig + :param tz_offset: use this offset as a local distance to GMT. + :type tz_offset: datetime.timedelta ''' leap_assert_type(eipconfig, EIPConfig) - self._local_offset = 0 # defaults to GMT - self._local_timezone = None - self._set_local_offset() + + self._local_offset = tz_offset + if tz_offset is None: + self._local_offset = self._get_local_offset() + self._eipconfig = eipconfig def get_gateways(self): @@ -95,15 +99,17 @@ class VPNGatewaySelector(object): hours = diff.seconds / (60 * 60) return hours - def _set_local_offset(self): + def _get_local_offset(self): ''' - Sets the distance between GMT and the local timezone. + Returns the distance between GMT and the local timezone. + + :rtype: datetime.timedelta ''' local_offset = time.timezone if time.daylight: local_offset = time.altzone - self._local_offset = datetime.timedelta(seconds=-local_offset) + return datetime.timedelta(seconds=-local_offset) class EIPConfig(BaseConfig): @@ -233,6 +239,7 @@ if __name__ == "__main__": if eipconfig.load("leap/providers/bitmask.net/eip-service.json"): print eipconfig.get_clusters() print eipconfig.get_gateways() + print eipconfig.get_locations() print eipconfig.get_openvpn_configuration() print eipconfig.get_serial() print eipconfig.get_version() |