Skip to content
Myr

Added lazy file opening

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 81930b5 · Browse files · 14 files+415 added−248 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

14 files+415 added−248 removed

  • tests:+6 added−6 removed
  • other:+409 added−242 removed

14 files+415 added−248 removed

modified:click/__init__.py+12 added-6 removed
25 unmodified lines
26# Types27from .types import ParamType, File, Choice, IntRange, STRING, INT, FLOAT, \28 BOOL, UUID2930# Helper functions31from .helpers import prompt, confirm, get_terminal_size, echo, echo_via_pager30# Utilities31from .utils import echo3233# Terminal functions34from .termui import prompt, confirm, get_terminal_size, echo_via_pager3536# Exceptions34from .exceptions import UsageError, Abort37from .exceptions import ClickException, UsageError, FileError, Abort3839# Formatting40from .formatting import HelpFormatter, wrap_text41
11 unmodified lines
53 # Types54 'ParamType', 'File', 'Choice', 'IntRange', 'STRING', 'INT', 'FLOAT',55 'BOOL', 'UUID',5654 # Helper functions55 'prompt', 'confirm', 'get_terminal_size', 'echo', 'echo_via_pager',57 # Utilities58 'echo',5960 # Terminal functions61 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',6263 # Exceptions58 'UsageError', 'Abort',64 'ClickException', 'UsageError', 'FileError', 'Abort',6566 # Formatting67 'HelpFormatter', 'wrap_text',68]
modified:click/_compat.py+26 added
40 unmodified lines
41 if encoding is None:42 encoding = sys.stdin.encoding43 f = _wrap_stream_for_codec(f, encoding, errors)44 return f, False4546 def filename_to_ui(value):47 if isinstance(value, bytes):48 value = value.decode(sys.getfilesystemencoding(), 'replace')49 return value50else:51 import io52 text_type = str53 raw_input = input
29 unmodified lines
83 if encoding is not None:84 f = _wrap_stream_for_codec(f, encoding, errors)8586 return f, False8788 def filename_to_ui(value):89 if isinstance(value, bytes):90 value = value.decode(sys.getfilesystemencoding(), 'replace')91 else:92 value = value.encode('utf-8', 'surrogateescape') \93 .decode('utf-8', 'replace')94 return value959697def get_streerror(e, default=None):98 if hasattr(e, 'strerror'):99 msg = e.strerror100 else:101 if default is not None:102 msg = default103 else:104 msg = str(e)105 if isinstance(msg, bytes):106 msg = msg.decode('utf-8', 'replace')107 return msg
modified:click/core.py+6 added-8 removed
2 unmodified lines
3import codecs4from itertools import chain56from .types import convert_type, IntRange, BOOL7from .utils import make_str, make_default_short_help8from .exceptions import UsageError, Abort9from .helpers import prompt, confirm, echo7from .utils import make_str, make_default_short_help, echo8from .exceptions import ClickException, UsageError, Abort9from .termui import prompt, confirm10from .formatting import HelpFormatter11from .parser import OptionParser1213from ._compat import PY2, isidentifier
419 unmodified lines
433 ctx.exit()434 except (EOFError, KeyboardInterrupt):435 echo(file=sys.stderr)436 raise Abort()437 except UsageError as e:438 if e.ctx is not None:439 echo(e.ctx.get_usage() + '\n', file=sys.stderr)440 echo('Error: %s' % e.message, file=sys.stderr)441 sys.exit(2)437 except ClickException as e:438 e.show()439 sys.exit(e.exit_code)440 except Abort:441 echo('Aborted!', file=sys.stderr)442 sys.exit(1)443
594 unmodified lines
modified:click/decorators.py+1 added-1 removed
1import inspect23from functools import update_wrapper45from .helpers import echo5from .utils import echo678def pass_context(f):9 """Marks a callback that it wants to receive the current context
256 unmodified lines
modified:click/exceptions.py+38 added-6 removed
1from ._compat import PY21from ._compat import PY2, filename_to_ui2from .utils import echo344class UsageError(Exception):5 """An internal exception that signals a usage error. This typically6 aborts any further handling.7 """5class ClickException(Exception):6 """An exception that click can handle and show to the user.."""78 #: The exit code for this exception9 exit_code = 1109 def __init__(self, message, ctx=None):11 def __init__(self, message):12 if PY2:13 Exception.__init__(self, message.encode('utf-8'))14 else:15 Exception.__init__(self, message)16 self.message = message1718 def show(self, file=None):19 echo('Error: %s' % self.message)202122class UsageError(ClickException):23 """An internal exception that signals a usage error. This typically24 aborts any further handling.25 """26 exit_code = 22728 def __init__(self, message, ctx=None):29 ClickException.__init__(self, message)30 self.ctx = ctx3132 def show(self, file=None):33 echo(self.ctx.get_usage() + '\n', file=file)34 echo('Error: %s' % self.message, file=file)353637class FileError(ClickException):38 """Raised if a file cannot be opened."""3940 def __init__(self, filename, hint=None):41 ui_filename = filename_to_ui(filename)42 if hint is None:43 hint = 'unknown error'44 message = 'Could not open file %s: %s' % (filename, hint)45 ClickException.__init__(self, message)46 self.ui_filename = ui_filename47 self.filename = filename484950class Abort(RuntimeError):51 """An internal signalling exception that signals click to abort."""
modified:click/formatting.py+1 added-1 removed
1import textwrap2from contextlib import contextmanager34from .helpers import get_terminal_size4from .termui import get_terminal_size567def measure_table(rows):8 widths = {}
219 unmodified lines
deleted:click/helpers.py-195 removed
1import os2import sys3import struct45from ._compat import raw_input, PY2, text_type, string_types6from .utils import get_best_encoding7from .exceptions import Abort, UsageError8from .types import convert_type91011# The prompt functions to use. The doc tools currently override these12# functions to customize how they work.13visible_prompt_func = raw_input141516def hidden_prompt_func(prompt):17 import getpass18 return getpass.getpass(prompt)192021def prompt(text, default=None, hide_input=False,22 confirmation_prompt=False, type=None,23 value_proc=None):24 """Prompts a user for input. This is a convenience function that can25 be used to prompt a user for input later.2627 If the user aborts the input by sending a interrupt signal this28 function will catch it and raise a :exc:`Abort` exception.2930 :param text: the text to show for the prompt.31 :param default: the default value to use if no input happens. If this32 is not given it will prompt until it's aborted.33 :param hide_input: if this is set to true then the input value will34 be hidden.35 :param confirmation_prompt: asks for confirmation for the value.36 :param type: the type to use to check the value against.37 :param value_proc: if this parameter is provided it's a function that38 is invoked instead of the type conversion to39 convert a value.40 """41 result = None4243 def prompt_func(text):44 f = hide_input and hidden_prompt_func or visible_prompt_func45 try:46 return f(text)47 except (KeyboardInterrupt, EOFError):48 raise Abort()4950 if value_proc is None:51 value_proc = convert_type(type, default)5253 prompt = text54 if default is not None:55 prompt = '%s [%s]' % (prompt, default)56 prompt += ': '5758 while 1:59 while 1:60 value = prompt_func(prompt)61 if value:62 break63 # If a default is set and used, then the confirmation64 # prompt is always skipped because that's the only thing65 # that really makes sense.66 elif default is not None:67 return default68 try:69 result = value_proc(value)70 except UsageError as e:71 echo('Error: %s' % e.message)72 continue73 if not confirmation_prompt:74 return result75 while 1:76 value2 = prompt_func('Repeat for confirmation: ')77 if value2:78 break79 if value == value2:80 return result81 echo('Error: the two entered values do not match')828384def confirm(text, default=False, abort=False):85 """Prompts for confirmation (yes/no question).8687 If the user aborts the input by sending a interrupt signal this88 function will catch it and raise a :exc:`Abort` exception.8990 :param text: the question to ask.91 :param default: the default for the prompt.92 :param abort: if this is set to `True` a negative answer aborts the93 exception by raising :exc:`Abort`.94 """95 prompt = '%s [%s]: ' % (text, default and 'Yn' or 'yN')96 while 1:97 try:98 value = visible_prompt_func(prompt).lower().strip()99 except (KeyboardInterrupt, EOFError):100 raise Abort()101 if value in ('y', 'yes'):102 rv = True103 elif value in ('n', 'no'):104 rv = False105 elif value == '':106 rv = default107 else:108 echo('Error: invalid input')109 continue110 break111 if abort and not rv:112 raise Abort()113 return rv114115116def get_terminal_size():117 """Returns the current size of the terminal as tuple in the form118 ``(width, height)`` in columns and rows.119 """120 # If shutil has get_terminal_size() (Python 3.3 and later) use that121 if sys.version_info >= (3, 3):122 import shutil123 shutil_get_terminal_size = getattr(shutil, 'get_terminal_size', None)124 if shutil_get_terminal_size:125 sz = shutil_get_terminal_size()126 return sz.columns, sz.lines127128 def ioctl_gwinsz(fd):129 try:130 import fcntl131 import termios132 cr = struct.unpack(133 'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))134 except Exception:135 return136 return cr137138 cr = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2)139 if not cr:140 try:141 fd = os.open(os.ctermid(), os.O_RDONLY)142 try:143 cr = ioctl_gwinsz(fd)144 finally:145 os.close(fd)146 except Exception:147 pass148 if not cr or not cr[0] or not cr[1]:149 cr = (os.environ.get('LINES', 25),150 os.environ.get('COLUMNS', 80))151 return int(cr[1]), int(cr[0])152153154def echo(message=None, file=None):155 """Prints a message plus a newline to the given file or stdout. On156 first sight this looks like the print function but it has improved157 support for handling unicode data that does not fail no matter how158 badly configured the system is.159160 :param message: the message to print161 :param file: the file to write to (defaults to ``stdout``)162 """163 if file is None:164 file = sys.stdout165 if message is not None:166 if not isinstance(message, string_types):167 message = text_type(message)168 if message:169 if PY2 and isinstance(message, text_type):170 encoding = get_best_encoding(file)171 message = message.encode(encoding, 'replace')172 file.write(message)173 file.write('\n')174 file.flush()175176177def echo_via_pager(text):178 """This function takes a text and shows it via an environment specific179 pager on stdout.180181 :param text: the text to page.182 """183 if not isinstance(text, string_types):184 text = text_type(text)185186 if PY2 and isinstance(text, text_type):187 encoding = get_best_encoding(sys.stdout)188 text = text.encode(encoding, 'replace')189190 # Pydoc's pager is badly broken with LANG=C on Python 3 to the point191 # where it will corrupt the terminal. http://bugs.python.org/issue21398192 # I don't feel like reimplementing it given that it works on Python 2193 # and seems reasonably stable otherwise.194 import pydoc195 pydoc.pager(text)
added:click/termui.py+172 added
1import os2import sys3import struct45from ._compat import raw_input, PY2, text_type, string_types6from .utils import get_best_encoding, echo7from .exceptions import Abort, UsageError8from .types import convert_type91011# The prompt functions to use. The doc tools currently override these12# functions to customize how they work.13visible_prompt_func = raw_input141516def hidden_prompt_func(prompt):17 import getpass18 return getpass.getpass(prompt)192021def prompt(text, default=None, hide_input=False,22 confirmation_prompt=False, type=None,23 value_proc=None):24 """Prompts a user for input. This is a convenience function that can25 be used to prompt a user for input later.2627 If the user aborts the input by sending a interrupt signal this28 function will catch it and raise a :exc:`Abort` exception.2930 :param text: the text to show for the prompt.31 :param default: the default value to use if no input happens. If this32 is not given it will prompt until it's aborted.33 :param hide_input: if this is set to true then the input value will34 be hidden.35 :param confirmation_prompt: asks for confirmation for the value.36 :param type: the type to use to check the value against.37 :param value_proc: if this parameter is provided it's a function that38 is invoked instead of the type conversion to39 convert a value.40 """41 result = None4243 def prompt_func(text):44 f = hide_input and hidden_prompt_func or visible_prompt_func45 try:46 return f(text)47 except (KeyboardInterrupt, EOFError):48 raise Abort()4950 if value_proc is None:51 value_proc = convert_type(type, default)5253 prompt = text54 if default is not None:55 prompt = '%s [%s]' % (prompt, default)56 prompt += ': '5758 while 1:59 while 1:60 value = prompt_func(prompt)61 if value:62 break63 # If a default is set and used, then the confirmation64 # prompt is always skipped because that's the only thing65 # that really makes sense.66 elif default is not None:67 return default68 try:69 result = value_proc(value)70 except UsageError as e:71 echo('Error: %s' % e.message)72 continue73 if not confirmation_prompt:74 return result75 while 1:76 value2 = prompt_func('Repeat for confirmation: ')77 if value2:78 break79 if value == value2:80 return result81 echo('Error: the two entered values do not match')828384def confirm(text, default=False, abort=False):85 """Prompts for confirmation (yes/no question).8687 If the user aborts the input by sending a interrupt signal this88 function will catch it and raise a :exc:`Abort` exception.8990 :param text: the question to ask.91 :param default: the default for the prompt.92 :param abort: if this is set to `True` a negative answer aborts the93 exception by raising :exc:`Abort`.94 """95 prompt = '%s [%s]: ' % (text, default and 'Yn' or 'yN')96 while 1:97 try:98 value = visible_prompt_func(prompt).lower().strip()99 except (KeyboardInterrupt, EOFError):100 raise Abort()101 if value in ('y', 'yes'):102 rv = True103 elif value in ('n', 'no'):104 rv = False105 elif value == '':106 rv = default107 else:108 echo('Error: invalid input')109 continue110 break111 if abort and not rv:112 raise Abort()113 return rv114115116def get_terminal_size():117 """Returns the current size of the terminal as tuple in the form118 ``(width, height)`` in columns and rows.119 """120 # If shutil has get_terminal_size() (Python 3.3 and later) use that121 if sys.version_info >= (3, 3):122 import shutil123 shutil_get_terminal_size = getattr(shutil, 'get_terminal_size', None)124 if shutil_get_terminal_size:125 sz = shutil_get_terminal_size()126 return sz.columns, sz.lines127128 def ioctl_gwinsz(fd):129 try:130 import fcntl131 import termios132 cr = struct.unpack(133 'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))134 except Exception:135 return136 return cr137138 cr = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2)139 if not cr:140 try:141 fd = os.open(os.ctermid(), os.O_RDONLY)142 try:143 cr = ioctl_gwinsz(fd)144 finally:145 os.close(fd)146 except Exception:147 pass148 if not cr or not cr[0] or not cr[1]:149 cr = (os.environ.get('LINES', 25),150 os.environ.get('COLUMNS', 80))151 return int(cr[1]), int(cr[0])152153154def echo_via_pager(text):155 """This function takes a text and shows it via an environment specific156 pager on stdout.157158 :param text: the text to page.159 """160 if not isinstance(text, string_types):161 text = text_type(text)162163 if PY2 and isinstance(text, text_type):164 encoding = get_best_encoding(sys.stdout)165 text = text.encode(encoding, 'replace')166167 # Pydoc's pager is badly broken with LANG=C on Python 3 to the point168 # where it will corrupt the terminal. http://bugs.python.org/issue21398169 # I don't feel like reimplementing it given that it works on Python 2170 # and seems reasonably stable otherwise.171 import pydoc172 pydoc.pager(text)
modified:click/types.py+29 added-16 removed
1import sys2import uuid34from ._compat import open_stream, text_type4from ._compat import open_stream, text_type, filename_to_ui, get_streerror5from .exceptions import UsageError6from .utils import safecall6from .utils import safecall, LazyFile789class ParamType(object):10 """Helper for converting values through types. The following is
207 unmodified lines
218 See :ref:`file-args` for more information.219 """220 name = 'filename'221222 def __init__(self, mode='r', encoding=None, errors='strict'):222 def __init__(self, mode='r', encoding=None, errors='strict', lazy=None):223 self.mode = mode224 self.encoding = encoding225 self.errors = errors226 self.lazy = lazy227228 def resolve_lazy_flag(self, value):229 if self.lazy is not None:230 return self.lazy231 if value == '-':232 return False233 elif 'w' in self.mode:234 return True235 return False236237 def convert(self, value, param, ctx):238 try:239 if hasattr(value, 'read') or hasattr(value, 'write'):240 return value231 f, was_opened = open_stream(value, self.mode, self.encoding,232 self.errors)241242 lazy = self.resolve_lazy_flag(value)243244 if lazy:245 f = LazyFile(value, self.mode, self.encoding, self.errors)246 if ctx is not None:247 ctx.call_on_close(f.close_intelligently)248 return f249250 f, should_close = open_stream(value, self.mode,251 self.encoding, self.errors)252 # If a context is provided we automatically close the file253 # at the end of the context execution (or flush out). If a254 # context does not exist it's the caller's responsibility to255 # properly close the file. This for instance happens when the256 # type is used with prompts.257 if ctx is not None:239 if was_opened:258 if should_close:259 ctx.call_on_close(safecall(f.close))260 else:261 ctx.call_on_close(safecall(f.flush))262 return f263 except (IOError, OSError) as e:245 if isinstance(value, bytes):246 value = value.decode(sys.getfilesystemencoding(), 'replace')247 if hasattr(e, 'strerror'):248 msg = e.strerror249 else:250 msg = str(e)251 if isinstance(msg, bytes):252 msg = msg.decode('utf-8', 'replace')253 self.fail('Could not open file %s: %s' % (value, msg),254 param, ctx)264 self.fail('Could not open file: %s: %s' % (265 filename_to_ui(value),266 get_streerror(e),267 ), param, ctx)268269270def convert_type(ty, default=None):271 """Converts a callable or python ty into the most appropriate param
43 unmodified lines
modified:click/utils.py+93 added-1 removed
1import sys2import codecs3from collections import deque45from ._compat import text_type5from ._compat import text_type, open_stream, get_streerror, string_types, PY2678def unpack_args(args, nargs_spec):9 """Given an iterable of arguments and an iterable of nargs specifications
111 unmodified lines
121 break122 total_length += new_length123124 return ''.join(result)125126127class LazyFile(object):128 """A lazy file works like a regular file but it does not fully open129 the file but it does perform some basic checks early to see if the130 filename parameter does make sense. This is useful for safely opening131 files for writing.132 """133134 def __init__(self, filename, mode='r', encoding=None, errors='strict'):135 self.name = filename136 self.mode = mode137 self.encoding = encoding138 self.errors = errors139140 if filename == '-':141 self._f, self.should_close = open_stream(filename, mode,142 encoding, errors)143 else:144 if 'r' in mode:145 # Open and close the file in case we're opening it for146 # reading so that we can catch at least some errors in147 # some cases early.148 open(filename, mode, encoding, errors).close()149 self._f = None150 self.should_close = True151152 def __getattr__(self, name):153 return getattr(self.open(), name)154155 def __repr__(self):156 if self._f is not None:157 return repr(self._f)158 return '<unopened file %r %s>' % (self.name, self.mode)159160 def open(self):161 """Opens the file if it's not yet open. This call might fail with162 a :exc:`FileError`. Not handling this error will produce an error163 that click shows.164 """165 if self._f is not None:166 return self._f167 try:168 rv, self.should_close = open_stream(self.name, self.mode,169 self.encoding,170 self.errors)171 except (IOError, OSError) as e:172 from .exceptions import FileError173 raise FileError(self.name, hint=get_streerror(e))174 self._f = rv175 return rv176177 def close(self):178 """Closes the underlying file, no matter what."""179 if self._f is not None:180 self._f.close()181182 def close_intelligently(self):183 """This function only closes the file if it was opened by the lazy184 file wrapper. For instance this will never close stdin.185 """186 if self.should_close:187 self.close()188189 def __enter__(self):190 return self191192 def __exit__(self, exc_type, exc_value, tb):193 self.close_intelligently()194195196def echo(message=None, file=None):197 """Prints a message plus a newline to the given file or stdout. On198 first sight this looks like the print function but it has improved199 support for handling unicode data that does not fail no matter how200 badly configured the system is.201202 :param message: the message to print203 :param file: the file to write to (defaults to ``stdout``)204 """205 if file is None:206 file = sys.stdout207 if message is not None:208 if not isinstance(message, string_types):209 message = text_type(message)210 if message:211 if PY2 and isinstance(message, text_type):212 encoding = get_best_encoding(file)213 message = message.encode(encoding, 'replace')214 file.write(message)215 file.write('\n')216 file.flush()
modified:docs/api.rst+6 added-2 removed
29 unmodified lines
30.. autofunction:: pass_obj3132.. autofunction:: make_pass_decorator3334Helper Functions35----------------34Utilities35---------3637.. autofunction:: echo3839.. autofunction:: echo_via_pager
56 unmodified lines
9697Exceptions98----------99100.. autoexception:: ClickException101102.. autoexception:: Abort103104.. autoexception:: UsageError105106.. autoexception:: FileError107108Formatting109----------110111.. autoclass:: HelpFormatter
3 unmodified lines
modified:docs/arguments.rst+19 added
93 unmodified lines
94 invoke(inout, args=['-', 'hello.txt'], input=['hello'],95 terminate_input=True)96 invoke(inout, args=['hello.txt', '-'])9798File Opening Safety99-------------------100101The :class:`FileType` type has one problem it needs to deal with and that102is to decide when to open a file. The default behavior is to be103"intelligent" about it. What this means is that it will open stdin/stdout104and files opened for reading immediately. This will directly give the105user feedback when a file cannot be opened. But it will only open files106for writing the first time an IO operation is performed by wrapping the107file automatically in a special wrapper.108109This behavior can be forced by passing ``lazy=True`` or ``lazy=False`` to110the constructor. If the file is openened lazily it will fail on first IO111operation by raising an :exc:`FileError`.112113Since files opened for writing will typically immediatley empty the file,114the lazy mode should really only be disabled if the developer is 100% sure115that this is intended behavior.116117Environment Variables118---------------------119120Like options, arguments can also get values from an environment variable.
26 unmodified lines
modified:docs/clickdoctools.py+6 added-6 removed
70 unmodified lines
71 return input.readline().rstrip('\r\n')7273 sys.stdout = output74 sys.stderr = output75 old_visible_prompt_func = click.helpers.visible_prompt_func76 old_hidden_prompt_func = click.helpers.hidden_prompt_func77 click.helpers.visible_prompt_func = visible_input78 click.helpers.hidden_prompt_func = hidden_input75 old_visible_prompt_func = click.termui.visible_prompt_func76 old_hidden_prompt_func = click.termui.hidden_prompt_func77 click.termui.visible_prompt_func = visible_input78 click.termui.hidden_prompt_func = hidden_input7980 old_env = {}81 try:82 if env:
11 unmodified lines
94 else:95 os.environ[key] = value96 sys.stdout = sys.__stdout__97 sys.stderr = sys.__stderr__98 click.helpers.visible_prompt_func = old_visible_prompt_func99 click.helpers.hidden_prompt_func = old_hidden_prompt_func98 click.termui.visible_prompt_func = old_visible_prompt_func99 click.termui.hidden_prompt_func = old_hidden_prompt_func100101102@contextlib.contextmanager103def isolated_filesystem():
153 unmodified lines
modified:tests/conftest.py+6 added-6 removed
90 unmodified lines
91 sys.stdout.write((prompt or '') + '\n')92 sys.stdout.flush()93 return input.readline().rstrip('\r\n')9495 old_visible_prompt_func = click.helpers.visible_prompt_func96 old_hidden_prompt_func = click.helpers.hidden_prompt_func97 click.helpers.visible_prompt_func = visible_input98 click.helpers.hidden_prompt_func = hidden_input95 old_visible_prompt_func = click.termui.visible_prompt_func96 old_hidden_prompt_func = click.termui.hidden_prompt_func97 click.termui.visible_prompt_func = visible_input98 click.termui.hidden_prompt_func = hidden_input99100 old_env = {}101 try:102 if env:
11 unmodified lines
114 else:115 os.environ[key] = value116 sys.stdout = old_stdout117 sys.stderr = old_stderr118 click.helpers.visible_prompt_func = old_visible_prompt_func119 click.helpers.hidden_prompt_func = old_hidden_prompt_func118 click.termui.visible_prompt_func = old_visible_prompt_func119 click.termui.hidden_prompt_func = old_hidden_prompt_func120121 def invoke(self, cli, args):122 with self.isolation() as out:123 exception = None
34 unmodified lines