예제 #1
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            username = request.authorization.username
            if is_bytes(username):
                username = username.decode("utf-8")

            password = request.authorization.password
            if is_bytes(password):
                password = password.decode("utf-8")

            user = User.by_credentials(username, password)

            request.user_id = user.id if user else None
            set_sentry_user({"id": request.user_id})

            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None
            set_sentry_user({"id": request.user_id})

            return valid, req
예제 #2
0
def normalize_whitespace(s):
    """Strip the string and replace all whitespace sequences and other
    non-printable characters with a single space."""

    assert is_bytes(s)

    return whitespace_re.sub(b" ", s.strip())
예제 #3
0
def sanitise_filename(name):
    assert is_string(name)

    # strip the parent directory name
    name = os.path.basename(name)

    # replace all non-ASCII or dangerous characters
    if is_bytes(name):
        name = re.sub(br"[^-_.a-zA-Z0-9]", "_", name)

        # convert to unicode string
        name = name.decode("ascii")
    else:
        name = re.sub(r"[^-_.a-zA-Z0-9]", "_", name)

    # dots at the beginning of a file name are "special", remove them
    name = name.lstrip(".")

    # normalise to lower case
    name = name.lower()

    # empty file names are illegal, replace
    if name == "":
        name = u"empty"
    return name
예제 #4
0
def sanitise_filename(name):
    assert is_string(name)

    # strip the parent directory name
    name = os.path.basename(name)

    # replace all non-ASCII or dangerous characters
    if is_bytes(name):
        name = re.sub(br"[^-_.a-zA-Z0-9]", "_", name)

        # convert to unicode string
        name = name.decode("ascii")
    else:
        name = re.sub(r"[^-_.a-zA-Z0-9]", "_", name)

    # dots at the beginning of a file name are "special", remove them
    name = name.lstrip(".")

    # normalise to lower case
    name = name.lower()

    # empty file names are illegal, replace
    if name == "":
        name = u"empty"
    return name
예제 #5
0
def normalize_whitespace(s):
    """Strip the string and replace all whitespace sequences and other
    non-printable characters with a single space."""

    assert is_bytes(s)

    return whitespace_re.sub(b' ', s.strip())
예제 #6
0
def import_alnum(s):
    """Import a byte string, convert to a unicode string,
    discarding all non-alphanumeric characters (ASCII only)."""

    assert is_bytes(s)

    s = non_alnum_re.sub(b"", s)
    return s.decode("ascii")
예제 #7
0
def import_ascii(s):
    """Import a byte string, convert to a unicode string, discarding all
    non-ASCII characters."""

    assert is_bytes(s)

    s = normalize_whitespace(s)
    return s.decode("ascii", "ignore")
예제 #8
0
def import_alnum(s):
    """Import a byte string, convert to a unicode string,
    discarding all non-alphanumeric characters (ASCII only)."""

    assert is_bytes(s)

    s = non_alnum_re.sub(b'', s)
    return s.decode('ascii')
예제 #9
0
def import_ascii(s):
    """Import a byte string, convert to a unicode string, discarding all
    non-ASCII characters."""

    assert is_bytes(s)

    s = normalize_whitespace(s)
    return s.decode('ascii', 'ignore')
예제 #10
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            username = request.authorization.username
            if is_bytes(username):
                username = username.decode('utf-8')

            password = request.authorization.password
            if is_bytes(password):
                password = password.decode('utf-8')

            user = User.by_credentials(username, password)

            request.user_id = user.id if user else None
            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None

            return valid, req
예제 #11
0
파일: user.py 프로젝트: yataOrg/skylines
    def _hash_password(cls, password, salt=None):
        if salt is None:
            salt = os.urandom(60)

        assert is_unicode(password)
        assert is_bytes(salt)

        salt_hash = sha256()
        salt_hash.update(salt)

        hash = sha256()
        hash.update((password + salt_hash.hexdigest()).encode("utf-8"))

        return str_to_unicode(salt_hash.hexdigest() + hash.hexdigest())
