Franck Pommereau

### fixed encoding problems

Showing with 23 additions and 19 deletions
 1 -# -*- encoding: latin-1 1 +"""A plugin to compose nets _a la_ Petri Box Calculus. 2 -"""A plugin to compose nets _à la_ Petri Box Calculus. 3 2 4 @note: this plugin depends on plugins `clusters` and `status` that are 3 @note: this plugin depends on plugins `clusters` and `status` that are 5 automatically loaded 4 automatically loaded ... ...
 1 -#-*- encoding: latin-1 2 """A plugin to add positions to the nodes. 1 """A plugin to add positions to the nodes. 3 2 4 `Place` and `Transition` are added an optional argument for the 3 `Place` and `Transition` are added an optional argument for the ... @@ -388,8 +387,8 @@ def extend (module) : ... @@ -388,8 +387,8 @@ def extend (module) : 388 for node in self.node() : 387 for node in self.node() : 389 node.pos.shift(dx, dy) 388 node.pos.shift(dx, dy) 390 def transpose (self) : 389 def transpose (self) : 391 - """Perform a clockwise 90° rotation of node coordinates, 390 + """Perform a clockwise 90 degrees rotation of node coordinates, ie, 392 - ie, change every position `(x, y)` to `(-y, x)` 391 + change every position `(x, y)` to `(-y, x)` 393 """ 392 """ 394 for node in self.node() : 393 for node in self.node() : 395 x, y = node.pos() 394 x, y = node.pos() ... ...
 1 -#-*- coding: latin-1 2 """Add statuses to nodes: a status is a special kind of label that is 1 """Add statuses to nodes: a status is a special kind of label that is 3 -used to define Petri nets compositions _à la_ Petri Box Calculus. See 2 +used to define Petri nets compositions _a la_ Petri Box Calculus. See 4 plugin `ops` to read more about how statuses are used in practice. 3 plugin `ops` to read more about how statuses are used in practice. 5 4 6 Several status are defined by default: `entry`, `internal`, `exit`, 5 Several status are defined by default: `entry`, `internal`, `exit`, ... @@ -33,6 +32,7 @@ Place('p1', MultiSet([]), tAll, status=Status('entry')) ... @@ -33,6 +32,7 @@ Place('p1', MultiSet([]), tAll, status=Status('entry')) 33 >>> n.add_place(Place('p2', status=exit)) 32 >>> n.add_place(Place('p2', status=exit)) 34 >>> n.place('p2') 33 >>> n.place('p2') 35 Place('p2', MultiSet([]), tAll, status=Status('exit')) 34 Place('p2', MultiSet([]), tAll, status=Status('exit')) 35 + 36 """ 36 """ 37 37 38 import operator, weakref 38 import operator, weakref ... @@ -717,6 +717,6 @@ def extend (module) : ... @@ -717,6 +717,6 @@ def extend (module) : 717 (self.place(s).status for s in sources)) 717 (self.place(s).status for s in sources)) 718 module.PetriNet.merge_transitions(self, target, sources, **args) 718 module.PetriNet.merge_transitions(self, target, sources, **args) 719 self.set_status(target, status) 719 self.set_status(target, status) 720 - return Place, Transition, PetriNet, Status, \ 720 + return (Place, Transition, PetriNet, Status, 721 - ("entry", entry), ("exit", exit), ("internal", internal), \ 721 + ("entry", entry), ("exit", exit), ("internal", internal), 722 - Buffer, buffer, Safebuffer, safebuffer, Tick, tick 722 + Buffer, buffer, Safebuffer, safebuffer, Tick, tick) ... ...
 ... @@ -51,11 +51,10 @@ at SNAKES source code. However, let's note a few points: ... @@ -51,11 +51,10 @@ at SNAKES source code. However, let's note a few points: 51 it should work in other cases but this may required some work 51 it should work in other cases but this may required some work 52 """ 52 """ 53 53 54 -import sys, os, os.path 54 +import sys, os, os.path, codecs 55 -import inspect, fnmatch, collections, re, shlex 55 +import inspect, fnmatch, re, shlex 56 import textwrap, doctest 56 import textwrap, doctest 57 import snakes 57 import snakes 58 -from snakes.lang import unparse 59 from snakes.lang.python.parser import parse, ast 58 from snakes.lang.python.parser import parse, ast 60 59 61 try : 60 try : ... @@ -118,7 +117,8 @@ def die (message, code=1) : ... @@ -118,7 +117,8 @@ def die (message, code=1) : 118 class DocExtract (object) : 117 class DocExtract (object) : 119 """The class that extracts documentation and renders it 118 """The class that extracts documentation and renders it 120 """ 119 """ 121 - def __init__ (self, inpath, outpath, exclude=[]) : 120 + def __init__ (self, inpath, outpath, exclude=[], 121 + inputenc="utf-8", outputenc="utf-8") : 122 """ 122 """ 123 @param inpath: directory where the source code is searched for 123 @param inpath: directory where the source code is searched for 124 @type inpath: `str` 124 @type inpath: `str` ... @@ -127,11 +127,17 @@ class DocExtract (object) : ... @@ -127,11 +127,17 @@ class DocExtract (object) : 127 @param exclude: a list of glob patterns to exclude modules 127 @param exclude: a list of glob patterns to exclude modules 128 (not file names, but Python modules names) 128 (not file names, but Python modules names) 129 @type exclude: `list` 129 @type exclude: `list` 130 + @param inputenc: encoding of input files 131 + @type inputenc: `str` 132 + @param outputenc: encoding of output files 133 + @type outputenc: `str` 130 """ 134 """ 131 self.path = inpath.rstrip(os.sep) 135 self.path = inpath.rstrip(os.sep) 132 self.outpath = outpath 136 self.outpath = outpath 133 self.out = None 137 self.out = None 134 self.exclude = exclude 138 self.exclude = exclude 139 + self.inputenc = inputenc 140 + self.outputenc = outputenc 135 self._last = "\n\n" 141 self._last = "\n\n" 136 def md (self, text, inline=True) : 142 def md (self, text, inline=True) : 137 """Return the Markdow rendering of `text`, include `

` if 143 """Return the Markdow rendering of `text`, include `

` if ... @@ -196,7 +202,7 @@ class DocExtract (object) : ... @@ -196,7 +202,7 @@ class DocExtract (object) : 196 info("%s -> %r" % (self.module, outpath)) 202 info("%s -> %r" % (self.module, outpath)) 197 if not os.path.exists(outdir) : 203 if not os.path.exists(outdir) : 198 os.makedirs(outdir) 204 os.makedirs(outdir) 199 - self.out = open(outpath, "w") 205 + self.out = codecs.open(outpath, "w", encoding=self.outputenc) 200 self.classname = None 206 self.classname = None 201 return True 207 return True 202 def write (self, text) : 208 def write (self, text) : ... @@ -271,9 +277,9 @@ class DocExtract (object) : ... @@ -271,9 +277,9 @@ class DocExtract (object) : 271 if not self.openout(path) : 277 if not self.openout(path) : 272 continue 278 continue 273 try : 279 try : 274 - node = parse(open(path).read()) 280 + node = parse(codecs.open(path, encoding=self.inputenc).read()) 275 - except : 281 + except Exception as e : 276 - err("error parsing %r" % path) 282 + err("error parsing %r (%s)" % (path, e)) 277 continue 283 continue 278 if ".plugins." in self.module : 284 if ".plugins." in self.module : 279 self.visit_plugin(node) 285 self.visit_plugin(node) ... @@ -594,7 +600,7 @@ class DocExtract (object) : ... @@ -594,7 +600,7 @@ class DocExtract (object) : 594 path = os.path.join(os.path.dirname(self.inpath), name) 600 path = os.path.join(os.path.dirname(self.inpath), name) 595 if not os.path.exists(path) : 601 if not os.path.exists(path) : 596 err("include file %r not found" % name) 602 err("include file %r not found" % name) 597 - with open(path) as infile : 603 + with codecs.open(path, encoding=self.inputenc) as infile : 598 self.newline() 604 self.newline() 599 self.writeline(" :::%s" % lang) 605 self.writeline(" :::%s" % lang) 600 for i, line in enumerate(infile) : 606 for i, line in enumerate(infile) : ... ...