예제 #1
0
def main(shp):
    shp, _ = os.path.splitext(shp)
    with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
        with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
            w.fields = r.fields[1:]  # skip first deletion field
            for rec in r.iterShapeRecords():
                w.record(*rec.record)
                w.shape(rec.shape)
예제 #2
0
파일: main.py 프로젝트: jelly/c3bottles
def dp_all_labels():
    output = PdfFileWriter()
    for dp in db.session.query(DropPoint).all():
        if not dp.removed:
            output.addPage(PdfFileReader(IO(_pdf(dp.number))).getPage(0))
    f = IO()
    output.write(f)
    return Response(f.getvalue(), mimetype="application/pdf")
예제 #3
0
 def load_weights(self, model, data, read_rank):
     weights_size = data['_weights_size_']
     str_weights = ctypes.create_string_buffer(weights_size)
     self.lib.pbt_ds_get_weights(read_rank, str_weights, weights_size,
                                 self.mpi_comm_self)
     model.set_weights(pkl.load(IO(str_weights)))
     self.release_read_lock(read_rank)
예제 #4
0
def resize(file_, max_width=0, max_height=0, crop=0):
    max_width = int(max_width)
    max_height = int(max_height)
    crop = int(crop)

    if max_width is 0 and max_height is 0:
        return file_

    max_width = 9999 if max_width is 0 else max_width
    max_height = 9999 if max_height is 0 else max_height

    size = (max_width, max_height)
    image = Image.open(file_)

    if image.mode == "RGBA":
        image.load()
        background = Image.new("RGB", image.size, (255, 255, 255))
        background.paste(image, mask=image.split()[3])
        image = background

    temp = IO()

    if crop is 1:
        image = ImageOps.fit(image, size, Image.ANTIALIAS)
    else:
        image.thumbnail(size, Image.ANTIALIAS)

    image.save(temp, "jpeg")
    temp.seek(0)

    return SimpleUploadedFile(file_.name,
                              temp.read(),
                              content_type="image/jpeg")
예제 #5
0
    def makefile(self, flags, *args, **kwargs):
        # type: (str, *Any, **Any) -> Union[IO, IOProxy]
        if flags.startswith('w'):
            return self.body

        if sys.version_info[0] > 2:
            output = bytes("GET {}".format(self.path), 'ascii')
        else:
            output = "GET {}".format(self.path)
        return IO(output)
예제 #6
0
 def resize(self, image, name, size):
     if image.size[0] > size[0] or image.size[1] > size[1]:
         new_mode = 'RGB'
         if image.mode in ('RGBA', 'LA') or (image.mode == 'P' and
                                             'transparency' in image.info):
             # image is transparent
             if image.mode != 'RGBA':
                 image = image.convert('RGBA')
             base = Image.new('RGBA', image.size, '#fff')
             base.paste(image, mask=image)
             image = base
         if image.mode != new_mode:
             image = image.convert(new_mode)
         image.thumbnail(size, resample=Image.ANTIALIAS)
         image_resized = IO()
         image.save(image_resized, 'jpeg')
         path = default_storage.save(name, image_resized)
     else:
         path = default_storage.save(name, image.fp)
     return path
예제 #7
0
def resize(file_, max_width=0, max_height=0, crop=0):
    max_width = int(max_width)
    max_height = int(max_height)
    crop = int(crop)

    if (max_width is 0 and max_height is 0):
        return file_

    max_width = 9999 if max_width is 0 else max_width
    max_height = 9999 if max_height is 0 else max_height

    size = (max_width, max_height)
    image = Image.open(file_)

    if (image.mode == 'RGBA'):
        image.load()
        background = Image.new('RGB', image.size, (255, 255, 255))
        background.paste(image, mask=image.split()[3])
        image = background

    temp = IO()

    if (crop is 1):
        image = ImageOps.fit(image, size, Image.ANTIALIAS)
    else:
        image.thumbnail(size, Image.ANTIALIAS)

    if 'png' in file_.content_type:
        image.save(temp, 'png')
    elif 'gif' in file_.content_type:
        image.save(temp, 'gif')
    else:
        image.save(temp, 'jpeg')

    temp.seek(0)

    return SimpleUploadedFile(file_.name,
                              temp.read(),
                              content_type=file_.content_type)
예제 #8
0
 def makefile(self, *args, **kwargs):
     return IO(self.request)
예제 #9
0
 def makefile(self, *args, **kwargs):
     return IO(b"GET /")
예제 #10
0
파일: main.py 프로젝트: jelly/c3bottles
def _pdf(number):
    img = qrcode.make(request.url_root + str(number))
    f = IO()
    img.save(f)
    b64 = b64encode(f.getvalue()).decode("utf-8")
    return svg2pdf(render_template("label.svg", number=number, qr=b64))
