2626#--Standard
2727from __future__ import division
2828import StringIO
29- import cPickle
29+ import cPickle as pickle # PY3
3030import chardet
3131import codecs
3232import collections
3838import re
3939import shutil
4040import stat
41+ import string
4142import struct
4243import subprocess
4344import sys
5051# Internal
5152from . import exception
5253
54+ # PY3
55+ try :
56+ from urllib .parse import quote
57+ except ImportError :
58+ from urllib import quote
59+
5360# structure aliases, mainly introduced to reduce uses of 'pack' and 'unpack'
5461struct_pack = struct .pack
5562struct_unpack = struct .unpack
@@ -1364,7 +1371,7 @@ def load(self):
13641371 try :
13651372 with path .open ('rb' ) as ins :
13661373 try :
1367- firstPickle = cPickle .load (ins )
1374+ firstPickle = pickle .load (ins )
13681375 except ValueError :
13691376 cor = path
13701377 cor_name = GPath (path .s + u' (%s)' % timestamp () +
@@ -1373,8 +1380,8 @@ def load(self):
13731380 path , cor_name .tail ), traceback = True )
13741381 continue # file corrupt - try next file
13751382 if firstPickle == 'VDATA2' :
1376- self .vdata .update (cPickle .load (ins ))
1377- self .data .update (cPickle .load (ins ))
1383+ self .vdata .update (pickle .load (ins ))
1384+ self .data .update (pickle .load (ins ))
13781385 else :
13791386 raise PickleDict .Mold (path )
13801387 return 1 + (path == self .backup )
@@ -1394,7 +1401,7 @@ def save(self):
13941401 self .vdata ['boltPaths' ] = True # needed so pre 307 versions don't blow
13951402 with self .path .temp .open ('wb' ) as out :
13961403 for data in ('VDATA2' ,self .vdata ,self .data ):
1397- cPickle .dump (data ,out ,- 1 )
1404+ pickle .dump (data ,out ,- 1 )
13981405 self .path .untemp (doBackup = True )
13991406 return True
14001407
@@ -2068,7 +2075,6 @@ class WryeText(object):
20682075 @staticmethod
20692076 def genHtml (ins ,out = None ,* cssDirs ):
20702077 """Reads a wtxt input stream and writes an html output stream."""
2071- import string , urllib
20722078 # Path or Stream? -----------------------------------------------
20732079 if isinstance (ins ,(Path ,str ,unicode )):
20742080 srcPath = GPath (ins )
@@ -2116,7 +2122,7 @@ def subAnchor(match):
21162122 # urllib will automatically take any unicode characters and escape them, so to
21172123 # convert back to unicode for purposes of storing the string, everything will
21182124 # be in cp1252, due to the escapings.
2119- anchor = unicode (urllib . quote (reWd .sub (u'' ,text ).encode ('utf8' )),'cp1252' )
2125+ anchor = unicode (quote (reWd .sub (u'' ,text ).encode ('utf8' )),'cp1252' )
21202126 count = 0
21212127 if re .match (u'' r'\d' , anchor ):
21222128 anchor = u'_' + anchor
@@ -2160,7 +2166,7 @@ def subLink(match):
21602166 address = text = match .group (1 ).strip ()
21612167 if u'|' in text :
21622168 (address ,text ) = [chunk .strip () for chunk in text .split (u'|' ,1 )]
2163- if address == u'#' : address += unicode (urllib . quote (reWd .sub (u'' ,text ).encode ('utf8' )),'cp1252' )
2169+ if address == u'#' : address += unicode (quote (reWd .sub (u'' ,text ).encode ('utf8' )),'cp1252' )
21642170 if address .startswith (u'!' ):
21652171 newWindow = u' target="_blank"'
21662172 if address == text :
@@ -2281,7 +2287,7 @@ def subLink(match):
22812287 elif maHead :
22822288 lead ,text = maHead .group (1 ,2 )
22832289 text = re .sub (u' *=*#?$' ,'' ,text .strip ())
2284- anchor = unicode (urllib . quote (reWd .sub (u'' ,text ).encode ('utf8' )),'cp1252' )
2290+ anchor = unicode (quote (reWd .sub (u'' ,text ).encode ('utf8' )),'cp1252' )
22852291 level = len (lead )
22862292 if anchorHeaders :
22872293 if re .match (u'' r'\d' , anchor ):
0 commit comments