15.2.119. camcops_server.cc_modules.cc_proquint

camcops_server/cc_modules/cc_proquint.py


Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.


Convert integers into Pronounceable Quintuplets (proquints) https://arxiv.org/html/0901.4016

Based on https://github.com/dsw/proquint, which has the following licence:

–8<—————————————————————————

Copyright (c) 2009 Daniel S. Wilkerson All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Daniel S. Wilkerson nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

–8<—————————————————————————

exception camcops_server.cc_modules.cc_proquint.InvalidProquintException[source]
camcops_server.cc_modules.cc_proquint.int_from_proquint(proquint: str) → int[source]

Convert proquint string into integer.

Parameters

proquint – string to decode

Returns

converted integer value

camcops_server.cc_modules.cc_proquint.proquint_from_int(int_value: int, size_in_bits: int) → str[source]

Convert integer value into proquint

>>> proquint_from_int(0x493b05ee, 32)
hohur-bilov

0x493b05ee in binary is:
0100 1001 0011 1011 - 0000 0101 1110 1110

grouped into alternating 4 and 2 bit values:

cons vo cons vo cons - cons vo cons vo cons
0100 10 0100 11 1011 - 0000 01 0111 10 1110

   h  o    h  u    r -    b  i    l  o    v
Parameters
  • int_value – integer value to encode

  • size_in_bits – size of integer in bits (must be a multiple of 16)

Returns

proquint string identifier

camcops_server.cc_modules.cc_proquint.proquint_from_uuid(uuid_obj: uuid.UUID) → str[source]

Convert UUID to proquint (via the UUID’s 128-bit integer representation).

camcops_server.cc_modules.cc_proquint.uuid_from_proquint(proquint: str) → uuid.UUID[source]

Convert proquint to UUID.