prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  New line character issue when using create_user management command 
  The create_user management command reads password from a text file created by the server admin. To run this command I tried creating this text file using VIM, nano and echo (` echo pass > password.txt` without using `-n` flag). Each and every time new line character was automatically added to the end of the file. So if I set the content of file as `helloworld` and try to login to the server by entering `helloworld` it would not let me login since `\n` is missing. It was not obvious to me that the extra `\n` added by editors was the reason behind the server rejecting the credentials.
  
  Should we remove the trailing `\n` character while reading the password from file?
  
  </issue>
  <code>
  [start of zerver/management/commands/create_user.py]
  1 import argparse
  2 import sys
  3 from typing import Any
  4 
  5 from django.core import validators
  6 from django.core.exceptions import ValidationError
  7 from django.core.management.base import CommandError
  8 from django.db.utils import IntegrityError
  9 
  10 from zerver.lib.actions import do_create_user
  11 from zerver.lib.initial_password import initial_password
  12 from zerver.lib.management import ZulipBaseCommand
  13 
  14 
  15 class Command(ZulipBaseCommand):
  16     help = """Create the specified user with a default initial password.
  17 
  18 Set tos_version=None, so that the user needs to do a ToS flow on login.
  19 
  20 Omit both <email> and <full name> for interactive user creation.
  21 """
  22 
  23     def add_arguments(self, parser: argparse.ArgumentParser) -> None:
  24         parser.add_argument('--this-user-has-accepted-the-tos',
  25                             dest='tos',
  26                             action="store_true",
  27                             help='Acknowledgement that the user has already accepted the ToS.')
  28         parser.add_argument('--password',
  29                             help='password of new user. For development only.'
  30                                  'Note that we recommend against setting '
  31                                  'passwords this way, since they can be snooped by any user account '
  32                                  'on the server via `ps -ef` or by any superuser with'
  33                                  'read access to the user\'s bash history.')
  34         parser.add_argument('--password-file',
  35                             help='The file containing the password of the new user.')
  36         parser.add_argument('email', metavar='<email>', nargs='?', default=argparse.SUPPRESS,
  37                             help='email address of new user')
  38         parser.add_argument('full_name', metavar='<full name>', nargs='?',
  39                             default=argparse.SUPPRESS,
  40                             help='full name of new user')
  41         self.add_realm_args(parser, True, "The name of the existing realm to which to add the user.")
  42 
  43     def handle(self, *args: Any, **options: Any) -> None:
  44         if not options["tos"]:
  45             raise CommandError("""You must confirm that this user has accepted the
  46 Terms of Service by passing --this-user-has-accepted-the-tos.""")
  47         realm = self.get_realm(options)
  48         assert realm is not None  # Should be ensured by parser
  49 
  50         try:
  51             email = options['email']
  52             full_name = options['full_name']
  53             try:
  54                 validators.validate_email(email)
  55             except ValidationError:
  56                 raise CommandError("Invalid email address.")
  57         except KeyError:
  58             if 'email' in options or 'full_name' in options:
  59                 raise CommandError("""Either specify an email and full name as two
  60 parameters, or specify no parameters for interactive user creation.""")
  61             else:
  62                 while True:
  63                     email = input("Email: ")
  64                     try:
  65                         validators.validate_email(email)
  66                         break
  67                     except ValidationError:
  68                         print("Invalid email address.", file=sys.stderr)
  69                 full_name = input("Full name: ")
  70 
  71         try:
  72             if options['password_file'] is not None:
  73                 with open(options['password_file']) as f:
  74                     pw = f.read()
  75             elif options['password'] is not None:
  76                 pw = options['password']
  77             else:
  78                 user_initial_password = initial_password(email)
  79                 if user_initial_password is None:
  80                     raise CommandError("Password is unusable.")
  81                 pw = user_initial_password
  82             do_create_user(
  83                 email,
  84                 pw,
  85                 realm,
  86                 full_name,
  87                 acting_user=None,
  88             )
  89         except IntegrityError:
  90             raise CommandError("User already exists.")
  91
  [end of zerver/management/commands/create_user.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/zerver/management/commands/create_user.py b/zerver/management/commands/create_user.py
  --- a/zerver/management/commands/create_user.py
  +++ b/zerver/management/commands/create_user.py
  @@ -71,7 +71,7 @@
           try:
               if options['password_file'] is not None:
                   with open(options['password_file']) as f:
  -                    pw = f.read()
  +                    pw = f.read().strip()
               elif options['password'] is not None:
                   pw = options['password']
               else:
  
verification_info: {"golden_diff": "diff --git a/zerver/management/commands/create_user.py b/zerver/management/commands/create_user.py\n--- a/zerver/management/commands/create_user.py\n+++ b/zerver/management/commands/create_user.py\n@@ -71,7 +71,7 @@\n         try:\n             if options['password_file'] is not None:\n                 with open(options['password_file']) as f:\n-                    pw = f.read()\n+                    pw = f.read().strip()\n             elif options['password'] is not None:\n                 pw = options['password']\n             else:\n", "issue": "New line character issue when using create_user management command \nThe create_user management command reads password from a text file created by the server admin. To run this command I tried creating this text file using VIM, nano and echo (` echo pass > password.txt` without using `-n` flag). Each and every time new line character was automatically added to the end of the file. So if I set the content of file as `helloworld` and try to login to the server by entering `helloworld` it would not let me login since `\\n` is missing. It was not obvious to me that the extra `\\n` added by editors was the reason behind the server rejecting the credentials.\r\n\r\nShould we remove the trailing `\\n` character while reading the password from file?\n", "before_files": [{"content": "import argparse\nimport sys\nfrom typing import Any\n\nfrom django.core import validators\nfrom django.core.exceptions import ValidationError\nfrom django.core.management.base import CommandError\nfrom django.db.utils import IntegrityError\n\nfrom zerver.lib.actions import do_create_user\nfrom zerver.lib.initial_password import initial_password\nfrom zerver.lib.management import ZulipBaseCommand\n\n\nclass Command(ZulipBaseCommand):\n    help = \"\"\"Create the specified user with a default initial password.\n\nSet tos_version=None, so that the user needs to do a ToS flow on login.\n\nOmit both <email> and <full name> for interactive user creation.\n\"\"\"\n\n    def add_arguments(self, parser: argparse.ArgumentParser) -> None:\n        parser.add_argument('--this-user-has-accepted-the-tos',\n                            dest='tos',\n                            action=\"store_true\",\n                            help='Acknowledgement that the user has already accepted the ToS.')\n        parser.add_argument('--password',\n                            help='password of new user. For development only.'\n                                 'Note that we recommend against setting '\n                                 'passwords this way, since they can be snooped by any user account '\n                                 'on the server via `ps -ef` or by any superuser with'\n                                 'read access to the user\\'s bash history.')\n        parser.add_argument('--password-file',\n                            help='The file containing the password of the new user.')\n        parser.add_argument('email', metavar='<email>', nargs='?', default=argparse.SUPPRESS,\n                            help='email address of new user')\n        parser.add_argument('full_name', metavar='<full name>', nargs='?',\n                            default=argparse.SUPPRESS,\n                            help='full name of new user')\n        self.add_realm_args(parser, True, \"The name of the existing realm to which to add the user.\")\n\n    def handle(self, *args: Any, **options: Any) -> None:\n        if not options[\"tos\"]:\n            raise CommandError(\"\"\"You must confirm that this user has accepted the\nTerms of Service by passing --this-user-has-accepted-the-tos.\"\"\")\n        realm = self.get_realm(options)\n        assert realm is not None  # Should be ensured by parser\n\n        try:\n            email = options['email']\n            full_name = options['full_name']\n            try:\n                validators.validate_email(email)\n            except ValidationError:\n                raise CommandError(\"Invalid email address.\")\n        except KeyError:\n            if 'email' in options or 'full_name' in options:\n                raise CommandError(\"\"\"Either specify an email and full name as two\nparameters, or specify no parameters for interactive user creation.\"\"\")\n            else:\n                while True:\n                    email = input(\"Email: \")\n                    try:\n                        validators.validate_email(email)\n                        break\n                    except ValidationError:\n                        print(\"Invalid email address.\", file=sys.stderr)\n                full_name = input(\"Full name: \")\n\n        try:\n            if options['password_file'] is not None:\n                with open(options['password_file']) as f:\n                    pw = f.read()\n            elif options['password'] is not None:\n                pw = options['password']\n            else:\n                user_initial_password = initial_password(email)\n                if user_initial_password is None:\n                    raise CommandError(\"Password is unusable.\")\n                pw = user_initial_password\n            do_create_user(\n                email,\n                pw,\n                realm,\n                full_name,\n                acting_user=None,\n            )\n        except IntegrityError:\n            raise CommandError(\"User already exists.\")\n", "path": "zerver/management/commands/create_user.py"}]}