Permalink
Browse files

version 3 without unit testing

  • Loading branch information...
1 parent 3698f17 commit fc3f36ba081e642926f89f7535ec48f3490d40be @paulhtremblay committed Jul 19, 2016
View
@@ -1,2 +0,0 @@
-# rtf2xml
-Converts MS Rich Text Format to XML
@@ -1,13 +1,8 @@
-$Revision: 1.18 $
-$Date: 2006/02/05 22:58:12 $
-
-Please see the docs for a complete explanation.
-
===========
VERSION:
===========
-1.33
+2.0
========
OVERVIEW
@@ -24,16 +19,17 @@ strucutre of the original RTF document.
INSTALLATION
============
-Please see the full documentation if this README does not help you.
-
+1. Type::
+
+ python setup.py install
+FOR earlier versions::
-1. Install python if you do not have it on your system. You can get
- python from http://python.org.
+ pip install rtf2xml
-2. Type:
-
- python setup.py install
+NOTE: I have not yet uploaded rtf2xml to the Python PyPi. I am waiting to get a
+permissions issue resolved. The installation downloaded with pip will work for
+python 2, but not python 3.
View
@@ -1,4 +1,4 @@
-"""
+"""
<ms_standard>
NON-BREAKING HYPEHN:_:8290:&#x2011;
LEFT DOUBLE QUOTATION MARK:ldblquote:8220:&#x201C;
@@ -3069,8 +3069,9 @@
HORIZONTAL TABULATION:TAB :9:&#x0009;
</ms_set_old>
<single_set>
-NULL:<’>:0:&#xnull;
+NULL:<>:0:&#xnull;
</single_set>
</unused>
"""
+
@@ -1,4 +1,4 @@
-import os, re, sys, codecs, rtf2xml.copy
+import os, re, sys, codecs, rtf2xml.copy
class Configure:
@@ -64,7 +64,7 @@ def get_configuration(self, type):
msg += ('Options take the form of option = value.\n')
msg += ('Please correct the configuration file "%s" before continuing\n'
% self.__configuration_file)
- raise self.__bug_handler, msg
+ raise self.__bug_handler(msg)
error = 1
att = fields[0]
value = fields[1]
@@ -76,7 +76,7 @@ def get_configuration(self, type):
if return_dict == 1:
msg = ('Please correct the configuration file "%s" before continuing\n'
% self.__configuration_file)
- raise self.__bug_handler, msg
+ raise self.__bug_handler(msg)
return return_dict
def __get_file_name(self):
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python
@@ -54,7 +54,7 @@ def __initiate_values(self):
rtf_dir = rtf2xml.configuration_dir.get_dir()
if not os.path.isfile(the_char_map):
msg = ('Cannot find character set "%s" \n' % the_char_map)
- raise self.__bug_hander, msg
+ raise self.__bug_hander(msg)
self.__sub_dict = {}
char_map_obj = rtf2xml.get_char_map.GetCharMap(the_char_map)
@@ -91,15 +91,15 @@ def encode_line(self, line):
line = line.replace('\t', '\\tab')
try:
line.encode('us-ascii')
- except UnicodeError, msg:
+ except UnicodeError as msg:
line = self.__standard_sub(line)
return line
def __standard_sub(self, line):
line = re.sub(self.__sub_string, self.__replace_func, line)
try:
line.encode('us-ascii')
- except UnicodeError, msg:
+ except UnicodeError as msg:
line = self.__encode_each_char(line)
return line
@@ -1,4 +1,4 @@
-#########################################################################
+#########################################################################
# #
# #
# copyright 2016 Paul Henry Tremblay #
@@ -128,7 +128,7 @@ def get_options(self):
if the_level:
try:
return_options['level'] = int(the_level)
- except ValueError, msg:
+ except ValueError as msg:
sys.stderr.write('The options "--level" must be a number.\n')
return_options['valid'] = 0
return return_options
@@ -1,4 +1,4 @@
-import sys
+import sys
class ParseOptions:
"""
@@ -381,7 +381,7 @@ def parse_options(self):
)
options, the_args = test_obj.parse_options()
- print options, the_args
+ print (options, the_args)
"""
this_options = ['--foo', '-o']
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"Convert a Microsoft RTF file to XML"
@@ -64,7 +64,7 @@
-import tempfile
+import tempfile
import rtf2xml.ParseRtf
import rtf2xml.get_options
@@ -88,7 +88,7 @@ def make_debug_dir(out_file):
if not os.path.isdir(debug_dir):
try:
os.mkdir(debug_dir)
- except OSError, msg:
+ except OSError as msg:
sys.stderr.write('Sorry, but cannot make a debug directory:\n')
sys.stderr.write(msg)
sys.stderr.wrtie('Script will now quit.\n')
@@ -149,62 +149,62 @@ def print_config_message(options_dict):
no_dtd = options_dict.get('no-dtd')
if in_file:
- print "in file is %s" % in_file
+ print ("in file is %s") % in_file
else:
- print "No input file specified"
+ print ("No input file specified")
if out_file:
- print "out file is %s" % out_file
+ print ("out file is %s" % out_file)
else:
- print "No output file specified"
+ print ("No output file specified")
if convert_symbol:
- print "script will convert Symbol font"
+ print ("script will convert Symbol font")
else:
- print "script will not convert Symol font"
+ print ("script will not convert Symol font")
if convert_zapf:
- print "script will convert Zapf Dingbat font"
+ print ("script will convert Zapf Dingbat font")
else:
- print "script will not convert Zapf Dingbat font"
+ print ("script will not convert Zapf Dingbat font")
if convert_wingdings:
- print "script will convert Wingdings font"
+ print ("script will convert Wingdings font")
else:
- print "script will not convert Wingdings font"
+ print ("script will not convert Wingdings font")
- print "the run level = '%s'" % run_level
+ print ("the run level = '%s'" % run_level)
if indent:
- print 'script will indent resulting XML'
+ print ('script will indent resulting XML')
else:
- print 'script will not indent resulting XML'
+ print ('script will not indent resulting XML')
if form_lists:
- print 'script will form lists'
+ print ('script will form lists')
else:
- print 'script will not form lists'
+ print ('script will not form lists')
if headings_to_sections:
- print 'script will convert headings to sections'
+ print ('script will convert headings to sections')
else:
- print 'script will not convert headings to sections'
+ print ('script will not convert headings to sections')
if group_styles:
- print 'script will group styles with the same name'
+ print ('script will group styles with the same name')
else:
- print 'script will not group styles with the same name'
+ print ('script will not group styles with the same name')
if group_borders:
- print 'script will group borders'
+ print ('script will group borders')
else:
- print 'script will not group borders'
+ print ('script will not group borders')
if empty_paragraphs:
- print 'script will print out empty paragraphs'
+ print ('script will print out empty paragraphs')
else:
- print 'script will ignore empty paragraphs'
+ print ('script will ignore empty paragraphs')
- print 'the script will print out the following dtd: "%s"' % dtd
+ print ('the script will print out the following dtd: "%s"') % dtd
def handle_options():
get_options_obj = rtf2xml.get_options.GetOptions(
@@ -272,10 +272,6 @@ def print_version():
rtf2xml %s
Written by Paul Tremblay.
-Copyright (C) 2003 Free Software Foundation, Inc.
-This is free software; see the source for copying conditions. There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
"""
% __version__
)
@@ -286,12 +282,12 @@ def Handle_Main():
this_run_level = options_dict.get('level')
if this_run_level > 3:
- parse_obj =rtf2xml.ParseRtf.ParseRtf(
- in_file = options_dict['in-file'],
+ parse_obj =rtf2xml.ParseRtf.ParseRtf(
+ in_file = options_dict['in-file'],
out_file = options_dict['the-out-file'],
out_dir = options_dict['out-dir'],
- dtd = options_dict.get('raw-dtd-path'),
- char_data = options_dict.get('char-data'),
+ dtd = options_dict.get('raw-dtd-path'),
+ char_data = options_dict.get('char-data'),
debug = options_dict['debug-dir'],
convert_symbol = options_dict['convert-symbol'],
convert_zapf = options_dict.get('convert-zapf'),
@@ -305,17 +301,18 @@ def Handle_Main():
group_borders = options_dict.get('group-borders'),
empty_paragraphs = options_dict.get('empty-paragraphs'),
no_dtd = 1,
- )
+ )
- parse_obj.parse_rtf()
+ xml_string = parse_obj.parse_rtf()
+ sys.stdout.write(xml_string)
else:
try:
- parse_obj =rtf2xml.ParseRtf.ParseRtf(
- in_file = options_dict['in-file'],
+ parse_obj =rtf2xml.ParseRtf.ParseRtf(
+ in_file = options_dict['in-file'],
out_file = options_dict['the-out-file'],
out_dir = options_dict['out-dir'],
- dtd = options_dict.get('raw-dtd-path'),
- char_data = options_dict.get('char-data'),
+ dtd = options_dict.get('raw-dtd-path'),
+ char_data = options_dict.get('char-data'),
debug = options_dict['debug-dir'],
convert_symbol = options_dict['convert-symbol'],
convert_zapf = options_dict.get('convert-zapf'),
@@ -329,13 +326,14 @@ def Handle_Main():
group_borders = options_dict.get('group-borders'),
empty_paragraphs = options_dict.get('empty-paragraphs'),
no_dtd = 1,
- )
+ )
- parse_obj.parse_rtf()
- except rtf2xml.ParseRtf.InvalidRtfException, msg:
+ xml_string = parse_obj.parse_rtf()
+ sys.stdout.write(xml_string)
+ except rtf2xml.ParseRtf.InvalidRtfException as msg:
quit(msg = msg)
- except rtf2xml.ParseRtf.RtfInvalidCodeException, msg:
+ except rtf2xml.ParseRtf.RtfInvalidCodeException as msg:
quit(msg = msg)
View
@@ -1,22 +1,15 @@
-#!/usr/bin/env python
+#!/usr/bin/env python
import sys, os, shutil
from distutils.core import setup
-def remove_build():
- if os.path.isdir('build'):
- shutil.rmtree('build')
# get the script name
def get_script_name():
- if os.path.exists(os.path.join('scripts' , 'rtf2xml')):
- return os.path.join('scripts', 'rtf2xml')
if os.path.exists(os.path.join('scripts', 'rtf2xml.py')):
return os.path.join('scripts', 'rtf2xml.py')
sys.stderr.write('Script not found\n')
- sys.stderr.write('Did you name it something other than rtf2xml.py?\n')
sys.exit(1)
-# remove_build()
script_name = get_script_name()
setup(name="rtf2xml",
@@ -25,18 +18,7 @@ def get_script_name():
author="Paul Tremblay",
author_email="paulhtremblay@gmail.com",
license = 'MIT',
- url = "http://rtf2xml.sourceforge.net/",
+ url = "https://github.com/paulhtremblay/rtf2xml",
packages=['rtf2xml'],
scripts=[script_name],
- # data_files = [
- # ('/usr/share/man/man1', ['data/rtf2xml.1']),
- # ],
)
-
-
-
-
-
-
-
-## os.remove('var_file')
Oops, something went wrong.

0 comments on commit fc3f36b

Please sign in to comment.