Skip to content

Commit

Permalink
Merge pull request pydicom#368 from scaramallion/write-updates
Browse files Browse the repository at this point in the history
Minor change to read_file docstring, use class name in exception messages
  • Loading branch information
darcymason authored Jun 6, 2017
2 parents adce60b + a04c795 commit e1674b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pydicom/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,10 @@ def save_as(self, filename, write_like_original=True):
# Ensure is_little_endian and is_implicit_VR exist
if not (hasattr(self, 'is_little_endian') and
hasattr(self, 'is_implicit_VR')):
raise AttributeError("'Dataset.is_little_endian' and "
"'Dataset.is_implicit_VR' must exist and be "
"set appropriately before saving.")
raise AttributeError("'{0}.is_little_endian' and "
"'{0}.is_implicit_VR' must exist and be "
"set appropriately before "
"saving.".format(self.__class__.__name__))

pydicom.write_file(filename, self, write_like_original)

Expand Down
10 changes: 6 additions & 4 deletions pydicom/filewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ def write_file(filename, dataset, write_like_original=True):
If (0002,0010) 'Transfer Syntax UID' is included then the user must ensure
it's value is compatible with the values for the `dataset.is_little_endian`
and `dataset.is_implicit_VR` attributes. For example, if is_little_endian
is True and is_implicit_VR is False then the Transfer Syntax UID must be
1.2.840.10008.1.2.1 'Explicit VR Little Endian'. See the DICOM standard
and is_implicit_VR are both True then the Transfer Syntax UID must be
1.2.840.10008.1.2 'Implicit VR Little Endian'. See the DICOM standard
Part 5 Section 10 for more information on Transfer Syntaxes.
Encoding
Expand Down Expand Up @@ -708,13 +708,15 @@ def write_file(filename, dataset, write_like_original=True):
if dataset.group_dataset(0x0002) != Dataset():
raise ValueError("File Meta Information Group Elements (0002,eeee) "
"should be in their own Dataset object in the "
"'Dataset.file_meta' attribute.")
"'{0}.file_meta' "
"attribute.".format(dataset.__class__.__name__))

# A preamble is required under the DICOM standard, however if
# `write_like_original` is True we treat it as optional
preamble = getattr(dataset, 'preamble', None)
if preamble and len(preamble) != 128:
raise ValueError("'Dataset.preamble' must be 128-bytes long.")
raise ValueError("'{0}.preamble' must be 128-bytes "
"long.".format(dataset.__class__.__name__))
if not preamble and not write_like_original:
# The default preamble is 128 0x00 bytes.
preamble = b'\x00' * 128
Expand Down

0 comments on commit e1674b5

Please sign in to comment.