def handle_register_or_upload(post_data, files, user, repository):
name = post_data.get('<STR_LIT:name>')<EOL>version = post_data.get('<STR_LIT:version>')<EOL>if settings.LOCALSHOP_VERSIONING_TYPE:<EOL><INDENT>scheme = get_versio_versioning_scheme(settings.LOCALSHOP_VERSIONING_TYPE)<EOL>try:<EOL><INDENT>Version(version, scheme=scheme)<EOL><DEDENT>except AttributeError:<EOL><INDENT>response = HttpResponseBadRequest(<EOL>reason="<STR_LIT>".format(<EOL>version, settings.LOCALSHOP_VERSIONING_TYPE))<EOL>return response<EOL><DEDENT><DEDENT>if not name or not version:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>return HttpResponseBadRequest('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>condition = Q()<EOL>for search_name in get_search_names(name):<EOL><INDENT>condition |= Q(name__iexact=search_name)<EOL><DEDENT>package = repository.packages.get(condition)<EOL>if not package.is_local:<EOL><INDENT>return HttpResponseBadRequest(<EOL>'<STR_LIT>' % package.name)<EOL><DEDENT>try:<EOL><INDENT>release = package.releases.get(version=version)<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>release = None<EOL><DEDENT><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>package = None<EOL>release = None<EOL><DEDENT>form = forms.ReleaseForm(post_data, instance=release)<EOL>if not form.is_valid():<EOL><INDENT>return HttpResponseBadRequest(reason=form.errors.values()[<NUM_LIT:0>][<NUM_LIT:0>])<EOL><DEDENT>if not package:<EOL><INDENT>pkg_form = forms.PackageForm(post_data, repository=repository)<EOL>if not pkg_form.is_valid():<EOL><INDENT>return HttpResponseBadRequest(<EOL>reason=six.next(six.itervalues(pkg_form.errors))[<NUM_LIT:0>])<EOL><DEDENT>package = pkg_form.save()<EOL><DEDENT>release = form.save(commit=False)<EOL>release.package = package<EOL>release.save()<EOL>if files:<EOL><INDENT>files = {<EOL>'<STR_LIT>': files['<STR_LIT:content>']<EOL>}<EOL>filename = files['<STR_LIT>']._name<EOL>try:<EOL><INDENT>release_file = release.files.get(filename=filename)<EOL>if settings.LOCALSHOP_RELEASE_OVERWRITE is False:<EOL><INDENT>message = '<STR_LIT>'<EOL>return HttpResponseBadRequest(message)<EOL><DEDENT><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>release_file = models.ReleaseFile(<EOL>release=release, filename=filename)<EOL><DEDENT>form_file = forms.ReleaseFileForm(<EOL>post_data, files, instance=release_file)<EOL>if not form_file.is_valid():<EOL><INDENT>return HttpResponseBadRequest('<STR_LIT>' % form_file.errors)<EOL><DEDENT>release_file = form_file.save(commit=False)<EOL>release_file.save()<EOL><DEDENT>return HttpResponse()<EOL>
Process a `register` or `upload` comment issued via distutils.

    This method is called with the authenticated user.