<commit_before>/*--------------------------------------------------------*\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: https://hprose.com                     |
|                                                          |
| client.dart                                              |
|                                                          |
| hprose Client for Dart.                                  |
|                                                          |
| LastModified: Feb 28, 2019                               |
| Author: <NAME> <<EMAIL>>                    |
|                                                          |
\*________________________________________________________*/

part of hprose.rpc.core;

abstract class Transport {
  Future<Uint8List> transport(Uint8List request, Context context);
  Future<void> abort();
}

abstract class TransportCreator<T extends Transport> {
  List<String> schemes;
  T create();
}

class Client {
  static final Map<String, TransportCreator> _creators = {};
  static final Map<String, String> _schemes = {};
  static void register<T extends Transport>(
      String name, TransportCreator<T> creator) {
    var schemes = creator.schemes;
    _creators[name] = creator;
    for (final scheme in schemes) {
      _schemes[scheme] = name;
    }
  }

  Map<String, Transport> _transports = {};
  Transport operator [](String name) => _transports[name];
  final Map<String, dynamic> requestHeaders = {};
  ClientCodec codec = DefaultClientCodec.instance;
  Duration timeout = new Duration(seconds: 30);
  List<Uri> _urilist = [];
  List<Uri> get uris => _urilist;
  set uris(List<Uri> value) {
    if (value.length > 0) {
      _urilist = List<Uri>.from(value);
      _urilist.shuffle();
    }
  }

  InvokeManager _invokeManager;
  IOManager _ioManager;
  Client([List<String> uris]) {
    if (!_creators.containsKey('mock')) {
      register<MockTransport>('mock', new MockTransportCreator());
    }
    _invokeManager = new InvokeManager(call);
    _ioManager = new IOManager(transport);
    for (final entry in _creators.entries) {
      _transports[entry.key] = entry.value.create();
    }
    if (uris != null) {
      _urilist.addAll(uris.map((uri) => Uri.parse(uri)));
    }
  }

  void use<Handler>(Handler handler) {
    if (handler is InvokeHandler) {
      _invokeManager.use(handler);
    } else if (handler is IOHandler) {
      _ioManager.use(handler);
    } else {
      throw new Exception('Invalid parameter type');
    }
  }

  void unuse<Handler>(Handler handler) {
    if (handler is InvokeHandler) {
      _invokeManager.unuse(handler);
    } else if (handler is IOHandler) {
      _ioManager.unuse(handler);
    } else {
      throw new Exception('Invalid parameter type');
    }
  }
<commit_msg>Update client.dart<commit_after>/*--------------------------------------------------------*\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: https://hprose.com                     |
|                                                          |
| client.dart                                              |
|                                                          |
| hprose Client for Dart.                                  |
|                                                          |
| LastModified: Feb 28, 2019                               |
| Author: <NAME> <<EMAIL>>                    |
|                                                          |
\*________________________________________________________*/

part of hprose.rpc.core;

abstract class Transport {
  Future<Uint8List> transport(Uint8List request, Context context);
  Future<void> abort();
}

abstract class TransportCreator<T extends Transport> {
  List<String> schemes;
  T create();
}

class _Proxy {
  final Client _client;
  String _namespace;
  _Proxy(this._client, this._namespace) {
    if (_namespace != null && _namespace.isNotEmpty) {
      _namespace += '_';
    } else {
      _namespace = '';
    }
  }
  String _getName(Symbol symbol) {
    String name = symbol.toString();
    return name.substring(8, name.length - 2);
  }
  noSuchMethod(Invocation mirror) {
    String name = this._namespace + _getName(mirror.memberName);
    if (mirror.isGetter) {
      return new _Proxy(this._client, name);
    }
    if (mirror.isMethod) {
      Type type = dynamic;
      if (mirror.typeArguments.isNotEmpty) {
        type = mirror.typeArguments.first;
      }
      ClientContext context;
      var args = [];
      if (mirror.positionalArguments.isNotEmpty) {
        args.addAll(mirror.positionalArguments);
        if (args.last is Context) {
          context = args.removeLast();
        }
      }
      if (mirror.namedArguments.isNotEmpty) {
        var namedArgs = new Map<String, dynamic>();
        mirror.namedArguments.forEach((name, value) {
          namedArgs[_getName(name)] = value;
        });
        if (namedArgs.containsKey('context') &&
            namedArgs['context'] is Context) {
          context = namedArgs.remove('context');
        }
        if (namedArgs.isNotEmpty) {
          args.add(namedArgs);
        }
      }
      if (context == null) {
        context = new ClientContext();
      }
      context.returnType = type;
      return _client.invoke(name, args, context);
    }
    super.noSuchMethod(mirror);
  }
}

class Client {
  static final Map<String, TransportCreator> _creators = {};
  static final Map<String, String> _schemes = {};
  static void register<T extends Transport>(
      String name, TransportCreator<T> creator) {
    var schemes = creator.schemes;
    _creators[name] = creator;
    for (final scheme in schemes) {
      _schemes[scheme] = name;
    }
  }

  Map<String, Transport> _transports = {};
  Transport operator [](String name) => _transports[name];
  final Map<String, dynamic> requestHeaders = {};
  ClientCodec codec = DefaultClientCodec.instance;
  Duration timeout = new Duration(seconds: 30);
  List<Uri> _urilist = [];
  List<Uri> get uris => _urilist;
  set uris(List<Uri> value) {
    if (value.length > 0) {
      _urilist = List<Uri>.from(value);
      _urilist.shuffle();
    }
  }

  InvokeManager _invokeManager;
  IOManager _ioManager;
  Client([List<String> uris]) {
    if (!_creators.containsKey('mock')) {
      register<MockTransport>('mock', new MockTransportCreator());
    }
    _invokeManager = new InvokeManager(call);
    _ioManager = new IOManager(transport);
    for (final entry in _creators.entries) {
      _transports[entry.key] = entry.value.create();
    }
    if (uris != null) {
      _urilist.addAll(uris.map((uri) => Uri.parse(uri)));
    }
  }

  dynamic useService([String namespace]) {
    return new _Proxy(this, namespace);
  }

  void use<Handler>(Handler handler) {
    if (handler is InvokeHandler) {
      _invokeManager.use(handler);
    } else if (handler is IOHandler) {
      _ioManager.use(handler);
    } else {
      throw new Exception('Invalid parameter type');
    }
  }

  void unuse<Handler>(Handler handler) {
    if (handler is InvokeHandler) {
      _invokeManager.unuse(handler);
    } else if (handler is IOHandler) {
      _ioManager.unuse(handler);
    } else {
      throw new Exception('Invalid parameter type');
    }
  }

{'fraction_non_alphanumeric': 0.1246680828465215, 'fraction_numerical': 0.003186404673393521, 'mean_word_length': 1.7644036697247707, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 54, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2240220', 'n_tokens_mistral': 2036, 'n_tokens_neox': 2001, 'n_words': 454}