Skip to content

Commit b36e40f

Browse files
author
Steve Canny
committed
doc: remove old Document shim object
1 parent 2bad8ed commit b36e40f

File tree

5 files changed

+8
-72
lines changed

5 files changed

+8
-72
lines changed

docx/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# encoding: utf-8
22

33
from docx.api import Document # noqa
4-
from docx.api import DocumentNew # noqa
54

65
__version__ = '0.8.1'
76

docx/api.py

+1-64
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
import os
1212

13-
from docx.enum.section import WD_SECTION
1413
from docx.opc.constants import CONTENT_TYPE as CT
1514
from docx.package import Package
1615

1716

18-
def DocumentNew(docx=None):
17+
def Document(docx=None):
1918
"""
2019
Return a |Document| object loaded from *docx*, where *docx* can be
2120
either a path to a ``.docx`` file (a string) or a file-like object. If
@@ -36,65 +35,3 @@ def _default_docx_path():
3635
"""
3736
_thisdir = os.path.split(__file__)[0]
3837
return os.path.join(_thisdir, 'templates', 'default.docx')
39-
40-
41-
class Document(object):
42-
"""
43-
Return a |Document| instance loaded from *docx*, where *docx* can be
44-
either a path to a ``.docx`` file (a string) or a file-like object. If
45-
*docx* is missing or ``None``, the built-in default document "template"
46-
is loaded.
47-
"""
48-
def __init__(self, docx=None):
49-
self._document = document = DocumentNew(docx)
50-
self._document_part = document._part
51-
self._package = document._part.package
52-
53-
def add_heading(self, text='', level=1):
54-
return self._document.add_heading(text, level)
55-
56-
def add_page_break(self):
57-
return self._document.add_page_break()
58-
59-
def add_paragraph(self, text='', style=None):
60-
return self._document.add_paragraph(text, style)
61-
62-
def add_picture(self, image_descriptor, width=None, height=None):
63-
return self._document.add_picture(image_descriptor, width, height)
64-
65-
def add_section(self, start_type=WD_SECTION.NEW_PAGE):
66-
return self._document.add_section(start_type)
67-
68-
def add_table(self, rows, cols, style='Light Shading Accent 1'):
69-
return self._document.add_table(rows, cols, style)
70-
71-
@property
72-
def core_properties(self):
73-
return self._document.core_properties
74-
75-
@property
76-
def inline_shapes(self):
77-
return self._document.inline_shapes
78-
79-
@property
80-
def paragraphs(self):
81-
return self._document.paragraphs
82-
83-
@property
84-
def part(self):
85-
return self._document.part
86-
87-
def save(self, path_or_stream):
88-
self._document.save(path_or_stream)
89-
90-
@property
91-
def sections(self):
92-
return self._document.sections
93-
94-
@property
95-
def styles(self):
96-
return self._document.styles
97-
98-
@property
99-
def tables(self):
100-
return self._document.tables

features/steps/api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import docx
1010

11-
from docx import DocumentNew
11+
from docx import Document
1212

1313
from helpers import test_docx
1414

@@ -24,12 +24,12 @@ def given_I_have_python_docx_installed(context):
2424

2525
@when('I call docx.Document() with no arguments')
2626
def when_I_call_docx_Document_with_no_arguments(context):
27-
context.document = DocumentNew()
27+
context.document = Document()
2828

2929

3030
@when('I call docx.Document() with the path of a .docx file')
3131
def when_I_call_docx_Document_with_the_path_of_a_docx_file(context):
32-
context.document = DocumentNew(test_docx('doc-default'))
32+
context.document = Document(test_docx('doc-default'))
3333

3434

3535
# then =====================================================

features/steps/shape.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def then_the_document_contains_the_inline_picture(context):
128128
picture_shape = document.inline_shapes[0]
129129
blip = picture_shape._inline.graphic.graphicData.pic.blipFill.blip
130130
rId = blip.embed
131-
image_part = document._document_part.related_parts[rId]
131+
image_part = document.part.related_parts[rId]
132132
image_sha1 = hashlib.sha1(image_part.blob).hexdigest()
133133
expected_sha1 = '79769f1e202add2e963158b532e36c2c0f76a70c'
134134
assert image_sha1 == expected_sha1, (

tests/test_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import docx
1414

15-
from docx.api import Document, DocumentNew
15+
from docx.api import Document
1616
from docx.opc.constants import CONTENT_TYPE as CT
1717

1818
from .unitutil.mock import function_mock, instance_mock, class_mock
@@ -22,13 +22,13 @@ class DescribeDocument(object):
2222

2323
def it_opens_a_docx_file(self, open_fixture):
2424
docx, Package_, document_ = open_fixture
25-
document = DocumentNew(docx)
25+
document = Document(docx)
2626
Package_.open.assert_called_once_with(docx)
2727
assert document is document_
2828

2929
def it_opens_the_default_docx_if_none_specified(self, default_fixture):
3030
docx, Package_, document_ = default_fixture
31-
document = DocumentNew()
31+
document = Document()
3232
Package_.open.assert_called_once_with(docx)
3333
assert document is document_
3434

0 commit comments

Comments
 (0)