Package: unirange
UnirangeUnirange is a notation for specifying multiple Unicode codepoints.A unirange comprises comma-delimitedcomponents.Apartis a notation for a single character, likeA,U+2600, or0x7535.
It is matched by the regular expression!?(?:0x|U\+|&#x)([0-9A-F]{1,7});?|(.)Arangeis twopartssplit by..(two dots) or-(a hyphen).
It is matched by the regular expression(?PART(?:-|\.\.)PART)Acomponentcomprises either arangeor apart.
It is matched by the regular expression(RANGE|PART)The full unirange notation is matched by the regular expression(?:COMPONENT, ?)*Exclusion can be applied to any component by prefixing it with a!.
This will instead perform thedifference(subtraction) on the current set of characters.Table of contents📄 About📦 Installation🛠 Usage📰 Changelog📜 License📄 AboutComponentA component is either arange, or apart.
These components define what characters are included or excluded by the unirange.PartA part is asinglecharacter notation.
In arange, there exist two parts, split by..or-.
In the rangeU+2600..U+26FF,U+2600andU+26FFare parts.Parts can match any of these regular expressions:U\+.{1,6}&#x.{1,6}0x.{1,6}.If more than one character is in a part, and it isnotprefixed, it isinvalid.
For example,2600is not a valid part, butU+2600is.There is no way to specify a codepoint in a base system other thanhexadecimal.&#1234is not valid.RangeA range is twopartsseparated by..or-.Implied infinite expansionIf either (but not both) part of the range is absent, it is calledimplied infinite expansion(IIE).
With IIE, the range's boundaries are implied to become to lower or upper limits of the Unicode character set.If the first part is absent, the first part becomes U+0000.
If the second part is absent, it becomes U+10FFFF.
If both parts are absent,the range is invalid.This means that the rangeU+2600..will result in characters from U+2600 to U+10FFFF.
It is semantically equivalent toU+2600..U+10FFFF.This also applies to the reverse: the range..U+2600will result in characters from U+0000 to U+2600.
Likewise, it is equivalent toU+0000..U+2600.ExclusionTo exclude a character from being included in a resulting range, prefix a component with a!.
This will prevent it from being included in the range, regardless of what other parts indicate.For example,U+2600..U+26FF, U+2704, !U+2605will include the codepoints from U+2600up toU+2605,
and then from U+2606 to U+26FF, as well as U+2704.You can exclude ranges as well. Either part of a range may be prefixed with a!to label that part as an
exclusion.!U+2600..U+267F,!U+2600..!U+267F, and!U+2600..!U+267Fresult in the same range:
no codepoints from U+2600 to U+267F.Exclusions must come after the inclusions, or else they will be overridden.The order of your components matters when excluding.
Components after an exclusion that conflict with itwillobsolete it, overriding it.
For example,!U+2600..U+2650,U+2600..U+26FFwill result in the effective range ofU+2600-26FF.📦 Installationunirangeis available on PyPI.
It requires a Python version ofat least 3.11.0.To install unirange with pip, run:python-mpipinstallunirange"externally-managed-environment"This error occurs on some Linux distributions such as Fedora 38 and Ubuntu 23.04.
It can be solved by either:Using avirtual environment (venv)Usingpipx🛠 UsageUsingunirangeis simple.>>>importunirange>>>unirange.unirange_to_characters("A..Z"){'G','D','I','K','X','J','V','O','H','C','A','B','Y','F','P','W','L','M','R','S','E','T','Z','N','U','Q'}>>>unirange.unirange_to_characters("..0"){'\x19','0','\x1c','#','\x14','\x0c','\x01','\x0e','\r','\t','+','.','%','\x18','\x15','\x12','\x16','\x05','!','\x1b','/','\x17','\x0b','&','\x1d','\n','\x1e','\x10','"',"'",'\x04','\x1a','(',' ','\x08','\x07','\x03',')','\x1f','\x02','\x13','$','-','\x11',',','\x00','*','\x06','\x0f'}>>>unirange.unirange_to_characters("U+2600..U+26FF, !U+2610.."){'☌','☍','☂','☉','☏','☋','☀','☄','☃','☈','☆','☊','☇','★','☁','☎'}>>>unirange.unirange_to_characters("U+2600....")unirange.UnirangeError:Invalidunirangenotation:U+2600....>>>unirange.unirange_to_characters("U+2600..U+10000"){'쏳','䔿','镔','种','嗼','溳','㟏','걕','줿','죕','䑀','ꕀ','\ue548','豴','촫','䪻','䋱','蹾','퉙','烅','\uea1f',...}It can also be used in CLI:$python-munirangeU+2600..U+2610
☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐$python-munirangeU+2600
☀$python-munirange'U+2600..,!U+2650..'☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏For some uniranges, you may need to wrap the argument in'or else the shell will interpret them oddly:$python-munirangeU+2600..,!U+2650..
bash:!U+2650..:eventnotfound
$python-munirange'U+2600..,!U+2650..'# Works as expected.📰 ChangelogThe changelog is atCHANGELOG.md.📜 Licenseunirangeis licensed under theMIT license.