Clean up unicode mentions in docstrings
This commit is contained in:
parent
a9902a8f18
commit
fa8c7657da
8 changed files with 34 additions and 55 deletions
|
|
@ -323,7 +323,7 @@ def build_map(caller, game_map, legend, iterations=1, build_exits=True):
|
||||||
for y in range(len(game_map)):
|
for y in range(len(game_map)):
|
||||||
for x in range(len(game_map[y])):
|
for x in range(len(game_map[y])):
|
||||||
for key in legend:
|
for key in legend:
|
||||||
# obs - we must use == for unicode
|
# obs - we must use == for strings
|
||||||
if game_map[y][x] == key:
|
if game_map[y][x] == key:
|
||||||
room = legend[key](x, y, iteration=iteration,
|
room = legend[key](x, y, iteration=iteration,
|
||||||
room_dict=room_dict,
|
room_dict=room_dict,
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ class AttributeForm(forms.ModelForm):
|
||||||
self.instance.attr_key = attr_key
|
self.instance.attr_key = attr_key
|
||||||
self.instance.attr_category = attr_category
|
self.instance.attr_category = attr_category
|
||||||
self.instance.attr_value = attr_value
|
self.instance.attr_value = attr_value
|
||||||
# prevent set from being transformed to unicode
|
# prevent set from being transformed to str
|
||||||
if isinstance(attr_value, set) or isinstance(attr_value, _SaverSet):
|
if isinstance(attr_value, set) or isinstance(attr_value, _SaverSet):
|
||||||
self.fields['attr_value'].disabled = True
|
self.fields['attr_value'].disabled = True
|
||||||
self.instance.deserialized_value = from_pickle(attr_value)
|
self.instance.deserialized_value = from_pickle(attr_value)
|
||||||
|
|
@ -242,8 +242,8 @@ class AttributeForm(forms.ModelForm):
|
||||||
|
|
||||||
def clean_attr_value(self):
|
def clean_attr_value(self):
|
||||||
"""
|
"""
|
||||||
Prevent Sets from being cleaned due to literal_eval failing on them. Otherwise they will be turned into
|
Prevent Sets from being cleaned due to literal_eval failing on them. Otherwise they will be turned into str.
|
||||||
unicode.
|
|
||||||
"""
|
"""
|
||||||
data = self.cleaned_data['attr_value']
|
data = self.cleaned_data['attr_value']
|
||||||
initial = self.instance.attr_value
|
initial = self.instance.attr_value
|
||||||
|
|
|
||||||
|
|
@ -613,7 +613,7 @@ def _transform(func_name):
|
||||||
|
|
||||||
class ANSIMeta(type):
|
class ANSIMeta(type):
|
||||||
"""
|
"""
|
||||||
Many functions on ANSIString are just light wrappers around the unicode
|
Many functions on ANSIString are just light wrappers around the string
|
||||||
base class. We apply them here, as part of the classes construction.
|
base class. We apply them here, as part of the classes construction.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -637,10 +637,9 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
|
||||||
"""
|
"""
|
||||||
Unicode-like object that is aware of ANSI codes.
|
Unicode-like object that is aware of ANSI codes.
|
||||||
|
|
||||||
This class can be used nearly identically to unicode, in that it will
|
This class can be used nearly identically to strings, in that it will
|
||||||
report string length, handle slices, etc, much like a unicode or
|
report string length, handle slices, etc, much like a string object
|
||||||
string object would. The methods should be used identically as unicode
|
would. The methods should be used identically as string methods are.
|
||||||
methods are.
|
|
||||||
|
|
||||||
There is at least one exception to this (and there may be more, though
|
There is at least one exception to this (and there may be more, though
|
||||||
they have not come up yet). When using ''.join() or u''.join() on an
|
they have not come up yet). When using ''.join() or u''.join() on an
|
||||||
|
|
@ -735,18 +734,11 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
|
||||||
ANSI parser with one of your own syntax if you wish, so long as it
|
ANSI parser with one of your own syntax if you wish, so long as it
|
||||||
implements the same interface.
|
implements the same interface.
|
||||||
|
|
||||||
The second is the _raw_string. It should be noted that the ANSIStrings
|
The second is the _raw_string. This is the original "dumb" string
|
||||||
are unicode based. This seemed more reasonable than basing it off of
|
with ansi escapes that ANSIString represents.
|
||||||
the string class, because if someone were to use a unicode character,
|
|
||||||
the benefits of knowing the indexes of the ANSI characters would be
|
|
||||||
negated by the fact that a character within the string might require
|
|
||||||
more than one byte to be represented. The raw string is, then, a
|
|
||||||
unicode object rather than a true encoded string. If you need the
|
|
||||||
encoded string for sending over the wire, try using the .encode()
|
|
||||||
method.
|
|
||||||
|
|
||||||
The third thing to set is the _clean_string. This is a unicode object
|
The third thing to set is the _clean_string. This is a string that is
|
||||||
that is devoid of all ANSI Escapes.
|
devoid of all ANSI Escapes.
|
||||||
|
|
||||||
Finally, _code_indexes and _char_indexes are defined. These are lookup
|
Finally, _code_indexes and _char_indexes are defined. These are lookup
|
||||||
tables for which characters in the raw string are related to ANSI
|
tables for which characters in the raw string are related to ANSI
|
||||||
|
|
@ -894,20 +886,20 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""
|
"""
|
||||||
Return a unicode object without the ANSI escapes.
|
Return a string object *without* the ANSI escapes.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
clean_string (unicode): A unicode object with no ANSI escapes.
|
clean_string (str): A unicode object with no ANSI escapes.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._clean_string
|
return self._clean_string
|
||||||
|
|
||||||
def raw(self):
|
def raw(self):
|
||||||
"""
|
"""
|
||||||
Return a unicode object with the ANSI escapes.
|
Return a string object with the ANSI escapes.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
raw (unicode): A unicode object with the raw ANSI escape sequences.
|
raw (str): A unicode object *with* the raw ANSI escape sequences.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._raw_string
|
return self._raw_string
|
||||||
|
|
@ -951,7 +943,7 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
|
||||||
readable characters, and one which contains the indexes of all ANSI
|
readable characters, and one which contains the indexes of all ANSI
|
||||||
escapes. It's important to remember that ANSI escapes require more
|
escapes. It's important to remember that ANSI escapes require more
|
||||||
that one character at a time, though no readable character needs more
|
that one character at a time, though no readable character needs more
|
||||||
than one character, since the unicode base class abstracts that away
|
than one character, since the string base class abstracts that away
|
||||||
from us. However, several readable characters can be placed in a row.
|
from us. However, several readable characters can be placed in a row.
|
||||||
|
|
||||||
We must use regexes here to figure out where all the escape sequences
|
We must use regexes here to figure out where all the escape sequences
|
||||||
|
|
@ -1229,7 +1221,7 @@ class ANSIString(with_metaclass(ANSIMeta, str)):
|
||||||
|
|
||||||
NOTE: This should always be used for joining strings when ANSIStrings
|
NOTE: This should always be used for joining strings when ANSIStrings
|
||||||
are involved. Otherwise color information will be discarded by
|
are involved. Otherwise color information will be discarded by
|
||||||
python, due to details in the C implementation of unicode strings.
|
python, due to details in the C implementation of strings.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
iterable (list of strings): A list of strings to join together
|
iterable (list of strings): A list of strings to join together
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ def read_batchfile(pythonpath, file_ending='.py'):
|
||||||
decoderr = []
|
decoderr = []
|
||||||
for abspath in abspaths:
|
for abspath in abspaths:
|
||||||
# try different paths, until we get a match
|
# try different paths, until we get a match
|
||||||
# we read the file directly into unicode.
|
# we read the file directly into string.
|
||||||
for file_encoding in _ENCODINGS:
|
for file_encoding in _ENCODINGS:
|
||||||
# try different encodings, in order
|
# try different encodings, in order
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,7 @@ Use as follows:
|
||||||
form.map(tables={"A": tableA,
|
form.map(tables={"A": tableA,
|
||||||
"B": tableB})
|
"B": tableB})
|
||||||
|
|
||||||
# unicode is required since the example contains non-ascii characters
|
print(form)
|
||||||
print unicode(form)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This produces the following result:
|
This produces the following result:
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,6 @@ This is an advanced ASCII table creator. It was inspired by
|
||||||
[prettytable](https://code.google.com/p/prettytable/) but shares no
|
[prettytable](https://code.google.com/p/prettytable/) but shares no
|
||||||
code.
|
code.
|
||||||
|
|
||||||
> Note: to test ANSI colors on the command line you need to call the
|
|
||||||
printed table in a unicode() call, like print unicode(table). This is
|
|
||||||
due to a bug in the python interpreter and print.
|
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
@ -140,7 +136,6 @@ def _to_ansi(obj):
|
||||||
return ANSIString(obj)
|
return ANSIString(obj)
|
||||||
|
|
||||||
|
|
||||||
_unicode = str
|
|
||||||
_whitespace = '\t\n\x0b\x0c\r '
|
_whitespace = '\t\n\x0b\x0c\r '
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -167,8 +162,6 @@ class ANSITextWrapper(TextWrapper):
|
||||||
# if self.replace_whitespace:
|
# if self.replace_whitespace:
|
||||||
# if isinstance(text, str):
|
# if isinstance(text, str):
|
||||||
# text = text.translate(self.whitespace_trans)
|
# text = text.translate(self.whitespace_trans)
|
||||||
# elif isinstance(text, _unicode):
|
|
||||||
# text = text.translate(self.unicode_whitespace_trans)
|
|
||||||
# return text
|
# return text
|
||||||
|
|
||||||
def _split(self, text):
|
def _split(self, text):
|
||||||
|
|
@ -440,7 +433,6 @@ class EvCell(object):
|
||||||
self.align = kwargs.get("align", "l")
|
self.align = kwargs.get("align", "l")
|
||||||
self.valign = kwargs.get("valign", "c")
|
self.valign = kwargs.get("valign", "c")
|
||||||
|
|
||||||
# self.data = self._split_lines(unicode(data))
|
|
||||||
self.data = self._split_lines(_to_ansi(data))
|
self.data = self._split_lines(_to_ansi(data))
|
||||||
self.raw_width = max(m_len(line) for line in self.data)
|
self.raw_width = max(m_len(line) for line in self.data)
|
||||||
self.raw_height = len(self.data)
|
self.raw_height = len(self.data)
|
||||||
|
|
@ -740,7 +732,6 @@ class EvCell(object):
|
||||||
`EvCell.__init__`.
|
`EvCell.__init__`.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# self.data = self._split_lines(unicode(data))
|
|
||||||
self.data = self._split_lines(_to_ansi(data))
|
self.data = self._split_lines(_to_ansi(data))
|
||||||
self.raw_width = max(m_len(line) for line in self.data)
|
self.raw_width = max(m_len(line) for line in self.data)
|
||||||
self.raw_height = len(self.data)
|
self.raw_height = len(self.data)
|
||||||
|
|
|
||||||
|
|
@ -35,23 +35,15 @@ from copy import deepcopy
|
||||||
from base64 import b64encode, b64decode
|
from base64 import b64encode, b64decode
|
||||||
from zlib import compress, decompress
|
from zlib import compress, decompress
|
||||||
# import six # this is actually a pypy component, not in default syslib
|
# import six # this is actually a pypy component, not in default syslib
|
||||||
import django
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# django 1.5 introduces force_text instead of force_unicode
|
|
||||||
from django.forms import CharField, Textarea
|
from django.forms import CharField, Textarea
|
||||||
from django.forms.utils import flatatt
|
from django.forms.utils import flatatt
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
|
||||||
from evennia.utils.dbserialize import from_pickle, to_pickle
|
|
||||||
from future.utils import with_metaclass
|
|
||||||
from pickle import loads, dumps
|
from pickle import loads, dumps
|
||||||
|
from django.utils.encoding import force_text
|
||||||
try:
|
|
||||||
from django.utils.encoding import force_text
|
|
||||||
except ImportError:
|
|
||||||
from django.utils.encoding import force_unicode as force_text
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_PROTOCOL = 4
|
DEFAULT_PROTOCOL = 4
|
||||||
|
|
@ -188,10 +180,10 @@ class PickledObjectField(models.Field):
|
||||||
"""
|
"""
|
||||||
Returns the default value for this field.
|
Returns the default value for this field.
|
||||||
|
|
||||||
The default implementation on models.Field calls force_unicode
|
The default implementation on models.Field calls force_text
|
||||||
on the default, which means you can't set arbitrary Python
|
on the default, which means you can't set arbitrary Python
|
||||||
objects as the default. To fix this, we just return the value
|
objects as the default. To fix this, we just return the value
|
||||||
without calling force_unicode on it. Note that if you set a
|
without calling force_text on it. Note that if you set a
|
||||||
callable as a default, the field will still call it. It will
|
callable as a default, the field will still call it. It will
|
||||||
*not* try to pickle and encode it.
|
*not* try to pickle and encode it.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -738,16 +738,21 @@ _UNICODE_MAP = {"EM DASH": "-", "FIGURE DASH": "-", "EN DASH": "-", "HORIZONTAL
|
||||||
"HORIZONTAL ELLIPSIS": "...", "RIGHT SINGLE QUOTATION MARK": "'"}
|
"HORIZONTAL ELLIPSIS": "...", "RIGHT SINGLE QUOTATION MARK": "'"}
|
||||||
|
|
||||||
|
|
||||||
def latinify(unicode_string, default='?', pure_ascii=False):
|
def latinify(string, default='?', pure_ascii=False):
|
||||||
"""
|
"""
|
||||||
Convert a unicode string to "safe" ascii/latin-1 characters.
|
Convert a unicode string to "safe" ascii/latin-1 characters.
|
||||||
This is used as a last resort when normal decoding does not work.
|
This is used as a last resort when normal encoding does not work.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
unicode_string (unicode): A string to convert to an ascii
|
string (str): A string to convert to 'safe characters' convertable
|
||||||
or latin-1 string.
|
to an latin-1 bytestring later.
|
||||||
default (str, optional): Characters resisting mapping will be replaced
|
default (str, optional): Characters resisting mapping will be replaced
|
||||||
with this character or string.
|
with this character or string. The intent is to apply an encode operation
|
||||||
|
on the string soon after.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string (str): A 'latinified' string where each unicode character has been
|
||||||
|
replaced with a 'safe' equivalent available in the ascii/latin-1 charset.
|
||||||
Notes:
|
Notes:
|
||||||
This is inspired by the gist by Ricardo Murri:
|
This is inspired by the gist by Ricardo Murri:
|
||||||
https://gist.github.com/riccardomurri/3c3ccec30f037be174d3
|
https://gist.github.com/riccardomurri/3c3ccec30f037be174d3
|
||||||
|
|
@ -757,7 +762,7 @@ def latinify(unicode_string, default='?', pure_ascii=False):
|
||||||
from unicodedata import name
|
from unicodedata import name
|
||||||
|
|
||||||
converted = []
|
converted = []
|
||||||
for unich in iter(unicode_string):
|
for unich in iter(string):
|
||||||
try:
|
try:
|
||||||
ch = unich.decode('ascii')
|
ch = unich.decode('ascii')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue