1""" Multicast DNS Service Discovery for Python, v0.14-wmcbrine 2 Copyright 2003 Paul Scott-Murphy, 2014 William McBrine 3 4 This module provides a framework for the use of DNS Service Discovery 5 using IP multicast. 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 20 USA 21""" 22 23from ..const import ( 24 _FLAGS_QR_MASK, 25 _FLAGS_QR_QUERY, 26 _FLAGS_QR_RESPONSE, 27 _FLAGS_TC, 28) 29 30 31class DNSMessage: 32 """A base class for DNS messages.""" 33 34 __slots__ = ('flags',) 35 36 def __init__(self, flags: int) -> None: 37 """Construct a DNS message.""" 38 self.flags = flags 39 40 def is_query(self) -> bool: 41 """Returns true if this is a query.""" 42 return (self.flags & _FLAGS_QR_MASK) == _FLAGS_QR_QUERY 43 44 def is_response(self) -> bool: 45 """Returns true if this is a response.""" 46 return (self.flags & _FLAGS_QR_MASK) == _FLAGS_QR_RESPONSE 47 48 @property 49 def truncated(self) -> bool: 50 """Returns true if this is a truncated.""" 51 return (self.flags & _FLAGS_TC) == _FLAGS_TC 52