X7ROOT File Manager
Current Path:
/usr/lib/python2.7/site-packages
usr
/
lib
/
python2.7
/
site-packages
/
📁
..
📄
ANSI.py
(10.59 KB)
📄
ANSI.pyc
(10.27 KB)
📄
ANSI.pyo
(10.27 KB)
📁
ConfigArgParse-0.11.0-py2.7.egg-info
📄
FSM.py
(13.01 KB)
📄
FSM.pyc
(13.48 KB)
📄
FSM.pyo
(13.48 KB)
📄
IPy-0.75-py2.7.egg-info
(9.83 KB)
📄
IPy.py
(50.07 KB)
📄
IPy.pyc
(39.92 KB)
📄
IPy.pyo
(39.92 KB)
📁
_dummy_thread
📁
_markerlib
📁
_markupbase
📁
_thread
📁
acme
📁
acme-1.11.0-py2.7.egg-info
📄
augeas.py
(23 KB)
📄
augeas.pyc
(21.69 KB)
📄
augeas.pyo
(21.69 KB)
📁
awscli
📁
awscli-1.23.2-py2.7.egg-info
📁
backports
📄
backports.ssl_match_hostname-3.5.0.1-py2.7.egg-info
(3.96 KB)
📁
blivet
📄
blivet-0.61.15.76-py2.7.egg-info
(269 B)
📁
builtins
📁
certbot
📁
certbot-1.11.0-py2.7.egg-info
📁
chardet
📁
chardet-2.2.1-py2.7.egg-info
📁
clufter
📁
clufter-0.77.1-py2.7.egg-info
📁
concurrent
📄
configargparse.py
(40.35 KB)
📄
configargparse.pyc
(32.46 KB)
📄
configargparse.pyo
(32.46 KB)
📄
configobj-4.7.2-py2.7.egg-info
(2.08 KB)
📄
configobj.py
(86.1 KB)
📄
configobj.pyc
(64.72 KB)
📄
configobj.pyo
(64.72 KB)
📁
configshell
📁
configshell_fb
📁
configshell_fb-1.1.25-py2.7.egg-info
📁
copyreg
📁
createrepo
📁
cupshelpers
📄
cupshelpers-1.0-py2.7.egg-info
(231 B)
📁
dateutil
📁
decorator-3.4.0-py2.7.egg-info
📄
decorator.py
(10.39 KB)
📄
decorator.pyc
(8.36 KB)
📄
decorator.pyo
(8.32 KB)
📁
di
📁
di-0.3-py2.7.egg-info
📁
distro-1.5.0-py2.7.egg-info
📄
distro.py
(42.61 KB)
📄
distro.pyc
(39.01 KB)
📄
distro.pyo
(38.92 KB)
📁
docutils
📄
docutils-0.11-py2.7.egg-info
(2.31 KB)
📄
easy_install.py
(126 B)
📄
easy_install.pyc
(315 B)
📄
easy_install.pyo
(315 B)
📁
enum
📄
enum34-1.0.4-py2.7.egg-info
(28.04 KB)
📁
fail2ban
📁
fail2ban-0.11.2-py2.7.egg-info
📄
fdpexpect.py
(2.43 KB)
📄
fdpexpect.pyc
(3.03 KB)
📄
fdpexpect.pyo
(3.03 KB)
📁
firewall
📁
firstboot
📄
firstboot-19.5-py2.7.egg-info
(263 B)
📁
fros-1.0-py2.7.egg-info
📁
future
📁
future-0.18.2-py2.7.egg-info
📁
futures-3.1.1-py2.7.egg-info
📁
gtweak
📁
html
📁
http
📁
idna
📁
idna-2.4-py2.7.egg-info
📁
iniparse
📄
iniparse-0.4-py2.7.egg-info
(1.06 KB)
📁
initial_setup
📁
initial_setup-0.3.9.45-py2.7.egg-info
📄
ipaddress-1.0.16-py2.7.egg-info
(783 B)
📄
ipaddress.py
(78.03 KB)
📄
ipaddress.pyc
(73.75 KB)
📄
ipaddress.pyo
(73.57 KB)
📁
isc
📄
isc-2.0-py2.7.egg-info
(267 B)
📁
javapackages
📁
javapackages-1.0.0-py2.7.egg-info
📁
josepy
📁
josepy-1.3.0-py2.7.egg-info
📁
kitchen
📁
kitchen-1.1.1-py2.7.egg-info
📄
langtable-0.0.31-py2.7.egg-info
(2.66 KB)
📄
langtable.py
(74.29 KB)
📄
langtable.pyc
(55.85 KB)
📄
langtable.pyo
(55.85 KB)
📁
libfuturize
📁
libpasteurize
📁
louis
📁
lsm
📁
meh
📁
mock-1.0.1-py2.7.egg-info
📄
mock.py
(73.76 KB)
📄
mock.pyc
(66.98 KB)
📄
mock.pyo
(66.98 KB)
📁
ndg
📄
ndg_httpsclient-0.3.2-py2.7-nspkg.pth
(298 B)
📁
ndg_httpsclient-0.3.2-py2.7.egg-info
📄
ntplib-0.3.2-py2.7.egg-info
(1.73 KB)
📄
ntplib.py
(13.21 KB)
📄
ntplib.pyc
(13.07 KB)
📄
ntplib.pyo
(13.07 KB)
📁
packagekit
📁
parsedatetime
📁
parsedatetime-2.4-py2.7.egg-info
📁
past
📁
pcs
📁
pcs-0.9.169-py2.7.egg-info
📄
pexpect-2.3-py2.7.egg-info
(287 B)
📄
pexpect.py
(74.16 KB)
📄
pexpect.pyc
(62.45 KB)
📄
pexpect.pyo
(62.29 KB)
📄
pkg_resources.py
(98.74 KB)
📄
pkg_resources.pyc
(105.5 KB)
📄
pkg_resources.pyo
(105.47 KB)
📁
ply
📄
ply-3.4-py2.7.egg-info
(900 B)
📁
procfs
📄
pxssh.py
(14.25 KB)
📄
pxssh.pyc
(11 KB)
📄
pxssh.pyo
(11 KB)
📁
pyRFC3339-1.1-py2.7.egg-info
📁
pyasn1
📁
pyasn1-0.1.9-py2.7.egg-info
📁
pyatspi
📁
pycparser
📁
pycparser-2.14-py2.7.egg-info
📁
pyfros
📄
pyinotify-0.9.4-py2.7.egg-info
(1.15 KB)
📄
pyinotify.py
(85.61 KB)
📄
pyinotify.pyc
(83.4 KB)
📄
pyinotify.pyo
(83.14 KB)
📁
pykickstart
📄
pykickstart-1.99.66.22-py2.7.egg-info
(279 B)
📄
pyparsing-1.5.6-py2.7.egg-info
(670 B)
📄
pyparsing.py
(151.79 KB)
📄
pyparsing.pyc
(145.41 KB)
📄
pyparsing.pyo
(145.41 KB)
📁
pyrfc3339
📄
python_augeas-0.5.0-py2.7.egg-info
(238 B)
📁
python_dateutil-1.5-py2.7.egg-info
📄
python_linux_procfs-0.4.9-py2.7.egg-info
(350 B)
📄
python_meh-0.25.3-py2.7.egg-info
(274 B)
📁
pytz
📁
pytz-2016.10-py2.7.egg-info
📁
pyudev
📁
pyudev-0.15-py2.7.egg-info
📁
queue
📁
reprlib
📁
requests
📄
requests-2.6.0-py2.7.egg-info
(39.41 KB)
📁
requests_toolbelt
📁
requests_toolbelt-0.8.0-py2.7.egg-info
📁
rpmUtils
📁
rtslib
📁
rtslib_fb
📁
rtslib_fb-2.1.74-py2.7.egg-info
📁
s3transfer
📁
s3transfer-0.1.13-py2.7.egg-info
📁
scdate
📄
scdate-1.10.6-py2.7.egg-info
(181 B)
📄
screen.py
(10.16 KB)
📄
screen.pyc
(13.2 KB)
📄
screen.pyo
(13.2 KB)
📁
setuptools
📁
setuptools-0.9.8-py2.7.egg-info
📁
six-1.9.0-py2.7.egg-info
📄
six.py
(28.97 KB)
📄
six.pyc
(29.01 KB)
📄
six.pyo
(29.01 KB)
📁
slip
📄
slip-0.4.0-py2.7.egg-info
(196 B)
📄
slip.dbus-0.4.0-py2.7.egg-info
(269 B)
📁
socketserver
📁
sos
📁
suds
📁
suds-0.4.1-py2.7.egg-info
📁
targetcli
📁
targetcli_fb-2.1.53-py2.7.egg-info
📁
targetd
📄
targetd-0.8.5-py2.7.egg-info
(244 B)
📁
tkinter
📁
tuned
📁
urlgrabber
📄
urlgrabber-3.10-py2.7.egg-info
(2.21 KB)
📁
urllib3
📁
urllib3-1.10.2-py2.7.egg-info
📄
validate.py
(45.22 KB)
📄
validate.pyc
(45.62 KB)
📄
validate.pyo
(45.62 KB)
📁
winreg
📁
xmlrpc
📁
yum
📁
yum_langpacks-0.4.2-py2.7.egg-info
📁
yumutils
📁
zope
📄
zope.component-4.1.0-py2.7-nspkg.pth
(301 B)
📁
zope.component-4.1.0-py2.7.egg-info
📄
zope.event-4.0.3-py2.7-nspkg.pth
(301 B)
📁
zope.event-4.0.3-py2.7.egg-info
Editing: ntplib.py
############################################################################### # ntplib - Python NTP library. # Copyright (C) 2009 Charles-Francois Natali <cf.natali@gmail.com> # # ntplib is free software; you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) any # later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software Foundation, 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA ############################################################################### """Python NTP library. Implementation of client-side NTP (RFC-1305), and useful NTP-related functions. """ import datetime import socket import struct import time class NTPException(Exception): """Exception raised by this module.""" pass class NTP: """Helper class defining constants.""" _SYSTEM_EPOCH = datetime.date(*time.gmtime(0)[0:3]) """system epoch""" _NTP_EPOCH = datetime.date(1900, 1, 1) """NTP epoch""" NTP_DELTA = (_SYSTEM_EPOCH - _NTP_EPOCH).days * 24 * 3600 """delta between system and NTP time""" REF_ID_TABLE = { "GOES": "Geostationary Orbit Environment Satellite", "GPS\0": "Global Position System", "GAL\0": "Galileo Positioning System", "PPS\0": "Generic pulse-per-second", "IRIG": "Inter-Range Instrumentation Group", "WWVB": "LF Radio WWVB Ft. Collins, CO 60 kHz", "DCF\0": "LF Radio DCF77 Mainflingen, DE 77.5 kHz", "HBG\0": "LF Radio HBG Prangins, HB 75 kHz", "MSF\0": "LF Radio MSF Anthorn, UK 60 kHz", "JJY\0": "LF Radio JJY Fukushima, JP 40 kHz, Saga, JP 60 kHz", "LORC": "MF Radio LORAN C station, 100 kHz", "TDF\0": "MF Radio Allouis, FR 162 kHz", "CHU\0": "HF Radio CHU Ottawa, Ontario", "WWV\0": "HF Radio WWV Ft. Collins, CO", "WWVH": "HF Radio WWVH Kauai, HI", "NIST": "NIST telephone modem", "ACTS": "NIST telephone modem", "USNO": "USNO telephone modem", "PTB\0": "European telephone modem", "LOCL": "uncalibrated local clock", "CESM": "calibrated Cesium clock", "RBDM": "calibrated Rubidium clock", "OMEG": "OMEGA radionavigation system", "DCN\0": "DCN routing protocol", "TSP\0": "TSP time protocol", "DTS\0": "Digital Time Service", "ATOM": "Atomic clock (calibrated)", "VLF\0": "VLF radio (OMEGA,, etc.)", "1PPS": "External 1 PPS input", "FREE": "(Internal clock)", "INIT": "(Initialization)", "\0\0\0\0": "NULL", } """reference identifier table""" STRATUM_TABLE = { 0: "unspecified or invalid", 1: "primary reference (%s)", } """stratum table""" MODE_TABLE = { 0: "reserved", 1: "symmetric active", 2: "symmetric passive", 3: "client", 4: "server", 5: "broadcast", 6: "reserved for NTP control messages", 7: "reserved for private use", } """mode table""" LEAP_TABLE = { 0: "no warning", 1: "last minute of the day has 61 seconds", 2: "last minute of the day has 59 seconds", 3: "unknown (clock unsynchronized)", } """leap indicator table""" class NTPPacket: """NTP packet class. This represents an NTP packet. """ _PACKET_FORMAT = "!B B B b 11I" """packet format to pack/unpack""" def __init__(self, version=2, mode=3, tx_timestamp=0): """Constructor. Parameters: version -- NTP version mode -- packet mode (client, server) tx_timestamp -- packet transmit timestamp """ self.leap = 0 """leap second indicator""" self.version = version """version""" self.mode = mode """mode""" self.stratum = 0 """stratum""" self.poll = 0 """poll interval""" self.precision = 0 """precision""" self.root_delay = 0 """root delay""" self.root_dispersion = 0 """root dispersion""" self.ref_id = 0 """reference clock identifier""" self.ref_timestamp = 0 """reference timestamp""" self.orig_timestamp = 0 """originate timestamp""" self.recv_timestamp = 0 """receive timestamp""" self.tx_timestamp = tx_timestamp """tansmit timestamp""" def to_data(self): """Convert this NTPPacket to a buffer that can be sent over a socket. Returns: buffer representing this packet Raises: NTPException -- in case of invalid field """ try: packed = struct.pack(NTPPacket._PACKET_FORMAT, (self.leap << 6 | self.version << 3 | self.mode), self.stratum, self.poll, self.precision, _to_int(self.root_delay) << 16 | _to_frac(self.root_delay, 16), _to_int(self.root_dispersion) << 16 | _to_frac(self.root_dispersion, 16), self.ref_id, _to_int(self.ref_timestamp), _to_frac(self.ref_timestamp), _to_int(self.orig_timestamp), _to_frac(self.orig_timestamp), _to_int(self.recv_timestamp), _to_frac(self.recv_timestamp), _to_int(self.tx_timestamp), _to_frac(self.tx_timestamp)) except struct.error: raise NTPException("Invalid NTP packet fields.") return packed def from_data(self, data): """Populate this instance from a NTP packet payload received from the network. Parameters: data -- buffer payload Raises: NTPException -- in case of invalid packet format """ try: unpacked = struct.unpack(NTPPacket._PACKET_FORMAT, data[0:struct.calcsize(NTPPacket._PACKET_FORMAT)]) except struct.error: raise NTPException("Invalid NTP packet.") self.leap = unpacked[0] >> 6 & 0x3 self.version = unpacked[0] >> 3 & 0x7 self.mode = unpacked[0] & 0x7 self.stratum = unpacked[1] self.poll = unpacked[2] self.precision = unpacked[3] self.root_delay = float(unpacked[4])/2**16 self.root_dispersion = float(unpacked[5])/2**16 self.ref_id = unpacked[6] self.ref_timestamp = _to_time(unpacked[7], unpacked[8]) self.orig_timestamp = _to_time(unpacked[9], unpacked[10]) self.recv_timestamp = _to_time(unpacked[11], unpacked[12]) self.tx_timestamp = _to_time(unpacked[13], unpacked[14]) class NTPStats(NTPPacket): """NTP statistics. Wrapper for NTPPacket, offering additional statistics like offset and delay, and timestamps converted to system time. """ def __init__(self): """Constructor.""" NTPPacket.__init__(self) self.dest_timestamp = 0 """destination timestamp""" @property def offset(self): """offset""" return ((self.recv_timestamp - self.orig_timestamp) + (self.tx_timestamp - self.dest_timestamp))/2 @property def delay(self): """round-trip delay""" return ((self.dest_timestamp - self.orig_timestamp) - (self.tx_timestamp - self.recv_timestamp)) @property def tx_time(self): """Transmit timestamp in system time.""" return ntp_to_system_time(self.tx_timestamp) @property def recv_time(self): """Receive timestamp in system time.""" return ntp_to_system_time(self.recv_timestamp) @property def orig_time(self): """Originate timestamp in system time.""" return ntp_to_system_time(self.orig_timestamp) @property def ref_time(self): """Reference timestamp in system time.""" return ntp_to_system_time(self.ref_timestamp) @property def dest_time(self): """Destination timestamp in system time.""" return ntp_to_system_time(self.dest_timestamp) class NTPClient: """NTP client session.""" def __init__(self): """Constructor.""" pass def request(self, host, version=2, port='ntp', timeout=5): """Query a NTP server. Parameters: host -- server name/address version -- NTP version to use port -- server port timeout -- timeout on socket operations Returns: NTPStats object """ # lookup server address addrinfo = socket.getaddrinfo(host, port)[0] family, sockaddr = addrinfo[0], addrinfo[4] # create the socket s = socket.socket(family, socket.SOCK_DGRAM) try: s.settimeout(timeout) # create the request packet - mode 3 is client query_packet = NTPPacket(mode=3, version=version, tx_timestamp=system_to_ntp_time(time.time())) # send the request s.sendto(query_packet.to_data(), sockaddr) # wait for the response - check the source address src_addr = None, while src_addr[0] != sockaddr[0]: response_packet, src_addr = s.recvfrom(256) # build the destination timestamp dest_timestamp = system_to_ntp_time(time.time()) except socket.timeout: raise NTPException("No response received from %s." % host) finally: s.close() # construct corresponding statistics stats = NTPStats() stats.from_data(response_packet) stats.dest_timestamp = dest_timestamp return stats def _to_int(timestamp): """Return the integral part of a timestamp. Parameters: timestamp -- NTP timestamp Retuns: integral part """ return int(timestamp) def _to_frac(timestamp, n=32): """Return the fractional part of a timestamp. Parameters: timestamp -- NTP timestamp n -- number of bits of the fractional part Retuns: fractional part """ return int(abs(timestamp - _to_int(timestamp)) * 2**n) def _to_time(integ, frac, n=32): """Return a timestamp from an integral and fractional part. Parameters: integ -- integral part frac -- fractional part n -- number of bits of the fractional part Retuns: timestamp """ return integ + float(frac)/2**n def ntp_to_system_time(timestamp): """Convert a NTP time to system time. Parameters: timestamp -- timestamp in NTP time Returns: corresponding system time """ return timestamp - NTP.NTP_DELTA def system_to_ntp_time(timestamp): """Convert a system time to a NTP time. Parameters: timestamp -- timestamp in system time Returns: corresponding NTP time """ return timestamp + NTP.NTP_DELTA def leap_to_text(leap): """Convert a leap indicator to text. Parameters: leap -- leap indicator value Returns: corresponding message Raises: NTPException -- in case of invalid leap indicator """ if leap in NTP.LEAP_TABLE: return NTP.LEAP_TABLE[leap] else: raise NTPException("Invalid leap indicator.") def mode_to_text(mode): """Convert a NTP mode value to text. Parameters: mode -- NTP mode Returns: corresponding message Raises: NTPException -- in case of invalid mode """ if mode in NTP.MODE_TABLE: return NTP.MODE_TABLE[mode] else: raise NTPException("Invalid mode.") def stratum_to_text(stratum): """Convert a stratum value to text. Parameters: stratum -- NTP stratum Returns: corresponding message Raises: NTPException -- in case of invalid stratum """ if stratum in NTP.STRATUM_TABLE: return NTP.STRATUM_TABLE[stratum] % (stratum) elif 1 < stratum < 16: return "secondary reference (%s)" % (stratum) elif stratum == 16: return "unsynchronized (%s)" % (stratum) else: raise NTPException("Invalid stratum or reserved.") def ref_id_to_text(ref_id, stratum=2): """Convert a reference clock identifier to text according to its stratum. Parameters: ref_id -- reference clock indentifier stratum -- NTP stratum Returns: corresponding message Raises: NTPException -- in case of invalid stratum """ fields = (ref_id >> 24 & 0xff, ref_id >> 16 & 0xff, ref_id >> 8 & 0xff, ref_id & 0xff) # return the result as a string or dot-formatted IP address if 0 <= stratum <= 1: text = '%c%c%c%c' % fields if text in NTP.REF_ID_TABLE: return NTP.REF_ID_TABLE[text] else: return "Unidentified reference source '%s'" % (text) elif 2 <= stratum < 255: return '%d.%d.%d.%d' % fields else: raise NTPException("Invalid stratum.")
Upload File
Create Folder