Skip to content

Commit

Permalink
Removing ctypes dependency. (#354)
Browse files Browse the repository at this point in the history
* Removing ctypes dependency.

* Update changelog

Co-authored-by: Romain Casati <romain.casati@webati.fr>
Co-authored-by: Steven Loria <sloria1@gmail.com>
  • Loading branch information
3 people committed Feb 18, 2021
1 parent e7cf1b4 commit 52c1168
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -31,3 +31,4 @@ Contributors (chronological)
- Jamie Moschella `@jammmo <https://github.com/jammmo>`_
- Roman Korolev `@roman-y-korolev <https://github.com/roman-y-korolev>`_
- Ram Rachum `@cool-RR <https://github.com/cool-RR>`_
- Romain Casati `@casatir <https://github.com/casatir>`_
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -9,6 +9,10 @@ Features:
- Performance improvement: Use ``chain.from_iterable`` in ``_text.py``
to improve runtime and memory usage (:pr:`333`). Thanks :user:`cool-RR` for the PR.

Other changes:

- Remove usage of `ctypes` (:pr:`354`). Thanks :user:`casatir`.

0.16.0 (2020-04-26)
-------------------

Expand Down
13 changes: 10 additions & 3 deletions textblob/translate.py
Expand Up @@ -8,7 +8,6 @@
from __future__ import absolute_import

import codecs
import ctypes
import json
import re

Expand Down Expand Up @@ -106,6 +105,14 @@ def _calculate_tk(source):
# Source: https://github.com/soimort/translate-shell/issues/94#issuecomment-165433715
# Source: http://www.liuxiatool.com/t.php

def c_int(x, nbits=32):
""" C cast to int32, int16, int8... """
return (x & ((1 << (nbits - 1)) - 1)) - (x & (1 << (nbits - 1)))

def c_uint(x, nbits=32):
""" C cast to uint32, uint16, uint8... """
return x & ((1 << nbits) - 1)

tkk = [406398, 561666268 + 1526272306]
b = tkk[0]

Expand All @@ -118,10 +125,10 @@ def RL(a, b):
for c in range(0, len(b) - 2, 3):
d = b[c + 2]
d = ord(d) - 87 if d >= 'a' else int(d)
xa = ctypes.c_uint32(a).value
xa = c_uint(a)
d = xa >> d if b[c + 1] == '+' else xa << d
a = a + d & 4294967295 if b[c] == '+' else a ^ d
return ctypes.c_int32(a).value
return c_int(a)

a = b

Expand Down

0 comments on commit 52c1168

Please sign in to comment.