Repository: pydicom/pydicom

Issue:
LookupError: unknown encoding: ISO_2022_IR_6
<!-- Instructions For Filing a Bug: https://github.com/pydicom/pydicom/blob/master/CONTRIBUTING.md#filing-bugs -->

#### Description
LookupError: unknown encoding: ISO_2022_IR_6

#### Steps/Code to Reproduce
```
import pydicom
dataset = pydicom.dcmread(filename)
print("Storage type.....:", dataset.SOPClassUID) # runs fine
pat_name = dataset.PatientName # throws error
x = dataset.PatientID # throws error
arr = dataset.pixel_array # runs fine
```
I cannot provide the original data, but pydicom runs fine on most images in my dataset -- it's only a couple images which have this problem. 

#### Expected Results
No error is thrown. 

#### Actual Results
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/afs/cs.stanford.edu/u/emmap1/.local/lib/python3.5/site-packages/pydicom/dataset.py", line 520, in __getattr__
    return self[tag].value
  File "/afs/cs.stanford.edu/u/emmap1/.local/lib/python3.5/site-packages/pydicom/dataset.py", line 599, in __getitem__
    self[tag] = DataElement_from_raw(data_elem, character_set)
  File "/afs/cs.stanford.edu/u/emmap1/.local/lib/python3.5/site-packages/pydicom/dataelem.py", line 493, in DataElement_from_raw
    value = convert_value(VR, raw, encoding)
  File "/afs/cs.stanford.edu/u/emmap1/.local/lib/python3.5/site-packages/pydicom/values.py", line 350, in convert_value
    encoding=encoding[1])
  File "/afs/cs.stanford.edu/u/emmap1/.local/lib/python3.5/site-packages/pydicom/values.py", line 234, in convert_string
    byte_string = byte_string.decode(encoding)
LookupError: unknown encoding: ISO_2022_IR_6
```

#### Versions
Linux-4.4.0-119-generic-x86_64-with-Ubuntu-16.04-xenial
Python 3.5.2
pydicom 1.1.0



Discussion:
pep8speaks: Hello @mrbean-bremen! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pydicom/charset.py`](https://github.com/mrbean-bremen/pydicom/blob/511cff9e6493d3533d38a6162fc5d9fe86c13c3e/pydicom/charset.py) !

 - There are no PEP8 issues in the file [`pydicom/tests/test_charset.py`](https://github.com/mrbean-bremen/pydicom/blob/511cff9e6493d3533d38a6162fc5d9fe86c13c3e/pydicom/tests/test_charset.py) !



Patch:
diff --git a/pydicom/charset.py b/pydicom/charset.py
index 59a0e62ca..120b6f22d 100644
--- a/pydicom/charset.py
+++ b/pydicom/charset.py
@@ -221,9 +221,15 @@ def convert_encodings(encodings):
         patched_encodings = []
         patched = {}
         for x in encodings:
-            if re.match('^ISO[^_]IR', x):
+            # check for spelling errors, but exclude the correct spelling
+            # standard encodings
+            if re.match('^ISO[^_]IR', x) is not None:
                 patched[x] = 'ISO_IR' + x[6:]
                 patched_encodings.append(patched[x])
+            # encodings with code extensions
+            elif re.match('^(?=ISO.2022.IR.)(?!ISO 2022 IR )', x) is not None:
+                patched[x] = 'ISO 2022 IR ' + x[12:]
+                patched_encodings.append(patched[x])
             else:
                 patched_encodings.append(x)
         if patched:


Test patch:
diff --git a/pydicom/tests/test_charset.py b/pydicom/tests/test_charset.py
index e6260ef50..1112bf3c8 100644
--- a/pydicom/tests/test_charset.py
+++ b/pydicom/tests/test_charset.py
@@ -150,6 +150,38 @@ class TestCharset(object):
         pydicom.charset.decode(elem, ['utf8'])
         assert u'Buc^Jérôme' == elem.value
 
+    def test_patched_code_extension_charset(self):
+        """Test some commonly misspelled charset values for code extensions."""
+        elem = DataElement(0x00100010, 'PN',
+                           b'Dionysios=\x1b\x2d\x46'
+                           b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2')
+        # correct encoding
+        pydicom.charset.decode(elem, ['ISO 2022 IR 100', 'ISO 2022 IR 126'])
+        assert u'Dionysios=Διονυσιος' == elem.value
+
+        # patched encoding shall behave correctly, but a warning is issued
+        with pytest.warns(UserWarning,
+                          match='Incorrect value for Specific Character Set '
+                                "'ISO_2022-IR 100' - assuming "
+                                "'ISO 2022 IR 100'"):
+            elem = DataElement(0x00100010, 'PN',
+                               b'Dionysios=\x1b\x2d\x46'
+                               b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2')
+            pydicom.charset.decode(elem,
+                                   ['ISO_2022-IR 100', 'ISO 2022 IR 126'])
+            assert u'Dionysios=Διονυσιος' == elem.value
+
+        with pytest.warns(UserWarning,
+                          match=r'Incorrect value for Specific Character Set '
+                                r"'ISO_2022_IR\+126' - assuming "
+                                r"'ISO 2022 IR 126'"):
+            elem = DataElement(0x00100010, 'PN',
+                               b'Dionysios=\x1b\x2d\x46'
+                               b'\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2')
+            pydicom.charset.decode(elem,
+                                   ['ISO 2022 IR 100', 'ISO_2022_IR+126'])
+            assert u'Dionysios=Διονυσιος' == elem.value
+
     def test_multi_charset_default_value(self):
         """Test that the first value is used if no escape code is given"""
         # regression test for #707