11from __future__ import absolute_import , division , print_function
22
3+ import codecs
34import errno
45import logging
56import os
910
1011import click
1112import six
13+ import zope .interface
1214
1315from bs4 import BeautifulSoup
14- from characteristic import attributes
15- from zope .interface import Attribute , Interface
16+ from characteristic import attributes , Attribute
1617
1718
1819log = logging .getLogger (__name__ )
1920
2021
21- class IParser (Interface ):
22+ class IParser (zope . interface . Interface ):
2223 """
2324 A doc2dash documentation parser.
2425 """
25- name = Attribute ("Name of the parser" )
26- doc_path = Attribute (
26+ name = zope . interface . Attribute ("Name of the parser" )
27+ doc_path = zope . interface . Attribute (
2728 "The place to look for documentation for parsing and patching."
2829 )
2930
@@ -49,14 +50,22 @@ def find_and_patch_entry(soup, entry):
4950 """
5051
5152
52- @attributes (["name" , "type" , "anchor" ])
53+ @attributes ([
54+ Attribute ("name" , instance_of = six .text_type ),
55+ Attribute ("type" , instance_of = six .text_type ),
56+ Attribute ("anchor" , instance_of = six .text_type )
57+ ])
5358class TOCEntry (object ):
5459 """
5560 A symbol entry generated by the parser and to be added to the TOC.
5661 """
5762
5863
59- @attributes (["name" , "type" , "path" ])
64+ @attributes ([
65+ Attribute ("name" , instance_of = six .text_type ),
66+ Attribute ("type" , instance_of = six .text_type ),
67+ Attribute ("path" , instance_of = six .text_type )
68+ ])
6069class ParserEntry (object ):
6170 """
6271 A symbol as found by the parser that get yield for further processing.
@@ -84,7 +93,7 @@ def start(*args, **kwargs):
8493 return start
8594
8695
87- APPLE_REF_TEMPLATE = '//apple_ref/cpp/{}/{}'
96+ APPLE_REF_TEMPLATE = u '//apple_ref/cpp/{}/{}'
8897
8998
9099@coroutine
@@ -113,15 +122,15 @@ def patch_anchors(parser, show_progressbar):
113122 def patch_files (files ):
114123 for fname , entries in files :
115124 full_path = os .path .join (parser .doc_path , fname )
116- with open (full_path ) as fp :
125+ with codecs . open (full_path , mode = "r" , encoding = "utf-8" ) as fp :
117126 soup = BeautifulSoup (fp , 'lxml' )
118127 for entry in entries :
119128 if not parser .find_and_patch_entry (soup , entry ):
120129 log .debug ("Can't find anchor {} in {}."
121130 .format (entry .anchor ,
122131 click .format_filename (fname )))
123- with open (full_path , 'w' ) as fp :
124- fp .write (str ( soup ))
132+ with open (full_path , mode = "wb" ) as fp :
133+ fp .write (soup . encode ( "utf-8" ))
125134
126135 if show_progressbar is True :
127136 with click .progressbar (
0 commit comments