'Sets the content of a port\'s screenshot.'

def setscreenshot(self, host, port, data, protocol='tcp', archive=False, overwrite=False):

    try:
        port = [p for p in host.get('ports', []) if ((p['port'] == port) and (p['protocol'] == protocol))][0]
    except IndexError:
        raise KeyError(('Port    %s/%d    does    not    exist' % (protocol, port)))
    if (('screenshot' in port) and (not overwrite)):
        return
    port['screenshot'] = 'field'
    trim_result = utils.trim_image(data)
    if (trim_result is False):
        return
    elif (trim_result is not True):
        data = trim_result
    port['screendata'] = bson.Binary(data)
    screenwords = utils.screenwords(data)
    if (screenwords is not None):
        port['screenwords'] = screenwords
    self.db[(self.colname_oldhosts if archive else self.colname_hosts)].update({'_id': host['_id']}, {'$set': {'ports': host['ports']}})
