Get homoglyphs for text, convert text to ASCII.
Project description
# Homoglyphs
Homoglyphs -- python library for getting [homoglyphs](https://en.wikipedia.org/wiki/Homoglyph) and converting to ASCII.
## Features
It's like [confusable_homoglyphs](https://github.com/vhf/confusable_homoglyphs) but with some features:
* Load only needed alphabet to memory.
* Work as quick as possible.
* Converting to ASCII.
* More configurable.
* More stable.
## Usage
```python
from homoglyphs import Homoglyphs, STRATEGY_LOAD, STRATEGY_IGNORE, STRATEGY_REMOVE
# detect category
Homoglyphs.detect_category('s')
# 'LATIN'
Homoglyphs.detect_category('ั')
# 'CYRILLIC'
Homoglyphs.detect_category('.')
# 'COMMON'
# get latin combinations (by default initiated only latin alphabet)
Homoglyphs().get_combinations('q')
# ['q', '๐ช', '๐', '๐', '๐', '๐บ', '๐ฎ', '๐ข', '๐', '๐', '๐พ', '๐ฒ', '๐ฆ', '๐']
# load alphabet on init by categories
Homoglyphs(categories=('LATIN', 'COMMON', 'CYRILLIC')).get_combinations('ะณั')
# ['rั', 'ะณั', '๊ญั', '๊ญั', '๐ซั', '๐ั', '๐ั', '๐ั', '๐ปั', '๐ฏั', '๐ฃั', '๐ั', '๐ั', '๐ฟั', '๐ณั', '๐งั', '๐ั']
# load alphabet by demand
Homoglyphs(strategy=STRATEGY_LOAD).get_combinations('ะณั')
# ['rั', 'ะณั', '๊ญั', '๊ญั', '๐ซั', '๐ั', '๐ั', '๐ั', '๐ปั', '๐ฏั', '๐ฃั', '๐ั', '๐ั', '๐ฟั', '๐ณั', '๐งั', '๐ั']
# convert to ASCII
Homoglyphs(strategy=STRATEGY_LOAD).to_ascii('ัะตัั')
# ['tect']
Homoglyphs(strategy=STRATEGY_LOAD).to_ascii('ะฅะ 123.') # this is cyrillic "ั " and "ั"
# ['XP123.', 'XPI23.', 'XPl23.']
# string with chars which can't be converted by default will be ignored
Homoglyphs(strategy=STRATEGY_LOAD).to_ascii('ะปะพะป')
# []
# you can set strategy for removing not converted non-ASCII chars from result
Homoglyphs(strategy=STRATEGY_LOAD, ascii_strategy=STRATEGY_REMOVE).to_ascii('ะปะพะป')
# ['o']
```
Homoglyphs -- python library for getting [homoglyphs](https://en.wikipedia.org/wiki/Homoglyph) and converting to ASCII.
## Features
It's like [confusable_homoglyphs](https://github.com/vhf/confusable_homoglyphs) but with some features:
* Load only needed alphabet to memory.
* Work as quick as possible.
* Converting to ASCII.
* More configurable.
* More stable.
## Usage
```python
from homoglyphs import Homoglyphs, STRATEGY_LOAD, STRATEGY_IGNORE, STRATEGY_REMOVE
# detect category
Homoglyphs.detect_category('s')
# 'LATIN'
Homoglyphs.detect_category('ั')
# 'CYRILLIC'
Homoglyphs.detect_category('.')
# 'COMMON'
# get latin combinations (by default initiated only latin alphabet)
Homoglyphs().get_combinations('q')
# ['q', '๐ช', '๐', '๐', '๐', '๐บ', '๐ฎ', '๐ข', '๐', '๐', '๐พ', '๐ฒ', '๐ฆ', '๐']
# load alphabet on init by categories
Homoglyphs(categories=('LATIN', 'COMMON', 'CYRILLIC')).get_combinations('ะณั')
# ['rั', 'ะณั', '๊ญั', '๊ญั', '๐ซั', '๐ั', '๐ั', '๐ั', '๐ปั', '๐ฏั', '๐ฃั', '๐ั', '๐ั', '๐ฟั', '๐ณั', '๐งั', '๐ั']
# load alphabet by demand
Homoglyphs(strategy=STRATEGY_LOAD).get_combinations('ะณั')
# ['rั', 'ะณั', '๊ญั', '๊ญั', '๐ซั', '๐ั', '๐ั', '๐ั', '๐ปั', '๐ฏั', '๐ฃั', '๐ั', '๐ั', '๐ฟั', '๐ณั', '๐งั', '๐ั']
# convert to ASCII
Homoglyphs(strategy=STRATEGY_LOAD).to_ascii('ัะตัั')
# ['tect']
Homoglyphs(strategy=STRATEGY_LOAD).to_ascii('ะฅะ 123.') # this is cyrillic "ั " and "ั"
# ['XP123.', 'XPI23.', 'XPl23.']
# string with chars which can't be converted by default will be ignored
Homoglyphs(strategy=STRATEGY_LOAD).to_ascii('ะปะพะป')
# []
# you can set strategy for removing not converted non-ASCII chars from result
Homoglyphs(strategy=STRATEGY_LOAD, ascii_strategy=STRATEGY_REMOVE).to_ascii('ะปะพะป')
# ['o']
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
homoglyphs-1.0.0.tar.gz
(7.0 kB
view details)
File details
Details for the file homoglyphs-1.0.0.tar.gz
.
File metadata
- Download URL: homoglyphs-1.0.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85c48d6752f339a63eac378cf5a001f3407e663086c2670ddef06dd368504a48 |
|
MD5 | c686ca9a451af7a756e8cf29817ef58e |
|
BLAKE2b-256 | f3eea942500eaa20405e3007d8308c10ea14a33d852978bb5abcd17e89e23efc |