示例#1
0
def main():
    args = build_parser().parse_args()
    i3 = i3ipc.Connection()

    event_filter = true_filter

    if args.run is not None:
        event_filter = combine_filters(event_filter,
                                       change_filter('run', not args.run))

    if args.focus is not None:
        event_filter = combine_filters(event_filter,
                                       change_filter('focus', not args.focus))

    if args.quiet:
        formatter = quiet_formatter
    else:
        formatter = json.dumps

    handler = Handler(formatter, event_filter)

    WORKSPACE = "workspace"

    types = set(("ipc_shutdown", WORKSPACE, "output", "mode", "window",
                 "barconfig_update", "binding"))

    if args.workspace == True:
        types = set((WORKSPACE, ))
    elif args.workspace == False:
        types.remove(WORKSPACE)

    for name in types:
        i3.on(name, handler.handle)

    i3.main()
示例#2
0
 def find_types(self, seen):
     types = set([self])
     seen.add(self)
     seen.add(self.variable.deferred_type)
     self.dfs(types, seen)
     types.remove(self)
     return types
示例#3
0
 def __str__(self):
     types = list(self.types)
     if str != bytes:  # on Python 2 str == bytes
         if Instance(bytes) in types and Instance(str) in types:
             # we Union[bytes, str] -> AnyStr as late as possible so we avoid
             # corner cases like subclasses of bytes or str
             types.remove(Instance(bytes))
             types.remove(Instance(str))
             types.append(Instance(AnyStr))
     if len(types) == 1:
         return str(types[0])
     elif len(types) == 2 and None in types:
         type = [t for t in types if t is not None][0]
         return 'Optional[%s]' % type
     else:
         return 'Union[%s]' % (', '.join(sorted(str(t) for t in types)))
示例#4
0
 def __str__(self):
     types = list(self.types)
     if str != bytes:  # on Python 2 str == bytes
         if Instance(bytes) in types and Instance(str) in types:
             # we Union[bytes, str] -> AnyStr as late as possible so we avoid
             # corner cases like subclasses of bytes or str
             types.remove(Instance(bytes))
             types.remove(Instance(str))
             types.append(Instance(AnyStr))
     if len(types) == 1:
         return str(types[0])
     elif len(types) == 2 and None in types:
         type = [t for t in types if t is not None][0]
         return 'Optional[%s]' % type
     else:
         return 'Union[%s]' % (', '.join(sorted(str(t) for t in types)))
示例#5
0
    def strip_iterable(self):
        # type: () -> IOTypeHints
        """Removes outer Iterable (or equivalent) from output type.

    Only affects instances with simple output types, otherwise is a no-op.
    Does not modify self.

    Designed to be used with type hints from callables of ParDo, FlatMap, DoFn.
    Output type may be Optional[T], in which case the result of stripping T is
    used as the output type.
    Output type may be None/NoneType, in which case nothing is done.

    Example: Generator[Tuple(int, int)] becomes Tuple(int, int)

    Returns:
      A copy of this instance with a possibly different output type.

    Raises:
      ValueError if output type is simple and not iterable.
    """
        if self.output_types is None or not self.has_simple_output_type():
            return self
        output_type = self.output_types[0][0]
        if output_type is None or isinstance(output_type, type(None)):
            return self
        # If output_type == Optional[T]: output_type = T.
        if isinstance(output_type, typehints.UnionConstraint):
            types = list(output_type.union_types)
            if len(types) == 2:
                try:
                    types.remove(type(None))
                    output_type = types[0]
                except ValueError:
                    pass

        yielded_type = typehints.get_yielded_type(output_type)
        return self._replace(output_types=((yielded_type, ), {}),
                             origin=self._make_origin([self],
                                                      tb=False,
                                                      msg=['strip_iterable()'
                                                           ]))