CONFUSABLE_HOMOGLYPHS(1)
π CONFUSABLE_HOMOGLYPHS(1) π
okay bestie, welcome to confusable_homoglyphs(1) β the manual page that's gonna save you from getting catfished by a lookalike character. yes, really. this is the whole documentation, and we're gonna get through it together. grab a snack. π
β¨ NAME β¨
confusable_homoglyphs β the confusable_homoglyphs documentation, babes.
Contents:
π CONFUSABLE_HOMOGLYPHS [DOC] π
so like, plot twist: this project has been adopted from the original confusable_homoglyphs by Victor Felder. iconic of them, no cap. π
now. a homoglyph is one of two or more graphemes, characters, or glyphs with shapes that appear identical or very similar β wikipedia:Homoglyph. literally twins but make it unicode. π
Unicode homoglyphs can be a nuisance on the web. Your most popular client, AlaskaJazz, might be upset to be impersonated by a trickster who deliberately chose the username ΞlaskaJazz. the AUDACITY. π
AlaskaJazzis single script: only Latin characters.ΞlaskaJazzis mixed-script: the first character is a greek letter.
You might also want to avoid people being tricked into entering their password on www.microsΠΎft.com or www.faΟ²ebook.com instead of www.microsoft.com or www.facebook.com. like, do NOT let them do that to you. π¨ Here is a utility to play with these confusable homoglyphs.
Not all mixed-script strings have to be ruled out though β you could only exclude mixed-script strings containing characters that might be confused with a character from some unicode blocks of your choosing. selective toxicity, we love her. π
AlloandΟΟΟare fine: single script.AlloΞis fine when our preferred script alias is βlatinβ: mixed script, butΞis not confusable.AlloΟis dangerous: mixed script andΟcould be confused withp.
This library is compatible with Python 3. slay. πβ¨
π¦ API documentation π¦
π Is the data up to date? π
Yep. πβοΈ
The unicode blocks aliases and names for each character are extracted from this file provided by the unicode consortium.
The matrix of which character can be confused with which other characters is built using this file provided by the unicode consortium.
This data is stored in two JSON files: categories.json and confusables.json. If you delete them, they will both be recreated by downloading and parsing the two abovementioned files and stored as JSON files again. self-healing behavior, honestly? obsessed. πΈ
π INSTALLATION π
If available, install an appropriate package from your distribution:
Otherwise you can install from PyPi:
at the command line:
$ easy_install confusable_homoglyphs
or, if you have virtualenvwrapper installed:
$ mkvirtualenv confusable_homoglyphs
$ pip install confusable_homoglyphs
β USAGE β
To use confusable_homoglyphs in a project:
pip install confusable_homoglyphs
import confusable_homoglyphs
To update the data files, you first need to install the βcliβ bundle, then run the βupdateβ command:
pip install confusable_homoglyphs[cli]
confusable_homoglyphs update
bestie we are SO not done yet β more of this page is coming. stay tuned. π«Ά
β¨ API DOCUMENTATION β¨
π¦ confusable_homoglyphs package
β¨ Submodules
π confusable_homoglyphs.categories module
confusable_homoglyphs.categories.alias(chr)
Ok so like, this function? Itβs giving script block alias retrieval for a unicode character. You hand it a character, it hands you the alias. Obsessed. π
>>> categories.alias('A')
'LATIN'
>>> categories.alias('Ο')
'GREEK'
>>> categories.alias('-')
'COMMON'
Parameters
chr(str) β A unicode character
Returns β The script block alias.
Return type β str
confusable_homoglyphs.categories.aliases_categories(chr)
This one is highkey a two-for-one: it gets you the script block alias and the unicode category for a unicode character. Iconic. β¨
>>> categories.aliases_categories('A')
('LATIN', 'L')
>>> categories.aliases_categories('Ο')
('GREEK', 'L')
>>> categories.aliases_categories('-')
('COMMON', 'Pd')
Parameters
chr(str) β A unicode character
Returns β The script block alias and unicode category for a unicode character.
Return type β (str, str)
confusable_homoglyphs.categories.category(chr)
Bestie, this is the unicode category plug. Give it a character, it tells you the category. No cap. π
>>> categories.category('A')
'L'
>>> categories.category('Ο')
'L'
>>> categories.category('-')
'Pd'
Parameters
chr(str) β A unicode character
Returns β The unicode category for a unicode character.
Return type β str
confusable_homoglyphs.categories.unique_aliases(string)
This one collects all the unique script block aliases used in a unicode string. Like a little alias detective. π΅οΈββοΈ
>>> categories.unique_aliases('ABC')
{'LATIN'}
>>> categories.unique_aliases('ΟAΟ-')
{'GREEK', 'LATIN', 'COMMON'}
Parameters
string(str) β A unicode character
Returns β A set of the script block aliases used in a unicode string.
Return type β (str, str)
Yes, the return type in the original really says (str, str) even though it returns a set. We keep the lore exactly as written. π
π confusable_homoglyphs.cli module
confusable_homoglyphs.cli.generate_categories()
This one generates the categories JSON data file from the unicode specification. Slay. π
Returns β True for success, raises otherwise.
Return type β bool
confusable_homoglyphs.cli.generate_confusables()
Same energy: generates the confusables JSON data file from the unicode specification.
Returns β True for success, raises otherwise.
Return type β bool
π confusable_homoglyphs.confusables module
exception confusable_homoglyphs.confusables.Found
Bases: Exception
confusable_homoglyphs.confusables.is_confusable(string, greedy=False, preferred_aliases=[])
Ok so this is the main character. It checks if string contains characters which might be confusable with characters from preferred_aliases. π₯
If greedy=False, it will only return the first confusable character found without looking at the rest of the string, greedy=True returns all of them.
preferred_aliases=[] can take an array of unicode block aliases to be considered as your βbaseβ unicode blocks:
- considering
paΟa,- with
preferred_aliases=['latin'], the 3rd characterΟwould be returned because this greek letter can be confused with latinp. - with
preferred_aliases=['greek'], the 1st characterpwould be returned because this latin letter can be confused with greekΟ. - with
preferred_aliases=[]andgreedy=True, youβll discover the 29 characters that can be confused withp, the 23 characters that look likea, and the one that looks likeΟ(which is, of course,pakaLATIN SMALL LETTER P).
- with
>>> confusables.is_confusable('paΟa', preferred_aliases=['latin'])[0]['character']
'Ο'
>>> confusables.is_confusable('paΟa', preferred_aliases=['greek'])[0]['character']
'p'
>>> confusables.is_confusable('AbΓ§', preferred_aliases=['latin'])
False
>>> confusables.is_confusable('AlloΞ', preferred_aliases=['latin'])
False
>>> confusables.is_confusable('ΟΟΟ', preferred_aliases=['greek'])
False
>>> confusables.is_confusable('ΟΟ.Ο', preferred_aliases=['greek', 'common'])
False
>>> confusables.is_confusable('ΟΟΟp')
[{'homoglyphs': [{'c': 'p', 'n': 'LATIN SMALL LETTER P'}], 'alias': 'GREEK', 'character': 'Ο'}]
Parameters
string(str) β A unicode stringgreedy(bool) β Donβt stop on finding one confusable character - find all of them.preferred_aliases(list(str)) β Script blocks aliases which we donβt want stringβs characters to be confused with.
Returns β False if not confusable, all confusable characters and with what they are confusable otherwise.
Return type β bool or list
confusable_homoglyphs.confusables.is_dangerous(string, preferred_aliases=[])
Checks if string can be dangerous, i.e. is it not only mixed-scripts but also contains characters from other scripts than the ones in preferred_aliases that might be confusable with characters from scripts in preferred_aliases.
For preferred_aliases examples, see is_confusable docstring.
>>> bool(confusables.is_dangerous('Allo'))
False
>>> bool(confusables.is_dangerous('AlloΞ', preferred_aliases=['latin']))
False
>>> bool(confusables.is_dangerous('AlloΟ'))
True
>>> bool(confusables.is_dangerous('AlaskaJazz'))
False
>>> bool(confusables.is_dangerous('ΞlaskaJazz'))
True
Parameters
string(str) β A unicode stringpreferred_aliases(list(str)) β Script blocks aliases which we donβt want stringβs characters to be confused with.
Returns β Is it dangerous.
Return type β bool
confusable_homoglyphs.confusables.is_mixed_script(string, allowed_aliases=['COMMON'])
Checks if string contains mixed-scripts content, excluding script blocks aliases in allowed_aliases.
E.g. B. C is not considered mixed-scripts by default: it contains characters from Latin and Common, but Common is excluded by default.
>>> confusables.is_mixed_script('AbΓ§')
False
>>> confusables.is_mixed_script('ΟΟ.Ο')
False
>>> confusables.is_mixed_script('ΟΟ.Ο', allowed_aliases=[])
True
>>> confusables.is_mixed_script('AlloΟ')
True
Parameters
string(str) β A unicode stringallowed_aliases(list(str)) β Script blocks aliases not to consider.
Returns β Whether string is considered mixed-scripts or not.
Return type β bool
π confusable_homoglyphs.utils module
confusable_homoglyphs.utils.delete(filename)
Deletes a JSON data file if it exists.
confusable_homoglyphs.utils.dump(filename, data)
No description in the original, bestie. It just vibes. π
confusable_homoglyphs.utils.get(url, timeout=None)
Also no description. Just a signature serving looks. β¨
confusable_homoglyphs.utils.load(filename)
Loads a JSON data file.
Returns β A dict.
Return type β dict
confusable_homoglyphs.utils.path(filename)
Returns a file path relative to the data directory.
This is the package directory by default, or the env variable CONFUSABLE_DATA if set.
Returns β A file path string.
Return type β str
confusable_homoglyphs.utils.u(x)
No description. Short and mysterious. π¦
π¦ Module contents
π CONTRIBUTING π
Bestie. Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. Like, always always. No cap. π«Ά
You can contribute in many ways:
π Types of Contributions π
π Report Bugs
Report bugs at https://todo.sr.ht/~valhalla/confusable_homoglyphs β¨
If you're reporting a bug, please include:
- Any details about your local setup that might be helpful in troubleshooting. (spill the tea about your environment, it genuinely helps)
- Detailed steps to reproduce the bug. (receipts!! we need the receipts)
π§ Fix Bugs
Look through the sourcehut tickets for bugs. Anything tagged with βbugβ is open to whoever wants to implement it. Go off, honestly. π
β¨ Implement Features
Look through the sourcehut tickets for features. Anything tagged with βfeatureβ is open to whoever wants to implement it. main character energy, take the ticket π
π Write Documentation
confusable_homoglyphs could always use more documentation, whether as part of the official confusable_homoglyphs docs, in docstrings, or even on the web in blog posts, articles, and such. fr fr, docs are the love language of open source π
π Submit Feedback
The best way to send feedback is to file an issue at https://todo.sr.ht/~valhalla/confusable_homoglyphs.
If you're proposing a feature:
- Explain in detail how it would work. (be specific bestie, vague pitches are giving chaos)
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :) no one here is getting paid, be nice, be patient π¦
πΈ Get Started! πΈ
Ready to contribute? Here's how to set up confusable_homoglyphs for local development. Let's gooo π₯
- Clone the git repository from sourcehut:
$ git clone https://git.sr.ht/~valhalla/confusable_homoglyphs
- Install your local copy into a virtualenv. Assuming you have
virtualenvwrapperinstalled, this is how you set up your fork for local development:
$ mkvirtualenv confusable_homoglyphs
$ cd confusable_homoglyphs/
$ python setup.py develop
- Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally. tiny branch, big dreams π
- When you're done making changes, check that your changes pass
flake8and the tests, including testing other Python versions withtox:
$ flake8 confusable_homoglyphs tests
$ python setup.py test
$ tox
To get flake8 and tox, just pip install them into your virtualenv. yes, into the virtualenv, not globally, we're not monsters π
- Commit your changes:
$ git add .
$ git commit -m "Your detailed description of your changes."
- Send the patch to
mailto:~valhalla/confusable_homoglyphs-devel@lists.sr.ht:
$ git send-email \
--to="mailto:~valhalla/confusable_homoglyphs-devel@lists.sr.ht" \
HEAD^
you can see https://git-send-email.io/ for details on how to install and configure git-send-email. iykyk, the email workflow is a whole vibe once you get it π¬
Not me pointing out that the list jumps from 5 to 7 π β but it does, and we're keeping it exactly as it is, because the manual page says so and the manual page is the moment. π
π Pull Request Guidelines π
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests. always always always
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in
README.rst. - The pull request should work for all supported Python versions. all of them, bestie, not just your fave
π CREDITS π
π Original Author and Former Maintainer
- Victor Felder
<victorfelder@gmail.com>
π Current Maintainer
- Elena βof Valhallaβ Grandi
<valhalla@trueelena.org>
π«Ά Contributors
- Ryan P Kilby
<rpkilby@ncsu.edu>
π HISTORY π
1.0.0
- Initial release. the origin story β¨
2.0.0
allowed_categoriesrenamed toallowed_aliases
2.0.1
- Fix a
TypeError:https://github.com/vhf/confusable_homoglyphs/pull/2
3.0.0
Courtesy of Ryan P Kilby, via https://github.com/vhf/confusable_homoglyphs/pull/6 :
- Changed file paths to be relative to the
confusable_homoglyphspackage directory instead of the user's current working directory. - Data files are now distributed with the packaging.
- Fixes tests so that they use the installed distribution instead of the local files. (Originally, the data files were erroneously showing up during testing, despite not being included in the distribution).
- Moves the data file generation into a simple CLI. This way, users have a method for controlling when the data files are updated.
- Since the data files are now included in the distribution, the CLI is made optional. Its dependencies can be installed with the
clibundle, eg.pip install confusable_homoglyphs[cli].
3.1.0
- Update unicode data
3.1.1
- Update unicode data (via
ftp)
3.2.0
- Drop support for Python 3.3
- Fix #11: work as expected when char not found in datafiles
3.3.0
- Drop support for Python 2
- Drop support for Python < 3.7, add support for Python up to 3.12
- Allow using data files from a custom location set with the
CONFUSABLE_DATAenvironment variable. - Fix the return value of
confusables.is_dangerous()to the documented API of a boolean value. It used to return eitherFalseor the list output ofconfusable.is_confusable(). - Added a
checkcommand for command line use.
3.3.1
- Update unicode data
βοΈ AUTHOR βοΈ
Victor Felder
Β©οΈ COPYRIGHT Β©οΈ
2024, Victor Felder
and that's the whole page, bestie!! π This was CONFUSABLE_HOMOGLYPHS(1), version 3.3.1, dated Jan 30, 2024 β so if you're reading this from the future, hi, hope the unicode data got updated again π slay, stay safe out there, and go report that bug π¦β¨
π¦ where this page comes from
- debian trixie: python3-confusable-homoglyphs 3.3.1-1 Β· MIT
- ubuntu noble: python3-confusable-homoglyphs 3.3.1-1 Β· MIT
- ubuntu questing: python3-confusable-homoglyphs 3.3.1-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms