Пример #1
0
def get_display(display):
    # Use $DISPLAY if display isn't provided
    if display is None:
        display = os.environ.get('DISPLAY', '')

    re_list = [(DISPLAY_RE, {})]

    if 'darwin' in SUPPORTED_PROTOCOLS:
        re_list.insert(0, (DARWIN_DISPLAY_RE, {'protocol': 'darwin'}))

    for re, defaults in re_list:
        m = re.match(display)
        if m is not None:
            protocol, host, dno, screen = [
                m.groupdict().get(field, defaults.get(field))
                for field in ('proto', 'host', 'dno', 'screen')
            ]
            break
    else:
        raise error.DisplayNameError(display)

    if protocol == 'tcp' and not host:
        # Host is mandatory when protocol is TCP.
        raise error.DisplayNameError(display)

    dno = int(dno)
    if screen:
        screen = int(screen)
    else:
        screen = 0

    return display, protocol, host, dno, screen
Пример #2
0
def get_display(display):
    # Use $DISPLAY if display isn't provided
    if display is None:
        display = os.environ.get('DISPLAY', '')

    m = display_re.match(display)
    if not m:
        raise error.DisplayNameError(display)

    name = display
    protocol, host, dno, screen = m.group('proto', 'host', 'dno', 'screen')
    if protocol == 'tcp':
        # Host is mandatory when protocol is TCP.
        if not host:
            raise error.DisplayNameError(display)
    elif protocol == 'unix':
        # Clear host to force Unix socket connection.
        host = ''
    else:
        # Special case: `unix:0.0` is equivalent to `:0.0`.
        if host == 'unix':
            host = ''
    dno = int(dno)
    if screen:
        screen = int(screen)
    else:
        screen = 0

    return name, host, dno, screen
Пример #3
0
def get_display(display):
    # Use dummy display if none is set.  We really should
    # check DECW$DISPLAY instead, but that has to wait

    if display is None:
        return ':0.0', 'localhost', 0, 0

    m = display_re.match(display)
    if not m:
        raise error.DisplayNameError(display)

    name = display

    # Always return a host, since we don't have AF_UNIX sockets
    host = m.group(1)
    if not host:
        host = 'localhost'

    dno = int(m.group(2))
    screen = m.group(4)
    if screen:
        screen = int(screen)
    else:
        screen = 0

    return name, host, dno, screen
Пример #4
0
def get_display(display):
    # Use $DISPLAY if display isn't provided
    if display is None:
        display = os.environ.get('DISPLAY', '')

    m = display_re.match(display)
    if not m:
        raise error.DisplayNameError(display)

    name = display
    protocol, host, dno, screen = m.group('proto', 'host', 'dno', 'screen')
    if protocol == 'tcp' and not host:
        # Host is mandatory when protocol is TCP.
        raise error.DisplayNameError(display)
    dno = int(dno)
    if screen:
        screen = int(screen)
    else:
        screen = 0

    return name, protocol, host, dno, screen
Пример #5
0
def get_display(display):
    # Use $DISPLAY if display isn't provided
    if display is None:
        display = os.environ.get('DISPLAY', '')

    m = display_re.match(display)
    if not m:
        raise error.DisplayNameError(display)

    name = display
    host = m.group(1)
    dno = int(m.group(2))
    screen = m.group(4)
    if screen:
        screen = int(screen)
    else:
        screen = 0

    return name, host, dno, screen