prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  TypeError in Python 2.7
  https://github.com/pytorch/text/blob/a2795e5731d1b7c0298a1b5087bb8142e1c39d0b/torchtext/datasets/imdb.py#L32
  
  In python 2.7, it will report that `TypeError: 'encoding' is an invalid keyword argument for this function`.
  
  I replace `open` with `io.open` to fix it.
  
  </issue>
  <code>
  [start of torchtext/datasets/imdb.py]
  1 import os
  2 import glob
  3 
  4 from .. import data
  5 
  6 
  7 class IMDB(data.Dataset):
  8 
  9     urls = ['http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz']
  10     name = 'imdb'
  11     dirname = 'aclImdb'
  12 
  13     @staticmethod
  14     def sort_key(ex):
  15         return len(ex.text)
  16 
  17     def __init__(self, path, text_field, label_field, **kwargs):
  18         """Create an IMDB dataset instance given a path and fields.
  19 
  20         Arguments:
  21             path: Path to the dataset's highest level directory
  22             text_field: The field that will be used for text data.
  23             label_field: The field that will be used for label data.
  24             Remaining keyword arguments: Passed to the constructor of
  25                 data.Dataset.
  26         """
  27         fields = [('text', text_field), ('label', label_field)]
  28         examples = []
  29 
  30         for label in ['pos', 'neg']:
  31             for fname in glob.iglob(os.path.join(path, label, '*.txt')):
  32                 with open(fname, 'r', encoding="utf-8") as f:
  33                     text = f.readline()
  34                 examples.append(data.Example.fromlist([text, label], fields))
  35 
  36         super(IMDB, self).__init__(examples, fields, **kwargs)
  37 
  38     @classmethod
  39     def splits(cls, text_field, label_field, root='.data',
  40                train='train', test='test', **kwargs):
  41         """Create dataset objects for splits of the IMDB dataset.
  42 
  43         Arguments:
  44             text_field: The field that will be used for the sentence.
  45             label_field: The field that will be used for label data.
  46             root: Root dataset storage directory. Default is '.data'.
  47             train: The directory that contains the training examples
  48             test: The directory that contains the test examples
  49             Remaining keyword arguments: Passed to the splits method of
  50                 Dataset.
  51         """
  52         return super(IMDB, cls).splits(
  53             root=root, text_field=text_field, label_field=label_field,
  54             train=train, validation=None, test=test, **kwargs)
  55 
  56     @classmethod
  57     def iters(cls, batch_size=32, device=0, root='.data', vectors=None, **kwargs):
  58         """Creater iterator objects for splits of the IMDB dataset.
  59 
  60         Arguments:
  61             batch_size: Batch_size
  62             device: Device to create batches on. Use - 1 for CPU and None for
  63                 the currently active GPU device.
  64             root: The root directory that contains the imdb dataset subdirectory
  65             vectors: one of the available pretrained vectors or a list with each
  66                 element one of the available pretrained vectors (see Vocab.load_vectors)
  67 
  68             Remaining keyword arguments: Passed to the splits method.
  69         """
  70         TEXT = data.Field()
  71         LABEL = data.Field(sequential=False)
  72 
  73         train, test = cls.splits(TEXT, LABEL, root=root, **kwargs)
  74 
  75         TEXT.build_vocab(train, vectors=vectors)
  76         LABEL.build_vocab(train)
  77 
  78         return data.BucketIterator.splits(
  79             (train, test), batch_size=batch_size, device=device)
  80
  [end of torchtext/datasets/imdb.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/torchtext/datasets/imdb.py b/torchtext/datasets/imdb.py
  --- a/torchtext/datasets/imdb.py
  +++ b/torchtext/datasets/imdb.py
  @@ -1,5 +1,6 @@
   import os
   import glob
  +import io
   
   from .. import data
   
  @@ -29,7 +30,7 @@
   
           for label in ['pos', 'neg']:
               for fname in glob.iglob(os.path.join(path, label, '*.txt')):
  -                with open(fname, 'r', encoding="utf-8") as f:
  +                with io.open(fname, 'r', encoding="utf-8") as f:
                       text = f.readline()
                   examples.append(data.Example.fromlist([text, label], fields))
  
verification_info: {"golden_diff": "diff --git a/torchtext/datasets/imdb.py b/torchtext/datasets/imdb.py\n--- a/torchtext/datasets/imdb.py\n+++ b/torchtext/datasets/imdb.py\n@@ -1,5 +1,6 @@\n import os\n import glob\n+import io\n \n from .. import data\n \n@@ -29,7 +30,7 @@\n \n         for label in ['pos', 'neg']:\n             for fname in glob.iglob(os.path.join(path, label, '*.txt')):\n-                with open(fname, 'r', encoding=\"utf-8\") as f:\n+                with io.open(fname, 'r', encoding=\"utf-8\") as f:\n                     text = f.readline()\n                 examples.append(data.Example.fromlist([text, label], fields))\n", "issue": "TypeError in Python 2.7\nhttps://github.com/pytorch/text/blob/a2795e5731d1b7c0298a1b5087bb8142e1c39d0b/torchtext/datasets/imdb.py#L32\r\n\r\nIn python 2.7, it will report that `TypeError: 'encoding' is an invalid keyword argument for this function`.\r\n\r\nI replace `open` with `io.open` to fix it.\n", "before_files": [{"content": "import os\nimport glob\n\nfrom .. import data\n\n\nclass IMDB(data.Dataset):\n\n    urls = ['http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz']\n    name = 'imdb'\n    dirname = 'aclImdb'\n\n    @staticmethod\n    def sort_key(ex):\n        return len(ex.text)\n\n    def __init__(self, path, text_field, label_field, **kwargs):\n        \"\"\"Create an IMDB dataset instance given a path and fields.\n\n        Arguments:\n            path: Path to the dataset's highest level directory\n            text_field: The field that will be used for text data.\n            label_field: The field that will be used for label data.\n            Remaining keyword arguments: Passed to the constructor of\n                data.Dataset.\n        \"\"\"\n        fields = [('text', text_field), ('label', label_field)]\n        examples = []\n\n        for label in ['pos', 'neg']:\n            for fname in glob.iglob(os.path.join(path, label, '*.txt')):\n                with open(fname, 'r', encoding=\"utf-8\") as f:\n                    text = f.readline()\n                examples.append(data.Example.fromlist([text, label], fields))\n\n        super(IMDB, self).__init__(examples, fields, **kwargs)\n\n    @classmethod\n    def splits(cls, text_field, label_field, root='.data',\n               train='train', test='test', **kwargs):\n        \"\"\"Create dataset objects for splits of the IMDB dataset.\n\n        Arguments:\n            text_field: The field that will be used for the sentence.\n            label_field: The field that will be used for label data.\n            root: Root dataset storage directory. Default is '.data'.\n            train: The directory that contains the training examples\n            test: The directory that contains the test examples\n            Remaining keyword arguments: Passed to the splits method of\n                Dataset.\n        \"\"\"\n        return super(IMDB, cls).splits(\n            root=root, text_field=text_field, label_field=label_field,\n            train=train, validation=None, test=test, **kwargs)\n\n    @classmethod\n    def iters(cls, batch_size=32, device=0, root='.data', vectors=None, **kwargs):\n        \"\"\"Creater iterator objects for splits of the IMDB dataset.\n\n        Arguments:\n            batch_size: Batch_size\n            device: Device to create batches on. Use - 1 for CPU and None for\n                the currently active GPU device.\n            root: The root directory that contains the imdb dataset subdirectory\n            vectors: one of the available pretrained vectors or a list with each\n                element one of the available pretrained vectors (see Vocab.load_vectors)\n\n            Remaining keyword arguments: Passed to the splits method.\n        \"\"\"\n        TEXT = data.Field()\n        LABEL = data.Field(sequential=False)\n\n        train, test = cls.splits(TEXT, LABEL, root=root, **kwargs)\n\n        TEXT.build_vocab(train, vectors=vectors)\n        LABEL.build_vocab(train)\n\n        return data.BucketIterator.splits(\n            (train, test), batch_size=batch_size, device=device)\n", "path": "torchtext/datasets/imdb.py"}]}