Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

"""VOEvent-related utilities.""" 

import ipaddress 

import socket 

 

 

def get_host_port(address): 

"""Split a network address of the form ``host:port``. 

 

Parameters 

---------- 

network : str 

The network address. 

 

Returns 

------- 

host : str 

The hostname, or an empty string if missing. 

port : int, None 

The port number, or None if missing. 

 

""" 

host, _, port = address.partition(':') 

return host, (int(port) if port else None) 

 

 

def get_local_ivo(app): 

"""Create an IVOID to identify this application in VOEvent Transport 

Protocol packets. 

 

Returns 

------- 

str 

A local IVOID composed of the machine's fully qualified domain name and 

the Celery application name (for example, 

`ivo://emfollow.ligo.caltech.edu/gwcelery`). 

 

""" 

return 'ivo://{}/{}'.format(socket.getfqdn(), app.main) 

 

 

def get_network(address): 

"""Find the IP network prefix for a hostname or CIDR notation. 

 

Parameters 

---------- 

address : str 

A hostname, such as ``ligo.org``, or an IP address prefix in CIDR 

notation, such as ``127.0.0.0/8``. 

 

Returns 

------- 

ipaddress.IPv4Network 

An object representing the IP address prefix. 

 

""" 

try: 

net = ipaddress.ip_network(address, strict=False) 

except ValueError: 

net = ipaddress.ip_network(socket.gethostbyname(address), strict=False) 

return net