Ejemplo n.º 1
0
 def __repr__(self):
     return "<{0}: [{1}]>".format(
         self.__class__.__name__,
         curtail_string(
             ", ".join(curtail_string(repr(elem), 40) for elem in self._elements),
             100,
         ),
     )
Ejemplo n.º 2
0
 def expand(segments, parse_context):
     """Expand the list of child segments using their `parse` methods."""
     segs = ()
     for stmt in segments:
         try:
             if not stmt.is_expandable:
                 parse_context.logger.info(
                     "[PD:%s] Skipping expansion of %s...",
                     parse_context.parse_depth,
                     stmt,
                 )
                 segs += (stmt,)
                 continue
         except Exception as err:
             # raise ValueError("{0} has no attribute `is_expandable`. This segment appears poorly constructed.".format(stmt))
             parse_context.logger.error(
                 "%s has no attribute `is_expandable`. This segment appears poorly constructed.",
                 stmt,
             )
             raise err
         if not hasattr(stmt, "parse"):
             raise ValueError(
                 "{0} has no method `parse`. This segment appears poorly constructed.".format(
                     stmt
                 )
             )
         parse_depth_msg = "Parse Depth {0}. Expanding: {1}: {2!r}".format(
             parse_context.parse_depth,
             stmt.__class__.__name__,
             curtail_string(stmt.raw, length=40),
         )
         parse_context.logger.info(frame_msg(parse_depth_msg))
         res = stmt.parse(parse_context=parse_context)
         if isinstance(res, BaseSegment):
             segs += (res,)
         else:
             # We might get back an iterable of segments
             segs += tuple(res)
     # Basic Validation
     check_still_complete(segments, segs, ())
     return segs
Ejemplo n.º 3
0
def join_segments_raw_curtailed(segments: Tuple["BaseSegment", ...],
                                length=20) -> str:
    """Make a string up to a certain length from an iterable of segments."""
    return curtail_string(join_segments_raw(segments), length=length)