예제 #12
0
파일: user.py 프로젝트: Turbo87/skylines
    def _hash_password(cls, password, salt=None):
        if salt is None:
            salt = os.urandom(60)

        assert is_unicode(password)
        assert is_bytes(salt)

        salt_hash = sha256()
        salt_hash.update(salt)

        hash = sha256()
        hash.update((password + salt_hash.hexdigest()).encode('utf-8'))

        return str_to_unicode(salt_hash.hexdigest() + hash.hexdigest())
예제 #13
0
파일: igc.py 프로젝트: hess8/skylinesC
def read_igc_headers(f):
    """ Read IGC file headers from a file-like object, a list of strings or a
    file if the parameter is a path. """

    if is_string(f):
        try:
            f = open(f, "rb")
        except IOError:
            return None

    igc_headers = dict()

    for i, line in enumerate(f):
        assert is_bytes(line)

        if line.startswith(b"A"):
            length = len(line)

            if length >= 4:
                igc_headers["manufacturer_id"] = line[1:4].decode("ascii")

            if length >= 7:
                igc_headers["logger_id"] = parse_logger_id(line)

        if line.startswith(b"HFDTE"):
            igc_headers["date_utc"] = parse_date(line)

        if line.startswith(b"HFGTY"):
            igc_headers["model"] = parse_pattern(hfgty_re, line)

        if line.startswith(b"HFGID"):
            igc_headers["reg"] = parse_pattern(hfgid_re, line)

        if line.startswith(b"HFCID"):
            igc_headers["cid"] = parse_pattern(hfcid_re, line)

        # don't read more than 100 lines, that should be enough
        if i > 100:
            break

    return igc_headers
예제 #14
0
def read_igc_headers(f):
    """ Read IGC file headers from a file-like object, a list of strings or a
    file if the parameter is a path. """

    if is_string(f):
        try:
            f = open(f, "rb")
        except IOError:
            return None

    igc_headers = dict()

    for i, line in enumerate(f):
        assert is_bytes(line)

        if line.startswith(b"A"):
            length = len(line)

            if length >= 4:
                igc_headers["manufacturer_id"] = line[1:4].decode("ascii")

            if length >= 7:
                igc_headers["logger_id"] = parse_logger_id(line)

        if line.startswith(b"HFDTE"):
            igc_headers["date_utc"] = parse_date(line)

        if line.startswith(b"HFGTY"):
            igc_headers["model"] = parse_pattern(hfgty_re, line)

        if line.startswith(b"HFGID"):
            igc_headers["reg"] = parse_pattern(hfgid_re, line)

        if line.startswith(b"HFCID"):
            igc_headers["cid"] = parse_pattern(hfcid_re, line)

        # don't read more than 100 lines, that should be enough
        if i > 100:
            break

    return igc_headers
예제 #15
0
def read_igc_headers(f):
    """ Read IGC file headers from a file-like object, a list of strings or a
    file if the parameter is a path. """

    if is_string(f):
        try:
            f = open(f, 'rb')
        except IOError:
            return None

    igc_headers = dict()

    for i, line in enumerate(f):
        assert is_bytes(line)

        if line.startswith(b'A'):
            length = len(line)

            if length >= 4:
                igc_headers['manufacturer_id'] = line[1:4].decode('ascii')

            if length >= 7:
                igc_headers['logger_id'] = parse_logger_id(line)

        if line.startswith(b'HFDTE'):
            igc_headers['date_utc'] = parse_date(line)

        if line.startswith(b'HFGTY'):
            igc_headers['model'] = parse_pattern(hfgty_re, line)

        if line.startswith(b'HFGID'):
            igc_headers['reg'] = parse_pattern(hfgid_re, line)

        if line.startswith(b'HFCID'):
            igc_headers['cid'] = parse_pattern(hfcid_re, line)

        # don't read more than 100 lines, that should be enough
        if i > 100:
            break

    return igc_headers