'Convert name to wire format, possibly compressing it.
@param file: the file where the name is emitted (typically
a BytesIO file).  If None, a string containing the wire name
will be returned.
@type file: file or None
@param compress: The compression table.  If None (the default) names
will not be compressed.
@type compress: dict
@param origin: If the name is relative and origin is not None, then
origin will be appended to it.
@type origin: dns.name.Name object
@raises NeedAbsoluteNameOrOrigin: All names in wire format are
absolute.  If self is a relative name, then an origin must be supplied;
if it is missing, then this exception is raised'

def to_wire(self, file=None, compress=None, origin=None):

    if (file is None):
        file = BytesIO()
        want_return = True
    else:
        want_return = False
    if (not self.is_absolute()):
        if ((origin is None) or (not origin.is_absolute())):
            raise NeedAbsoluteNameOrOrigin
        labels = list(self.labels)
        labels.extend(list(origin.labels))
    else:
        labels = self.labels
    i = 0
    for label in labels:
        n = Name(labels[i:])
        i += 1
        if (compress is not None):
            pos = compress.get(n)
        else:
            pos = None
        if (pos is not None):
            value = (49152 + pos)
            s = struct.pack('!H', value)
            file.write(s)
            break
        else:
            if ((compress is not None) and (len(n) > 1)):
                pos = file.tell()
                if (pos <= 16383):
                    compress[n] = pos
            l = len(label)
            file.write(struct.pack('!B', l))
            if (l > 0):
                file.write(label)
    if want_return:
        return file.getvalue()
