Skip to content

Commit

Permalink
Merge aaba7f9 into 4398778
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 11, 2019
2 parents 4398778 + aaba7f9 commit 0b7033a
Show file tree
Hide file tree
Showing 18 changed files with 661 additions and 99 deletions.
73 changes: 73 additions & 0 deletions examples/echo/echos_tcp.py
@@ -0,0 +1,73 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Netius System
# Copyright (c) 2008-2018 Hive Solutions Lda.
#
# This file is part of Hive Netius System.
#
# Hive Netius System is free software: you can redistribute it and/or modify
# it under the terms of the Apache License as published by the Apache
# Foundation, either version 2.0 of the License, or (at your option) any
# later version.
#
# Hive Netius System is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Apache License for more details.
#
# You should have received a copy of the Apache License along with
# Hive Netius System. If not, see <http://www.apache.org/licenses/>.

__author__ = "João Magalhães <joamag@hive.pt>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2018 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """

import netius

import asyncio

class EchoServerClientProtocol(asyncio.Protocol):

def connection_made(self, transport):
peername = transport.get_extra_info("peername")
print("Connection from %s" % str(peername))
self.transport = transport

def data_received(self, data):
message = data.decode()
print("Data received: %s" % message)

print("Sending: %s" % message)
self.transport.write(data)

print("Closing the client socket")
self.transport.close()

loop = netius.get_loop(_compat = True)

coro = loop.create_server(EchoServerClientProtocol, "127.0.0.1", 8888)
server = loop.run_until_complete(coro)

print("Serving on %s" % (server.sockets[0].getsockname(),))

try: loop.run_forever()
except KeyboardInterrupt: pass

server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
2 changes: 2 additions & 0 deletions pylintrc
@@ -0,0 +1,2 @@
[messages control]
disable=C0103,C0111,C0121,C0123,C0301,C0302,C0321,C0325,C0326,C0330,C0412,C0413,E1128,W0102,W0106,W0108,W0150,W0201,W0212,W0221,W0401,W0603,W0613,W0621,W0622,W0702,W1113
6 changes: 4 additions & 2 deletions src/netius/base/__init__.py
Expand Up @@ -50,6 +50,7 @@
from . import protocol
from . import request
from . import server
from . import service
from . import stream
from . import tls
from . import transport
Expand All @@ -67,7 +68,7 @@
ensure_main, ensure_asyncio, ensure_loop, get_main, get_loop, get_event_loop,\
stop_loop, compat_loop, get_poll, build_future, ensure, ensure_pool
from .compat import BaseLoop, CompatLoop, is_compat, is_asyncio, build_datagram,\
connect_stream
connect_stream, serve_stream
from .config import conf, conf_prefix, conf_suffix, conf_s, conf_r, conf_d, conf_ctx
from .conn import OPEN, CLOSED, PENDING, CHUNK_SIZE, Connection
from .container import Container, ContainerServer
Expand All @@ -79,8 +80,9 @@
from .protocol import Protocol, DatagramProtocol, StreamProtocol
from .request import Request, Response
from .server import Server, DatagramServer, StreamServer
from .service import Service
from .stream import Stream
from .tls import fingerprint, match_fingerprint, match_hostname, dnsname_match,\
dump_certificate
from .transport import Transport, TransportDatagram, TransportStream
from .transport import Transport, TransportDatagram, TransportStream, ServerTransport
from .util import camel_to_underscore, verify
4 changes: 2 additions & 2 deletions src/netius/base/asynchronous.py
Expand Up @@ -40,10 +40,10 @@
# imports the base (old) version of the async implementation
# that should be compatible with all the available python
# interpreters, base collection of async library
from .async_old import * #@UnusedWildImport
from .async_old import * #@UnusedWildImport pylint: disable=W0614

# verifies if the current python interpreter version supports
# the new version of the async implementation and if that's the
# case runs the additional import of symbols, this should override
# most of the symbols that have just been created
if is_neo(): from .async_neo import * #@UnusedWildImport
if is_neo(): from .async_neo import * #@UnusedWildImport pylint: disable=W0614
6 changes: 3 additions & 3 deletions src/netius/base/client.py
Expand Up @@ -39,7 +39,7 @@

from . import request

from .common import * #@UnusedWildImport
from .common import * #@UnusedWildImport pylint: disable=W0614

BUFFER_SIZE = None
""" The size of the buffer that is going to be used in the
Expand Down Expand Up @@ -688,13 +688,13 @@ def connect(
# ensures that the proper socket family is defined in case the
# requested host value is unix socket oriented, this step greatly
# simplifies the process of created unix socket based clients
family = socket.AF_UNIX if host == "unix" else family
family = socket.AF_UNIX if host == "unix" else family #@UndefinedVariable pylint: disable=E1101

# verifies the kind of socket that is going to be used for the
# connect operation that is going to be performed, note that the
# unix type should be used with case as it does not exist in every
# operative system and may raised an undefined exceptions
is_unix = hasattr(socket, "AF_UNIX") and family == socket.AF_UNIX
is_unix = hasattr(socket, "AF_UNIX") and family == socket.AF_UNIX #@UndefinedVariable pylint: disable=E1101
is_inet = family in (socket.AF_INET, socket.AF_INET6)

# runs a series of default operation for the SSL related attributes
Expand Down

0 comments on commit 0b7033a

Please sign in to comment.