コード例 #1
0
def encode(name, password):
    if is_unicode(name):
        name = name.encode('utf-8')

    if is_unicode(password):
        password = password.encode('utf-8')

    return u'Basic ' + b64encode(name + b':' + password).decode('ascii')
コード例 #2
0
ファイル: basic_auth.py プロジェクト: yataOrg/skylines
def encode(name, password):
    if is_unicode(name):
        name = name.encode("utf-8")

    if is_unicode(password):
        password = password.encode("utf-8")

    return u"Basic " + b64encode(name + b":" + password).decode("ascii")
コード例 #3
0
def test_hash_password():
    hash = User._hash_password(u"secret123", salt=b"abcdef")
    assert (
        hash
        == "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
    )
    assert is_unicode(hash)
コード例 #4
0
def test_hash_password():
    hash = User._hash_password(u"secret123", salt=b"abcdef")
    assert (
        hash
        == "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
    )
    assert is_unicode(hash)
コード例 #5
0
ファイル: user.py プロジェクト: vdrok/skylines
    def _hash_password(cls, password):
        assert is_unicode(password)

        salt = sha256()
        salt.update(os.urandom(60))

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

        return salt.hexdigest() + hash.hexdigest()
コード例 #6
0
ファイル: search.py プロジェクト: RBE-Avionik/skylines
def text_to_tokens(search_text):
    assert is_unicode(search_text)

    try:
        if sys.version_info[0] == 2:
            return [str.decode('utf8') for str in shlex.split(search_text.encode('utf8'))]
        else:
            return shlex.split(search_text)
    except ValueError:
        return search_text.split(' ')
コード例 #7
0
def text_to_tokens(search_text):
    assert is_unicode(search_text)

    try:
        if sys.version_info[0] == 2:
            return [
                str.decode("utf8")
                for str in shlex.split(search_text.encode("utf8"))
            ]
        else:
            return shlex.split(search_text)
    except ValueError:
        return search_text.split(" ")
コード例 #8
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())
コード例 #9
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())
コード例 #10
0
def test_query_to_sql(db_session):
    input = ExampleTable(name="John Doe", uni=u"Jane and John Doe")
    db_session.add(input)
    db_session.commit()

    query = (db_session.query(ExampleTable).filter_by(id=input.id).order_by(
        ExampleTable.name))

    sql_text = sql.query_to_sql(query)

    assert is_unicode(sql_text)
    assert (
        sql_text == "SELECT ilike_test.id, ilike_test.name, ilike_test.uni \n"
        + "FROM ilike_test \n" +
        "WHERE ilike_test.id = {} ORDER BY ilike_test.name".format(input.id))
コード例 #11
0
def query_to_sql(query):
    """
    Convert a sqlalchemy query to raw SQL.
    https://stackoverflow.com/questions/4617291/how-do-i-get-a-raw-compiled-sql-query-from-a-sqlalchemy-expression
    """

    from psycopg2.extensions import adapt as sqlescape

    statement = query.statement.compile(dialect=query.session.bind.dialect)
    dialect = query.session.bind.dialect

    enc = dialect.encoding
    params = {}

    for k, v in statement.params.items():
        if is_unicode(v):
            v = v.encode(enc)
        params[k] = sqlescape(v)

    return statement.string % params
コード例 #12
0
ファイル: test_sql.py プロジェクト: skylines-project/skylines
def test_query_to_sql(db_session):
    input = ExampleTable(name="John Doe", uni=u"Jane and John Doe")
    db_session.add(input)
    db_session.commit()

    query = (
        db_session.query(ExampleTable)
        .filter_by(id=input.id)
        .order_by(ExampleTable.name)
    )

    sql_text = sql.query_to_sql(query)

    assert is_unicode(sql_text)
    assert (
        sql_text
        == "SELECT ilike_test.id, ilike_test.name, ilike_test.uni \n"
        + "FROM ilike_test \n"
        + "WHERE ilike_test.id = {} ORDER BY ilike_test.name".format(input.id)
    )
コード例 #13
0
ファイル: test_sql.py プロジェクト: skylines-project/skylines
def test_query_to_sql2(db_session):
    from geoalchemy2.shape import from_shape
    from sqlalchemy.sql import literal_column
    from shapely.geometry import LineString

    linestring = LineString([(0, 0), (1, 2), (3, 4)])
    locations = from_shape(linestring, srid=4326)

    one = literal_column("1 as flight_id")
    query = db_session.query(locations.label("flight_geometry"), one)

    sql_text = sql.query_to_sql(query)

    assert is_unicode(sql_text)
    assert (
        sql_text
        == u"SELECT ST_GeomFromWKB('\\001\\002\\000\\000\\000\\003\\000\\000\\000\\000\\000\\000\\000"
        + "\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\360?\\000"
        + "\\000\\000\\000\\000\\000\\000@\\000\\000\\000\\000\\000\\000\\010@\\000\\000\\000\\000\\000\\000"
        + "\\020@'::bytea, 4326) AS flight_geometry, 1 as flight_id"
    )