예제 #11
0
 def makefile(self, *args, **kwargs):
     return IO(b"GET / HTTP/1.0")
예제 #12
0
print request.request_version  # "HTTP/1.1"
print len(request.headers)     # 3
print request.headers.keys()   # ['accept-charset', 'host', 'accept']
#print request.headers['content-type']  # "cm.bell-labs.com"
content_len = int(request.headers.getheader('content-length', 0))
post_body = request.rfile.read(content_len)

print post_body



import cgi
from StringIO import StringIO as IO

parsed = cgi.FieldStorage(
    IO(post_body.encode('utf-8')),
    headers={'content-type': request.headers['content-type']},
    environ={'REQUEST_METHOD': request.command })



import cStringIO
from wsgiref import simple_server, util

from werkzeug.formparser import parse_form_data

input_string = """POST / HTTP/1.1
Host: example.com
User-Agent: curl/7.43.0
Accept: */*
Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150
예제 #13
0
 def makefile(self, *args, **kwargs):
     return IO(b"PUT /equalizer/9999/0/ HTTP/1.1")
예제 #14
0
def get_sized_images(image, sizes, crop=(50, 50)):
    (orig, c) = OriginalImage.objects.get_or_create(image_file=image.name)

    # filter out duplicates and larger than original
    sizes_set = set()
    for (width, height) in sizes:
        width = min(width, image.width)
        height = min(height, image.height)
        if not crop:
            orig_aspect = image.width / float(image.height)
            req_aspect = width / float(height)
            if orig_aspect > req_aspect:
                ratio = width / float(image.width)
            else:
                ratio = height / float(image.height)
            width = int(image.width * ratio + 0.5)
            height = int(image.height * ratio + 0.5)
        sizes_set.add((width, height))
    sizes = sorted(sizes_set)

    if sizes[0] == orig.size:
        # smallest size is original image
        return [orig]

    # common info to all resized images
    if crop:
        crop_type = '{}-{}'.format(*crop)
    else:
        crop_type = 'nocrop'
    split_ext = image.name.rsplit('.', 1)
    if len(split_ext) > 1:
        ext = '.' + split_ext[-1]
    else:
        ext = ''

    # open the original image
    image.open()
    orig_image = Image.open(image)
    orig_image.load()
    image.close()

    # create the resized images
    resized = []
    for (width, height) in sizes:
        if (width, height) == (image.width, image.height):
            resized.append(orig)
            continue
        try:
            found = ResizedImage.objects.get(
                original=orig,
                width=width,
                height=height,
                crop=crop_type
            )
        except ResizedImage.DoesNotExist:
            pass
        else:
            resized.append(found)
            continue

        if crop:
            new_image = ImageOps.fit(
                orig_image,
                (width, height),
                method=Image.BICUBIC,
                centering=(crop[0] / 100.0, crop[1] / 100.0)
            )
        else:
            new_image = orig_image.resize(
                (width, height),
                resample=Image.BICUBIC
            )

        data = IO()
        new_image.save(data, orig_image.format)
        resized_path = default_storage.save(
            os.path.join(
                'responsive_images',
                image.name,
                '{}x{}_{}{}'.format(width, height, crop_type, ext)),
            File(data)
        )
        resized.append(ResizedImage.objects.create(
            original=orig,
            image_file=resized_path,
            crop=crop_type
        ))

    return resized
예제 #15
0
 def makefile(self, *args, **kwargs):
     return IO(b"GET /helloWorld.css")
예제 #16
0
 def parseMutiPart(self, request_headers, content_type_line):
     body = request_headers.split("\r\n\r\n")[1:]
     body = ("\r\n\r\n".join(body))
     parsed = cgi.FieldStorage(IO(body),
                               headers={content_type_line},
                               environ={'REQUEST_METHOD': 'POST'})
예제 #17
0
 def makefile(self, *args, **kwargs):
     return IO(b"PUT /helloWorld HTTP/1.1")
예제 #18
0
 def __init__(self):
     # type: () -> None
     self.copy = IO()
     self.stream = IO()
예제 #19
0
 def makefile(self, *args, **kwargs):
     return IO(b"GET /css/style.css")
예제 #20
0
 def makefile(self, *args, **kwargs):
     return IO(b"PUT /source/9999/0/ HTTP/1.1")
예제 #21
0
 def makefile(self, *args, **kwargs):
     return IO(b"PUT /control/9999/0/ HTTP/1.1")
예제 #22
0
 def makefile(self, *args, **kwargs):
     return IO(b"PUT /card/0/ HTTP/1.1")
예제 #23
0
 def makefile(self, *args, **kwargs):
     return IO(b"GET /equalizer/")