This file is indexed.

/usr/share/pyshared/pyxid/serial_wrapper.py is in python-pyxid 1.0-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
from serial import serial_for_url, Serial
from serial.serialutil import SerialException
import os, sys

class SerialPort(object):
    def __init__(self, serial_port, baud_rate=115200):
        if sys.platform == 'darwin':
            self.impl = MacSerialPort(serial_port, baud_rate)
        elif sys.platform == 'linux2':
            self.impl = LinuxSerialPort(serial_port, baud_rate)
        else:
            self.impl = GenericSerialPort(serial_port, baud_rate)

    def __getattr__(self, attr):
        return getattr(self.impl, attr)


    @staticmethod
    def available_ports():
        if sys.platform == 'darwin':
            return MacSerialPort.available_ports()
        elif sys.platform == 'linux2':
            return LinuxSerialPort.available_ports()
        else:
            return GenericSerialPort.available_ports()


class LinuxSerialPort(object):
    """
    USB-serial devices on Linux show up as /dev/ttyUSB?

    pySerial expects /dev/tty? (no USB).
    """
    def __init__(self, serial_port, baud_rate=115200):
        self.serial_port = serial_port
        self.serial_port.setBaudrate(baud_rate)


    def __getattr__(self, attr):
        return getattr(self.serial_port, attr)


    @staticmethod
    def available_ports():
        usb_serial_ports = filter(
            (lambda x: x.startswith('ttyUSB')),
            os.listdir('/dev'))

        ports = []
        for p in usb_serial_ports:
            ports.append(serial_for_url('/dev/'+p, do_not_open=True))

        return ports


class GenericSerialPort(object):
    def __init__(self, serial_port, baud_rate=115200):
        self.serial_port = serial_port
        self.serail_port.setBaudrate(baud_rate)

    @staticmethod
    def available_ports():
        """
        Scans COM1 through COM255 for available serial ports

        returns a list of available ports
        """
        ports = []

        for i in range(256):
            try:
                p = Serial(i)
                p.close()
                ports.append(p)
            except SerialException:
                pass

        return ports


    def __getattr__(self, attr):
        """
        forward calls to the internal serial.Serial instance
        """
        return getattr(self.serial_port, attr)


class MacSerialPort(object):
    """
    USB-Serial ports on Mac OS show up as /dev/cu.usbserial-*

    pySerial expects them to be /dev/cuad*
    """
    def __init__(self, serial_port, baud_rate=115200):
        self.serial_port = serial_port
        self.serial_port.setBaudrate(baud_rate)

    @staticmethod
    def available_ports():
        usb_serial_ports = filter(
            (lambda x : x.startswith('cu.usbserial')),
            os.listdir('/dev'))

        ports = []
        for p in usb_serial_ports:
            ports.append(serial_for_url('/dev/'+p, do_not_open=True))

        return ports


    def __getattr__(self, attr):
        """
        forward calls to the internal serial.Serial instance
        """
        return getattr(self.serial_port, attr)