Class Polo

class marcopolo.polo.polo.Polo(offered_services=None, user_services=None, multicast_group=None, verify_regexp=None)[source]

Twisted-inherited class in charge of receiving Marco requests on the defined multicast groups

__init__(offered_services=None, user_services=None, multicast_group=None, verify_regexp=None)[source]

Creates the Polo instance with the data structures to work with. If defined, the offered_services and user_services variables will be treated as references to a list and dictionary respectively (i.e. the values will be modified, but the object reference will never be altered).

Parameters:
  • offered_services (list) – A list of dictionaries which comprises all the root services.
  • user_services (dict) – A dictionary of all the user services (the key is the user name and the value is a list of services like that of offered_services).
  • multicast_group (str) – The IPv4 address of the multicast group to join to. Important: The multicast_addr is not validated until the reactor is started.
  • verify_regexp (str) – Regular expression used to verify an user service.
datagramReceived(datagram, address)[source]

When a datagram is received the command is parsed and a response is generated

Parameters:
  • datagram (bytes) – The byte stream with the message
  • address (tuple) – A tuple with the requesting address and port
handler(arg)[source]

An ‘errback’ that is called when the multicast subscription is unsuccessful. It schedules a retry and increments an attempt counter.

Parameters:arg (object) – The arg passed in the addErrback() call
polo(command, address)[source]

Replies to Polo requests

Parameters:
  • command (str) – The command that triggered this action
  • address (tuple) – A tuple with the requesting address and port
reload_services()[source]

Reloads both root and user services (calling reload_user_services()). The services stored in a file are loaded again, whereas dynamic services are kept intact.

reload_user_services()[source]

Iterates through all the users who have services and calls reload_user_services_iter for each of them

reload_user_services_iter(user)[source]

Reloads the services for a given user

Parameters:user (str) – The name of the user
response_request_for(command, service, address)[source]

Handles request-for requests

Parameters:
  • command (str) – The command that triggered this action
  • service (str) – The id of the service
  • address (tuple) – A tuple with the requesting address and port
response_request_for_user(command, user, service, address)[source]

Handles user request-for requests

Parameters:
  • user (str) – The name of the user
  • command (str) – The command that triggered this action
  • service (str) – The service name
  • address (tuple) – A tuple with the requesting address and port

If the user has not been added to the list of services before this request, reload_user_services_iter(user) is called

response_services(command, param, address)[source]

Replies to Services requests

retry()[source]

Tries to join the multicast group if it unsuccessful

startProtocol()[source]

Operations to be performed before starting to listen