# -*- encoding: utf-8 -*-
# ! python3

import sys
import time
from contextlib import ContextDecorator

__all__ = ["Timer"]


class Timer(ContextDecorator):
    """
    Timer class that can be used both as a context manager and function/method decorator.

    Usage:

    >>> import math
    >>> import time
    >>>
    >>> with Timer():
    ...    for i in range(42):
    ...        print("{}! = {:.5}...".format(i**2, str(math.factorial(i**2))))
    >>>
    >>> @Timer(title="Second")
    ... def some_func():
    ...     time.sleep(1)
    >>>
    >>> with Timer(title="Some title") as t:
    ...    for i in range(42):
    ...        print("{}! = {:.5}...".format(i**2, str(math.factorial(i**2))))
    >>>
    >>> print(t.elapsed)
    """

    def __init__(self, title: str = "", print_title=True):
        self._title = title
        self._print = sys.stdout if print_title else print_title
        self._elapsed = 0

    def __float__(self) -> float:
        return float(self.elapsed)

    def __str__(self) -> str:
        """
        “informal” or nicely printable string representation of an object
        """
        return "Elapsed {}".format(self.__repr__())

    def __repr__(self) -> str:
        """
        “official” string representation of an object.
        """
        return str(float(self))

    def __enter__(self) -> 'Timer':
        self.start = time.perf_counter()

        return self

    def __exit__(self, *args):
        self._elapsed = time.perf_counter() - self.start
        if self._print:
            title = "[{}] ".format(self._title) if self._title else ""
            print('{title}Total time {total_seconds:.5f} seconds.'.format(title=title, total_seconds=self._elapsed),
                  file=self._print)

    @property
    def elapsed(self) -> float:
        return self._elapsed

@@ -94,16 +94,44 @@
 ecorator
+%0Afrom typing import Optional
 %0A%0A__all_
@@ -818,108 +818,470 @@
 itle
-=True):%0A        self._title = title%0A        self._print = sys.stdout if print_title else print_title
+: Optional%5Bbool%5D = True, print_file=None):%0A        %22%22%22%0A        Instantiate new Timer.%0A%0A        :param title: Title (prefix) that will be printed%0A        :param print_title: Should print elapsed time?%0A        :param print_file: File that will be passed to print function, see: https://docs.python.org/3/library/functions.html#print%0A        %22%22%22%0A        self._title = title%0A        self._print_title = print_title%0A        self._print_file = print_file or sys.stdout
 %0A   
@@ -1885,16 +1885,17 @@
 f.start%0A
+%0A
         
@@ -1908,16 +1908,22 @@
 f._print
+_title
 :%0A      
@@ -1999,22 +1999,34 @@
         
-print(
+formatted_title = 
 '%7Btitle%7D
@@ -2114,17 +2114,16 @@
 elapsed)
-,
 %0A       
@@ -2127,21 +2127,38 @@
         
-     
+print(formatted_title,
  file=se
@@ -2166,16 +2166,21 @@
 f._print
+_file
 )%0A%0A    @

add two new arguments: should print and print file