コード例 #14
0
ファイル: upload.py プロジェクト: yataOrg/skylines
def iterate_upload_files(upload):
    if is_unicode(upload):
        # the Chromium browser sends an empty string if no file is selected
        if not upload:
            return

        # some Android versions send the IGC file as a string, not as
        # a file
        with TemporaryFile() as f:
            f.write(upload.encode("UTF-8"))
            f.seek(0)
            yield "direct.igc", f

    elif isinstance(upload, list):
        for x in upload:
            for name, f in iterate_upload_files(x):
                yield name, f

    else:
        for x in iterate_files(upload.filename, upload):
            yield x
コード例 #15
0
ファイル: upload.py プロジェクト: skylines-project/skylines
def iterate_upload_files(upload):
    if is_unicode(upload):
        # the Chromium browser sends an empty string if no file is selected
        if not upload:
            return

        # some Android versions send the IGC file as a string, not as
        # a file
        with TemporaryFile() as f:
            f.write(upload.encode("UTF-8"))
            f.seek(0)
            yield "direct.igc", f

    elif isinstance(upload, list):
        for x in upload:
            for name, f in iterate_upload_files(x):
                yield name, f

    else:
        for x in iterate_files(upload.filename, upload):
            yield x
コード例 #16
0
def test_query_to_sql2(db_session):
    from geoalchemy2.shape import from_shape
    from sqlalchemy.sql import literal_column
    from shapely.geometry import LineString

    linestring = LineString([(0, 0), (1, 2), (3, 4)])
    locations = from_shape(linestring, srid=4326)

    one = literal_column("1 as flight_id")
    query = db_session.query(locations.label("flight_geometry"), one)

    sql_text = sql.query_to_sql(query)

    assert is_unicode(sql_text)
    assert (
        sql_text ==
        u"SELECT ST_GeomFromWKB('\\001\\002\\000\\000\\000\\003\\000\\000\\000\\000\\000\\000\\000"
        +
        "\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\360?\\000"
        +
        "\\000\\000\\000\\000\\000\\000@\\000\\000\\000\\000\\000\\000\\010@\\000\\000\\000\\000\\000\\000"
        + "\\020@'::bytea, 4326) AS flight_geometry, 1 as flight_id")
コード例 #17
0
ファイル: user.py プロジェクト: Turbo87/skylines
    def validate_password(self, password):
        """
        Check the password against existing credentials.

        :param password: the password that was provided by the user to
            try and authenticate. This is the clear text version that we will
            need to match against the hashed one in the database.
        :type password: unicode object.
        :return: Whether the password is valid.
        :rtype: bool
        """

        assert is_unicode(password)

        # Make sure accounts without a password can't log in
        if not self.password or not password:
            return False

        hash = sha256()
        hash.update((password + self.password[:64]).encode('utf-8'))

        return self.password[64:] == hash.hexdigest()
コード例 #18
0
ファイル: user.py プロジェクト: yataOrg/skylines
    def validate_password(self, password):
        """
        Check the password against existing credentials.

        :param password: the password that was provided by the user to
            try and authenticate. This is the clear text version that we will
            need to match against the hashed one in the database.
        :type password: unicode object.
        :return: Whether the password is valid.
        :rtype: bool
        """

        assert is_unicode(password)

        # Make sure accounts without a password can't log in
        if not self.password or not password:
            return False

        hash = sha256()
        hash.update((password + self.password[:64]).encode("utf-8"))

        return self.password[64:] == hash.hexdigest()
コード例 #19
0
def test_unicode():
    result = encode(u'foo', u'bar')
    assert result == u'Basic Zm9vOmJhcg=='
    assert is_unicode(result)
コード例 #20
0
def test_bytes():
    result = encode('foo', 'bar')
    assert result == u'Basic Zm9vOmJhcg=='
    assert is_unicode(result)
コード例 #21
0
ファイル: test_basic_auth.py プロジェクト: yataOrg/skylines
def test_bytes():
    result = encode("foo", "bar")
    assert result == u"Basic Zm9vOmJhcg=="
    assert is_unicode(result)
コード例 #22
0
def test_sanitise_filename(input, expected):
    output = files.sanitise_filename(input)

    assert is_unicode(output)
    assert output == expected
コード例 #23
0
ファイル: test_basic_auth.py プロジェクト: yataOrg/skylines
def test_unicode():
    result = encode(u"foo", u"bar")
    assert result == u"Basic Zm9vOmJhcg=="
    assert is_unicode(result)