Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

Commit

Permalink
pep8 and mypy fixes. Release 3.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Jul 26, 2017
1 parent 8af472b commit 7f95318
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any


__version__ = "3.7.dev0"
__version__ = "3.7"


class _MudContext:
Expand Down
16 changes: 9 additions & 7 deletions tale/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
from distutils.version import LooseVersion
if LooseVersion(tale.__version__) < LooseVersion("{required_tale_version}"):
print("Tale version installed:", tale.__version__, file=sys.stderr)
print("Tale version required : {required_tale_version}", file=sys.stderr)
print("Tale version required : {required_tale_version}", file=sys.stderr)
tale_error = "installed Tale library version too old"
except ImportError as x:
tale_error = str(x)
if tale_error:
print("Error loading Tale: ", tale_error, file=sys.stderr)
print("To run this game you have to install a recent enough Tale library.\\nRunning the command 'pip install --upgrade tale' usually fixes this.\\n", file=sys.stderr)
print("To run this game you have to install a recent enough Tale library.\\n"
"Running the command 'pip install --upgrade tale' usually fixes this.\\n", file=sys.stderr)
print("Enter to exit: ", file=sys.stderr)
input()
raise SystemExit
Expand All @@ -66,7 +67,7 @@ def do_zip(path: str, zipfilename: str, embed_tale: bool=False, verbose: bool=Fa
"""Zip a story (possibly including the tale library itself - but not its dependencies, to avoid license hassles) into a zip file."""
if os.path.exists(zipfilename):
raise IOError("output file already exists: " + zipfilename)
with zipfile.ZipFile(zipfilename+".tmp", mode="w", compression=zipfile.ZIP_DEFLATED) as zip:
with zipfile.ZipFile(zipfilename + ".tmp", mode="w", compression=zipfile.ZIP_DEFLATED) as zip:
prev_dir = os.getcwd()
os.chdir(path)
print("\nCreating zip file from '{}'...".format(path))
Expand Down Expand Up @@ -100,7 +101,8 @@ def do_zip(path: str, zipfilename: str, embed_tale: bool=False, verbose: bool=Fa
else:
# only one possible game mode, autoselect this one
mode = possible_game_modes.pop()
zip.writestr("__main__.py", main_py_template.format(gamemode=mode.value, required_tale_version=story.Story.config.requires_tale))
zip.writestr("__main__.py", main_py_template.format(gamemode=mode.value,
required_tale_version=story.Story.config.requires_tale))
if embed_tale:
os.chdir(os.path.dirname(tale.__file__))
if verbose:
Expand All @@ -117,8 +119,8 @@ def do_zip(path: str, zipfilename: str, embed_tale: bool=False, verbose: bool=Fa
os.chdir(prev_dir)
# use zipapp to add a posix shebang.
# note: we can't use zipapp conveniently to create the whole zipfile because it also includes temp files that I don't want...
zipapp.create_archive(zipfilename+".tmp", zipfilename, interpreter="/usr/bin/env python3")
os.remove(zipfilename+".tmp")
zipapp.create_archive(zipfilename + ".tmp", zipfilename, interpreter="/usr/bin/env python3")
os.remove(zipfilename + ".tmp")
if verbose:
print("\nDone. Try running 'python {}'".format(zipfilename))

Expand Down
2 changes: 1 addition & 1 deletion tale/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def write_output(self) -> None:
self.io.do_prompt_toolkit = self.player.prompt_toolkit_enabled
if mud_context.config.server_mode == GameMode.IF and self.player.output_line_delay > 0:
if os.name == "nt" and self.io.do_prompt_toolkit:
line_delay = 0 # on windows, when using prompt_toolkit, printing individual lines is already very slow
line_delay = 0.0 # on windows, when using prompt_toolkit, printing individual lines is already very slow
else:
line_delay = self.player.output_line_delay / 1000.0
for line in output.rstrip().splitlines():
Expand Down
6 changes: 4 additions & 2 deletions tale/tio/iobase.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ def smartquotes(self, text: str) -> str:
"""If enabled, apply 'smart quotes' to the text; replaces quotes and dashes by nicer looking symbols"""
if self.supports_smartquotes and self.do_smartquotes:
if hasattr(smartypants.Attr, "u"):
return smartypants.smartypants(text, smartypants.Attr.q | smartypants.Attr.B | smartypants.Attr.D | smartypants.Attr.e | smartypants.Attr.u)
return smartypants.smartypants(text, smartypants.Attr.q | smartypants.Attr.B |
smartypants.Attr.D | smartypants.Attr.e | smartypants.Attr.u)
else:
# older smartypants lack attribute 'u' for avoiding html entity creation
txt = smartypants.smartypants(text, smartypants.Attr.q | smartypants.Attr.B | smartypants.Attr.D | smartypants.Attr.e)
txt = smartypants.smartypants(text, smartypants.Attr.q | smartypants.Attr.B |
smartypants.Attr.D | smartypants.Attr.e)
import html.parser
return html.parser.unescape(txt) # type: ignore
return text
Expand Down

0 comments on commit 7f95318

Please sign in to comment.