1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6class PingFilter(object): 7 """Ping filter that accepts any pings.""" 8 9 def __call__(self, ping): 10 return True 11 12 13class DeletionRequestPingFilter(PingFilter): 14 """Ping filter that accepts deletion-request pings.""" 15 16 def __call__(self, ping): 17 if not super(DeletionRequestPingFilter, self).__call__(ping): 18 return False 19 20 return ping["type"] == "deletion-request" 21 22 23class EventPingFilter(PingFilter): 24 """Ping filter that accepts event pings.""" 25 26 def __call__(self, ping): 27 if not super(EventPingFilter, self).__call__(ping): 28 return False 29 30 return ping["type"] == "event" 31 32 33class FirstShutdownPingFilter(PingFilter): 34 """Ping filter that accepts first-shutdown pings.""" 35 36 def __call__(self, ping): 37 if not super(FirstShutdownPingFilter, self).__call__(ping): 38 return False 39 40 return ping["type"] == "first-shutdown" 41 42 43class MainPingFilter(PingFilter): 44 """Ping filter that accepts main pings.""" 45 46 def __call__(self, ping): 47 if not super(MainPingFilter, self).__call__(ping): 48 return False 49 50 return ping["type"] == "main" 51 52 53class MainPingReasonFilter(MainPingFilter): 54 """Ping filter that accepts main pings that match the 55 specified reason. 56 """ 57 58 def __init__(self, reason): 59 super(MainPingReasonFilter, self).__init__() 60 self.reason = reason 61 62 def __call__(self, ping): 63 if not super(MainPingReasonFilter, self).__call__(ping): 64 return False 65 66 return ping["payload"]["info"]["reason"] == self.reason 67 68 69ANY_PING = PingFilter() 70DELETION_REQUEST_PING = DeletionRequestPingFilter() 71EVENT_PING = EventPingFilter() 72FIRST_SHUTDOWN_PING = FirstShutdownPingFilter() 73MAIN_PING = MainPingFilter() 74MAIN_SHUTDOWN_PING = MainPingReasonFilter("shutdown") 75MAIN_ENVIRONMENT_CHANGE_PING = MainPingReasonFilter("environment-change") 76