xpra icon
Bug tracker and wiki

Ticket #2100: novideo-content-type.patch

File novideo-content-type.patch, 4.8 KB (added by Nathan Hallquist, 22 months ago)
  • xpra/server/window/content_guesser.py

     
    1616log = Logger("window", "util")
    1717
    1818DEFAULT_CONTENT_TYPE = os.environ.get("XPRA_DEFAULT_CONTENT_TYPE", "")
     19CONTENT_TYPE_DEFS = os.environ.get("XPRA_CONTENT_TYPE_DEFS","")
    1920
    2021
    2122def get_proc_cmdline(pid):
     
    4647        load_content_type_dir(content_type_dir)
    4748        for d in get_user_conf_dirs():
    4849            load_content_type_dir(d)
     50        for a in CONTENT_TYPE_DEFS.split(","):
     51            if not process_content_type_entry(a):
     52                log.warn("Processing entry from environment variable")
    4953    return content_type_defs
    5054
    5155def load_content_type_dir(d):
     
    6468                    log.error(" %s", e)
    6569
    6670def load_content_type_file(ct_file):
    67     global content_type_defs
    6871    if PYTHON2:
    6972        mode = "rU"
    7073    else:
     
    7275    with open(ct_file, mode) as f:
    7376        l = 0
    7477        for line in f:
     78            if not process_content_type_entry(line):
     79                log.warn("Line %i of %s", l, ct_file)
    7580            l += 1
    76             line = line.rstrip("\n\r")
    77             if line.startswith("#") or not (line.strip()):
    78                 continue
    79             parts = line.rsplit("=", 1)
    80             #ie: "title:helloworld=text   #some comments here" -> "title:helloworld", "text   #some comments here"
    81             if len(parts)!=2:
    82                 log.warn("Warning: invalid content-type definition")
    83                 log.warn(" found in '%s' at line %i", line, l)
    84                 log.warn(" '%s' is missing a '='", line)
    85                 continue
    86             match, content_type = parts
    87             parts = match.split(":", 1)
    88             #ie: "title:helloworld" -> "title", "helloworld"
    89             if len(parts)!=2:
    90                 log.warn("Warning: invalid content-type definition")
    91                 log.warn(" match string '%s' is missing a ':'", match)
    92                 continue
    93             #ignore comments:
    94             #"text    #some comments here" > "text"
    95             content_type = content_type.split(":")[0].strip()
    96             prop_name, regex = parts
    97             try:
    98                 c = re.compile(regex)
    99                 content_type_defs.setdefault(prop_name, OrderedDict())[c]=(regex, content_type)
    100                 log("%16s matching '%s' is %s", prop_name, regex, content_type)
    101             except Exception as e:
    102                 log.warn("Warning: invalid regular expression")
    103                 log.warn(" match string '%s':", regex)
    104                 log.warn(" %s", e)
    105                 continue
    10681
     82def process_content_type_entry(entry):
     83    global content_type_defs
     84    entry = entry.rstrip("\n\r")
     85    if entry.startswith("#") or not (entry.strip()):
     86        return True
     87    parts = entry.rsplit("=", 1)
     88    #ie: "title:helloworld=text   #some comments here" -> "title:helloworld", "text   #some comments here"
     89    if len(parts)!=2:
     90        log.warn("Warning: invalid content-type definition")
     91        log.warn(" found in '%s'", entry)
     92        log.warn(" '%s' is missing a '='", entry)
     93        return False
     94    match, content_type = parts
     95    parts = match.split(":", 1)
     96    #ie: "title:helloworld" -> "title", "helloworld"
     97    if len(parts)!=2:
     98        log.warn("Warning: invalid content-type definition")
     99        log.warn(" match string '%s' is missing a ':'", match)
     100        return False
     101    #ignore comments:
     102    #"text    #some comments here" > "text"
     103    content_type = content_type.split(":")[0].strip()
     104    prop_name, regex = parts
     105    try:
     106        c = re.compile(regex)
     107        content_type_defs.setdefault(prop_name, OrderedDict())[c]=(regex, content_type)
     108        log("%16s matching '%s' is %s", prop_name, regex, content_type)
     109    except Exception as e:
     110        log.warn("Warning: invalid regular expression")
     111        log.warn(" match string '%s':", regex)
     112        log.warn(" %s", e)
     113        return False
     114    return True
    107115
     116
    108117def get_content_type_properties():
    109118    """ returns the list of window properties which can be used
    110119        to guess the content-type.
  • xpra/server/window/window_video_source.py

     
    423423        cwh = wh & self.height_mask
    424424        video_hint = self.content_type=="video"
    425425        text_hint = self.content_type=="text"
     426        novideo_hint = self.content_type=="novideo"
     427        if novideo_hint:
     428            return nonvideo(info="lossless content-type")
    426429
    427430        rgbmax = self._rgb_auto_threshold
    428431        videomin = cww*cwh // (1+video_hint*2)