File: conversion.py

package info (click to toggle)
python-crownstone-cloud 1.4.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: python: 1,126; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 570 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Contains functions that convert a parameter into something else."""
from __future__ import annotations

import hashlib
import json
from typing import Any
from urllib.parse import quote


def password_to_hash(password: str) -> str | None:
    """Generate a sha1 password from string."""
    if password is None:
        return None
    pw_hash = hashlib.sha1(password.encode("utf-8"))
    return pw_hash.hexdigest()


def quote_json(_json: dict[str, Any]) -> str:
    """Convert JSON to HTML quote."""
    stringified = json.dumps(_json)
    return quote(stringified)