def register(app, uri, file_or_directory, pattern,<EOL>use_modified_since, use_content_range):<EOL>
<EOL>if not path.isfile(file_or_directory):<EOL><INDENT>uri += '<STR_LIT>' + pattern + '<STR_LIT:>>'<EOL><DEDENT>async def _handler(request, file_uri=None):<EOL><INDENT>if file_uri and '<STR_LIT>' in file_uri:<EOL><INDENT>raise InvalidUsage("<STR_LIT>")<EOL><DEDENT>root_path = file_path = file_or_directory<EOL>if file_uri:<EOL><INDENT>file_path = path.join(<EOL>file_or_directory, sub('<STR_LIT>', '<STR_LIT>', file_uri))<EOL><DEDENT>file_path = path.abspath(unquote(file_path))<EOL>if not file_path.startswith(path.abspath(unquote(root_path))):<EOL><INDENT>raise FileNotFound('<STR_LIT>',<EOL>path=file_or_directory,<EOL>relative_url=file_uri)<EOL><DEDENT>try:<EOL><INDENT>headers = {}<EOL>stats = None<EOL>if use_modified_since:<EOL><INDENT>stats = await stat(file_path)<EOL>modified_since = strftime(<EOL>'<STR_LIT>', gmtime(stats.st_mtime))<EOL>if request.headers.get('<STR_LIT>') == modified_since:<EOL><INDENT>return HTTPResponse(status=<NUM_LIT>)<EOL><DEDENT>headers['<STR_LIT>'] = modified_since<EOL><DEDENT>_range = None<EOL>if use_content_range:<EOL><INDENT>_range = None<EOL>if not stats:<EOL><INDENT>stats = await stat(file_path)<EOL><DEDENT>headers['<STR_LIT>'] = '<STR_LIT>'<EOL>headers['<STR_LIT>'] = str(stats.st_size)<EOL>if request.method != '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>_range = ContentRangeHandler(request, stats)<EOL><DEDENT>except HeaderNotFound:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>del headers['<STR_LIT>']<EOL>for key, value in _range.headers.items():<EOL><INDENT>headers[key] = value<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if request.method == '<STR_LIT>':<EOL><INDENT>return HTTPResponse(<EOL>headers=headers,<EOL>content_type=guess_type(file_path)[<NUM_LIT:0>] or '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>return await file(file_path, headers=headers, _range=_range)<EOL><DEDENT><DEDENT>except ContentRangeError:<EOL><INDENT>raise<EOL><DEDENT>except Exception:<EOL><INDENT>raise FileNotFound('<STR_LIT>',<EOL>path=file_or_directory,<EOL>relative_url=file_uri)<EOL><DEDENT><DEDENT>app.route(uri, methods=['<STR_LIT:GET>', '<STR_LIT>'])(_handler)<EOL>
Register a static directory handler with Mach9 by adding a route to the
router and registering a handler.

:param app: Mach9
:param file_or_directory: File or directory path to serve from
:param uri: URL to serve from
:param pattern: regular expression used to match files in the URL
:param use_modified_since: If true, send file modified time, and return
                           not modified if the browser's matches the
                           server's
:param use_content_range: If true, process header for range requests
                          and sends the file part that is requested